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 this(containingDeclaration, name, modality, kind, supertypes, source, name.asString());
055 }
056
057 public ClassDescriptorImpl(
058 @NotNull DeclarationDescriptor containingDeclaration,
059 @NotNull Name name,
060 @NotNull Modality modality,
061 @NotNull ClassKind kind,
062 @NotNull Collection<KotlinType> supertypes,
063 @NotNull SourceElement source,
064 @NotNull String debugName
065 ) {
066 super(LockBasedStorageManager.NO_LOCKS, containingDeclaration, name, source);
067 this.modality = modality;
068 this.kind = kind;
069
070 this.typeConstructor = TypeConstructorImpl.createForClass(this, Annotations.Companion.getEMPTY(), false, debugName,
071 Collections.<TypeParameterDescriptor>emptyList(), supertypes);
072 }
073
074 public final void initialize(
075 @NotNull MemberScope unsubstitutedMemberScope,
076 @NotNull Set<ConstructorDescriptor> constructors,
077 @Nullable ConstructorDescriptor primaryConstructor
078 ) {
079 this.unsubstitutedMemberScope = unsubstitutedMemberScope;
080 this.constructors = constructors;
081 this.primaryConstructor = primaryConstructor;
082 }
083
084 public void setPrimaryConstructor(@NotNull ConstructorDescriptor primaryConstructor) {
085 this.primaryConstructor = primaryConstructor;
086 }
087
088 @NotNull
089 @Override
090 public Annotations getAnnotations() {
091 return Annotations.Companion.getEMPTY();
092 }
093
094 @Override
095 @NotNull
096 public TypeConstructor getTypeConstructor() {
097 return typeConstructor;
098 }
099
100 @NotNull
101 @Override
102 public Collection<ConstructorDescriptor> getConstructors() {
103 return constructors;
104 }
105
106 @NotNull
107 @Override
108 public MemberScope getUnsubstitutedMemberScope() {
109 return unsubstitutedMemberScope;
110 }
111
112 @NotNull
113 @Override
114 public MemberScope getStaticScope() {
115 return staticScope;
116 }
117
118 @Nullable
119 @Override
120 public ClassDescriptor getCompanionObjectDescriptor() {
121 return null;
122 }
123
124 @NotNull
125 @Override
126 public ClassKind getKind() {
127 return kind;
128 }
129
130 @Override
131 public boolean isCompanionObject() {
132 return false;
133 }
134
135 @Override
136 public ConstructorDescriptor getUnsubstitutedPrimaryConstructor() {
137 return primaryConstructor;
138 }
139
140 @Override
141 @NotNull
142 public Modality getModality() {
143 return modality;
144 }
145
146 @NotNull
147 @Override
148 public Visibility getVisibility() {
149 return Visibilities.PUBLIC;
150 }
151
152 @Override
153 public boolean isData() {
154 return false;
155 }
156
157 @Override
158 public boolean isInner() {
159 return false;
160 }
161
162 @Override
163 public String toString() {
164 return "class " + getName();
165 }
166
167 @NotNull
168 @Override
169 public List<TypeParameterDescriptor> getDeclaredTypeParameters() {
170 return Collections.emptyList();
171 }
172 }