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.types;
018
019 import org.jetbrains.annotations.NotNull;
020 import org.jetbrains.kotlin.descriptors.ClassDescriptor;
021 import org.jetbrains.kotlin.descriptors.SupertypeLoopChecker;
022 import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor;
023 import org.jetbrains.kotlin.descriptors.annotations.Annotations;
024 import org.jetbrains.kotlin.resolve.DescriptorUtils;
025 import org.jetbrains.kotlin.storage.LockBasedStorageManager;
026
027 import java.util.ArrayList;
028 import java.util.Collection;
029 import java.util.Collections;
030 import java.util.List;
031
032 public class ClassTypeConstructorImpl extends AbstractClassTypeConstructor implements TypeConstructor {
033 private final ClassDescriptor classDescriptor;
034 private final Annotations annotations;
035 private final List<TypeParameterDescriptor> parameters;
036 private final Collection<KotlinType> supertypes;
037 private final boolean isFinal;
038
039 public ClassTypeConstructorImpl(
040 @NotNull ClassDescriptor classDescriptor,
041 @NotNull Annotations annotations,
042 boolean isFinal,
043 @NotNull List<? extends TypeParameterDescriptor> parameters,
044 @NotNull Collection<KotlinType> supertypes
045 ) {
046 super(LockBasedStorageManager.NO_LOCKS);
047 this.classDescriptor = classDescriptor;
048 this.annotations = annotations;
049 this.isFinal = isFinal;
050 this.parameters = Collections.unmodifiableList(new ArrayList<TypeParameterDescriptor>(parameters));
051 this.supertypes = Collections.unmodifiableCollection(supertypes);
052 }
053
054 @Override
055 @NotNull
056 public List<TypeParameterDescriptor> getParameters() {
057 return parameters;
058 }
059
060 @Override
061 public String toString() {
062 return DescriptorUtils.getFqName(classDescriptor).asString();
063 }
064
065 @Override
066 public boolean isFinal() {
067 return isFinal;
068 }
069
070 @Override
071 public boolean isDenotable() {
072 return true;
073 }
074
075 @Override
076 @NotNull
077 public ClassDescriptor getDeclarationDescriptor() {
078 return classDescriptor;
079 }
080
081 @NotNull
082 @Override
083 protected Collection<KotlinType> computeSupertypes() {
084 return supertypes;
085 }
086
087 @NotNull
088 @Override
089 protected SupertypeLoopChecker getSupertypeLoopChecker() {
090 return SupertypeLoopChecker.EMPTY.INSTANCE;
091 }
092
093 @NotNull
094 @Override
095 public Annotations getAnnotations() {
096 return annotations;
097 }
098 }