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<ConstructorDescriptor> constructors;
042 private ConstructorDescriptor 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 ) {
052 super(LockBasedStorageManager.NO_LOCKS, containingDeclaration, name, source);
053 this.modality = modality;
054 this.kind = kind;
055
056 this.typeConstructor = new ClassTypeConstructorImpl(
057 this, Annotations.Companion.getEMPTY(), false, Collections.<TypeParameterDescriptor>emptyList(), supertypes
058 );
059 }
060
061 public final void initialize(
062 @NotNull MemberScope unsubstitutedMemberScope,
063 @NotNull Set<ConstructorDescriptor> constructors,
064 @Nullable ConstructorDescriptor 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<ConstructorDescriptor> 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 ConstructorDescriptor getUnsubstitutedPrimaryConstructor() {
120 return primaryConstructor;
121 }
122
123 @Override
124 @NotNull
125 public Modality getModality() {
126 return modality;
127 }
128
129 @NotNull
130 @Override
131 public Visibility getVisibility() {
132 return Visibilities.PUBLIC;
133 }
134
135 @Override
136 public boolean isData() {
137 return false;
138 }
139
140 @Override
141 public boolean isInner() {
142 return false;
143 }
144
145 @Override
146 public String toString() {
147 return "class " + getName();
148 }
149
150 @NotNull
151 @Override
152 public List<TypeParameterDescriptor> getDeclaredTypeParameters() {
153 return Collections.emptyList();
154 }
155 }