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