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 @NotNull
085 @Override
086 public Annotations getAnnotations() {
087 return Annotations.Companion.getEMPTY();
088 }
089
090 @Override
091 @NotNull
092 public TypeConstructor getTypeConstructor() {
093 return typeConstructor;
094 }
095
096 @NotNull
097 @Override
098 public Collection<ConstructorDescriptor> getConstructors() {
099 return constructors;
100 }
101
102 @NotNull
103 @Override
104 public MemberScope getUnsubstitutedMemberScope() {
105 return unsubstitutedMemberScope;
106 }
107
108 @NotNull
109 @Override
110 public MemberScope getStaticScope() {
111 return staticScope;
112 }
113
114 @Nullable
115 @Override
116 public ClassDescriptor getCompanionObjectDescriptor() {
117 return null;
118 }
119
120 @NotNull
121 @Override
122 public ClassKind getKind() {
123 return kind;
124 }
125
126 @Override
127 public boolean isCompanionObject() {
128 return false;
129 }
130
131 @Override
132 public ConstructorDescriptor getUnsubstitutedPrimaryConstructor() {
133 return primaryConstructor;
134 }
135
136 @Override
137 @NotNull
138 public Modality getModality() {
139 return modality;
140 }
141
142 @NotNull
143 @Override
144 public Visibility getVisibility() {
145 return Visibilities.PUBLIC;
146 }
147
148 @Override
149 public boolean isData() {
150 return false;
151 }
152
153 @Override
154 public boolean isInner() {
155 return false;
156 }
157
158 @Override
159 public String toString() {
160 return "class " + getName();
161 }
162
163 @NotNull
164 @Override
165 public List<TypeParameterDescriptor> getDeclaredTypeParameters() {
166 return Collections.emptyList();
167 }
168 }