001 /*
002 * Copyright 2010-2015 JetBrains s.r.o.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017 package org.jetbrains.kotlin.serialization.deserialization.descriptors;
018
019 import org.jetbrains.annotations.NotNull;
020 import org.jetbrains.kotlin.descriptors.SourceElement;
021 import org.jetbrains.kotlin.descriptors.annotations.Annotations;
022 import org.jetbrains.kotlin.descriptors.impl.AbstractLazyTypeParameterDescriptor;
023 import org.jetbrains.kotlin.serialization.ProtoBuf;
024 import org.jetbrains.kotlin.serialization.deserialization.Deserialization;
025 import org.jetbrains.kotlin.serialization.deserialization.DeserializationContext;
026 import org.jetbrains.kotlin.serialization.deserialization.DeserializationPackage;
027 import org.jetbrains.kotlin.serialization.deserialization.TypeDeserializer;
028 import org.jetbrains.kotlin.types.JetType;
029
030 import java.util.Collections;
031 import java.util.LinkedHashSet;
032 import java.util.Set;
033
034 import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilPackage.getBuiltIns;
035
036 public class DeserializedTypeParameterDescriptor extends AbstractLazyTypeParameterDescriptor {
037 private final ProtoBuf.TypeParameter proto;
038 private final TypeDeserializer typeDeserializer;
039
040 public DeserializedTypeParameterDescriptor(@NotNull DeserializationContext c, @NotNull ProtoBuf.TypeParameter proto, int index) {
041 super(c.getStorageManager(),
042 c.getContainingDeclaration(),
043 c.getNameResolver().getName(proto.getName()),
044 Deserialization.variance(proto.getVariance()),
045 proto.getReified(),
046 index,
047 SourceElement.NO_SOURCE);
048 this.proto = proto;
049 this.typeDeserializer = c.getTypeDeserializer();
050 }
051
052 @NotNull
053 @Override
054 protected Set<JetType> resolveUpperBounds() {
055 if (proto.getUpperBoundCount() == 0) {
056 return Collections.singleton(getBuiltIns(this).getDefaultBound());
057 }
058 Set<JetType> result = new LinkedHashSet<JetType>(proto.getUpperBoundCount());
059 for (ProtoBuf.Type upperBound : proto.getUpperBoundList()) {
060 result.add(typeDeserializer.type(upperBound, Annotations.EMPTY));
061 }
062 return result;
063 }
064 }