001 /*
002 * Copyright 2010-2013 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.jet.lang.descriptors.impl;
018
019 import org.jetbrains.annotations.NotNull;
020 import org.jetbrains.annotations.Nullable;
021 import org.jetbrains.jet.lang.descriptors.*;
022 import org.jetbrains.jet.lang.descriptors.annotations.Annotations;
023 import org.jetbrains.jet.lang.resolve.name.Name;
024 import org.jetbrains.jet.lang.resolve.scopes.JetScope;
025 import org.jetbrains.jet.lang.types.JetType;
026 import org.jetbrains.jet.lang.types.TypeConstructor;
027 import org.jetbrains.jet.lang.types.TypeConstructorImpl;
028 import org.jetbrains.jet.storage.LockBasedStorageManager;
029
030 import java.util.Collection;
031 import java.util.Collections;
032 import java.util.Set;
033
034 public class ClassDescriptorImpl extends ClassDescriptorBase {
035 private final Modality modality;
036 private final TypeConstructor typeConstructor;
037
038 private JetScope scopeForMemberLookup;
039 private Set<ConstructorDescriptor> constructors;
040 private ConstructorDescriptor primaryConstructor;
041
042 public ClassDescriptorImpl(
043 @NotNull DeclarationDescriptor containingDeclaration,
044 @NotNull Name name,
045 @NotNull Modality modality,
046 @NotNull Collection<JetType> supertypes,
047 @NotNull SourceElement source
048 ) {
049 super(LockBasedStorageManager.NO_LOCKS, containingDeclaration, name, source);
050 this.modality = modality;
051
052 this.typeConstructor = TypeConstructorImpl.createForClass(this, Annotations.EMPTY, false, getName().asString(),
053 Collections.<TypeParameterDescriptor>emptyList(), supertypes);
054 }
055
056 public final void initialize(
057 @NotNull JetScope scopeForMemberLookup,
058 @NotNull Set<ConstructorDescriptor> constructors,
059 @Nullable ConstructorDescriptor primaryConstructor
060 ) {
061 this.scopeForMemberLookup = scopeForMemberLookup;
062 this.constructors = constructors;
063 this.primaryConstructor = primaryConstructor;
064 }
065
066 public void setPrimaryConstructor(@NotNull ConstructorDescriptor primaryConstructor) {
067 this.primaryConstructor = primaryConstructor;
068 }
069
070 @NotNull
071 @Override
072 public Annotations getAnnotations() {
073 return Annotations.EMPTY;
074 }
075
076 @Override
077 @NotNull
078 public TypeConstructor getTypeConstructor() {
079 return typeConstructor;
080 }
081
082 @NotNull
083 @Override
084 public Collection<ConstructorDescriptor> getConstructors() {
085 return constructors;
086 }
087
088 @NotNull
089 @Override
090 protected JetScope getScopeForMemberLookup() {
091 return scopeForMemberLookup;
092 }
093
094 @Nullable
095 @Override
096 public ClassDescriptor getClassObjectDescriptor() {
097 return null;
098 }
099
100 @NotNull
101 @Override
102 public ClassKind getKind() {
103 return ClassKind.CLASS;
104 }
105
106 @Override
107 public ConstructorDescriptor getUnsubstitutedPrimaryConstructor() {
108 return primaryConstructor;
109 }
110
111 @Override
112 @NotNull
113 public Modality getModality() {
114 return modality;
115 }
116
117 @NotNull
118 @Override
119 public Visibility getVisibility() {
120 return Visibilities.PUBLIC;
121 }
122
123 @Override
124 public boolean isInner() {
125 return false;
126 }
127
128 @Override
129 public String toString() {
130 return "class " + getName();
131 }
132 }