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.DeserializationContext;
025 import org.jetbrains.kotlin.serialization.deserialization.DeserializationPackage;
026 import org.jetbrains.kotlin.serialization.deserialization.TypeDeserializer;
027 import org.jetbrains.kotlin.types.JetType;
028
029 import java.util.Collections;
030 import java.util.LinkedHashSet;
031 import java.util.Set;
032
033 import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilPackage.getBuiltIns;
034
035 public class DeserializedTypeParameterDescriptor extends AbstractLazyTypeParameterDescriptor {
036 private final ProtoBuf.TypeParameter proto;
037 private final TypeDeserializer typeDeserializer;
038
039 public DeserializedTypeParameterDescriptor(@NotNull DeserializationContext c, @NotNull ProtoBuf.TypeParameter proto, int index) {
040 super(c.getStorageManager(),
041 c.getContainingDeclaration(),
042 c.getNameResolver().getName(proto.getName()),
043 DeserializationPackage.variance(proto.getVariance()),
044 proto.getReified(),
045 index,
046 SourceElement.NO_SOURCE);
047 this.proto = proto;
048 this.typeDeserializer = c.getTypeDeserializer();
049 }
050
051 @NotNull
052 @Override
053 protected Set<JetType> resolveUpperBounds() {
054 if (proto.getUpperBoundCount() == 0) {
055 return Collections.singleton(getBuiltIns(this).getDefaultBound());
056 }
057 Set<JetType> result = new LinkedHashSet<JetType>(proto.getUpperBoundCount());
058 for (ProtoBuf.Type upperBound : proto.getUpperBoundList()) {
059 result.add(typeDeserializer.type(upperBound, Annotations.EMPTY));
060 }
061 return result;
062 }
063 }