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