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.descriptors.impl;
018    
019    import org.jetbrains.annotations.NotNull;
020    import org.jetbrains.annotations.Nullable;
021    import org.jetbrains.kotlin.descriptors.*;
022    import org.jetbrains.kotlin.descriptors.annotations.Annotations;
023    import org.jetbrains.kotlin.name.Name;
024    import org.jetbrains.kotlin.resolve.scopes.MemberScope;
025    import org.jetbrains.kotlin.storage.LockBasedStorageManager;
026    import org.jetbrains.kotlin.types.ClassTypeConstructorImpl;
027    import org.jetbrains.kotlin.types.KotlinType;
028    import org.jetbrains.kotlin.types.TypeConstructor;
029    
030    import java.util.Collection;
031    import java.util.Collections;
032    import java.util.List;
033    import java.util.Set;
034    
035    public class ClassDescriptorImpl extends ClassDescriptorBase {
036        private final Modality modality;
037        private final ClassKind kind;
038        private final TypeConstructor typeConstructor;
039    
040        private MemberScope unsubstitutedMemberScope;
041        private Set<ConstructorDescriptor> constructors;
042        private ConstructorDescriptor primaryConstructor;
043    
044        public ClassDescriptorImpl(
045                @NotNull DeclarationDescriptor containingDeclaration,
046                @NotNull Name name,
047                @NotNull Modality modality,
048                @NotNull ClassKind kind,
049                @NotNull Collection<KotlinType> supertypes,
050                @NotNull SourceElement source
051        ) {
052            super(LockBasedStorageManager.NO_LOCKS, containingDeclaration, name, source);
053            this.modality = modality;
054            this.kind = kind;
055    
056            this.typeConstructor = new ClassTypeConstructorImpl(this, false, Collections.<TypeParameterDescriptor>emptyList(), supertypes);
057        }
058    
059        public final void initialize(
060                @NotNull MemberScope unsubstitutedMemberScope,
061                @NotNull Set<ConstructorDescriptor> constructors,
062                @Nullable ConstructorDescriptor primaryConstructor
063        ) {
064            this.unsubstitutedMemberScope = unsubstitutedMemberScope;
065            this.constructors = constructors;
066            this.primaryConstructor = primaryConstructor;
067        }
068    
069        @NotNull
070        @Override
071        public Annotations getAnnotations() {
072            return Annotations.Companion.getEMPTY();
073        }
074    
075        @Override
076        @NotNull
077        public TypeConstructor getTypeConstructor() {
078            return typeConstructor;
079        }
080    
081        @NotNull
082        @Override
083        public Collection<ConstructorDescriptor> getConstructors() {
084            return constructors;
085        }
086    
087        @NotNull
088        @Override
089        public MemberScope getUnsubstitutedMemberScope() {
090            return unsubstitutedMemberScope;
091        }
092    
093        @NotNull
094        @Override
095        public MemberScope getStaticScope() {
096            return MemberScope.Empty.INSTANCE;
097        }
098    
099        @Nullable
100        @Override
101        public ClassDescriptor getCompanionObjectDescriptor() {
102            return null;
103        }
104    
105        @NotNull
106        @Override
107        public ClassKind getKind() {
108            return kind;
109        }
110    
111        @Override
112        public boolean isCompanionObject() {
113            return false;
114        }
115    
116        @Override
117        public ConstructorDescriptor getUnsubstitutedPrimaryConstructor() {
118            return primaryConstructor;
119        }
120    
121        @Override
122        @NotNull
123        public Modality getModality() {
124            return modality;
125        }
126    
127        @NotNull
128        @Override
129        public Visibility getVisibility() {
130            return Visibilities.PUBLIC;
131        }
132    
133        @Override
134        public boolean isData() {
135            return false;
136        }
137    
138        @Override
139        public boolean isInner() {
140            return false;
141        }
142    
143        @Override
144        public String toString() {
145            return "class " + getName();
146        }
147    
148        @NotNull
149        @Override
150        public List<TypeParameterDescriptor> getDeclaredTypeParameters() {
151            return Collections.emptyList();
152        }
153    }