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        ) {
048            super(LockBasedStorageManager.NO_LOCKS, containingDeclaration, name);
049            this.modality = modality;
050    
051            this.typeConstructor = TypeConstructorImpl.createForClass(this, Annotations.EMPTY, false, getName().asString(),
052                                                           Collections.<TypeParameterDescriptor>emptyList(), supertypes);
053        }
054    
055        public final void initialize(
056                @NotNull JetScope scopeForMemberLookup,
057                @NotNull Set<ConstructorDescriptor> constructors,
058                @Nullable ConstructorDescriptor primaryConstructor
059        ) {
060            this.scopeForMemberLookup = scopeForMemberLookup;
061            this.constructors = constructors;
062            this.primaryConstructor = primaryConstructor;
063        }
064    
065        public void setPrimaryConstructor(@NotNull ConstructorDescriptor primaryConstructor) {
066            this.primaryConstructor = primaryConstructor;
067        }
068    
069        @NotNull
070        @Override
071        public Annotations getAnnotations() {
072            return Annotations.EMPTY;
073        }
074    
075        @Override
076        @NotNull
077        public TypeConstructor getTypeConstructor() {
078            return typeConstructor;
079        }
080    
081        @NotNull
082        @Override
083        public Collection<ConstructorDescriptor> getConstructors() {
084            return constructors;
085        }
086    
087        @NotNull
088        @Override
089        protected JetScope getScopeForMemberLookup() {
090            return scopeForMemberLookup;
091        }
092    
093        @Nullable
094        @Override
095        public ClassDescriptor getClassObjectDescriptor() {
096            return null;
097        }
098    
099        @NotNull
100        @Override
101        public ClassKind getKind() {
102            return ClassKind.CLASS;
103        }
104    
105        @Override
106        public ConstructorDescriptor getUnsubstitutedPrimaryConstructor() {
107            return primaryConstructor;
108        }
109    
110        @Override
111        @NotNull
112        public Modality getModality() {
113            return modality;
114        }
115    
116        @NotNull
117        @Override
118        public Visibility getVisibility() {
119            return Visibilities.PUBLIC;
120        }
121    
122        @Override
123        public boolean isInner() {
124            return false;
125        }
126    
127        @Override
128        public String toString() {
129            return "class " + getName();
130        }
131    }