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