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