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