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