Drop MutableClassDescriptorLite
Inline it into MutableClassDescriptor
This commit is contained in:
@@ -32,7 +32,10 @@ import org.jetbrains.jet.di.InjectorForLazyResolve;
|
||||
import org.jetbrains.jet.di.InjectorForTopDownAnalyzerBasic;
|
||||
import org.jetbrains.jet.lang.PlatformToKotlinClassMap;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.*;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.MutableClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.MutablePackageFragmentDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.PackageLikeBuilder;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.PackageLikeBuilderDummy;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.ForceResolveUtil;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.LazyImportScope;
|
||||
@@ -386,7 +389,7 @@ public class TopDownAnalyzer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addClassifierDescriptor(@NotNull MutableClassDescriptorLite classDescriptor) {
|
||||
public void addClassifierDescriptor(@NotNull MutableClassDescriptor classDescriptor) {
|
||||
if (scope != null) {
|
||||
scope.addClassifierDescriptor(classDescriptor);
|
||||
}
|
||||
@@ -403,7 +406,7 @@ public class TopDownAnalyzer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassObjectStatus setClassObjectDescriptor(@NotNull MutableClassDescriptorLite classObjectDescriptor) {
|
||||
public ClassObjectStatus setClassObjectDescriptor(@NotNull MutableClassDescriptor classObjectDescriptor) {
|
||||
return ClassObjectStatus.NOT_ALLOWED;
|
||||
}
|
||||
},
|
||||
|
||||
@@ -21,7 +21,10 @@ import com.intellij.psi.PsiNameIdentifierOwner;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.*;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.ConstructorDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.MutableClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.MutablePackageFragmentDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.PackageLikeBuilder;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.name.SpecialNames;
|
||||
@@ -122,12 +125,12 @@ public class TypeHierarchyResolver {
|
||||
JetScope scope = c.normalScope.get(declarationContainer);
|
||||
|
||||
// Even more temp code
|
||||
if (descriptorForDeferredResolve instanceof MutableClassDescriptorLite) {
|
||||
if (descriptorForDeferredResolve instanceof MutableClassDescriptor) {
|
||||
forDeferredResolve.addAll(
|
||||
collectPackageFragmentsAndClassifiers(
|
||||
c,
|
||||
scope,
|
||||
((MutableClassDescriptorLite) descriptorForDeferredResolve).getBuilder(),
|
||||
((MutableClassDescriptor) descriptorForDeferredResolve).getBuilder(),
|
||||
declarationContainer.getDeclarations()));
|
||||
}
|
||||
else if (descriptorForDeferredResolve instanceof MutablePackageFragmentDescriptor) {
|
||||
@@ -199,7 +202,7 @@ public class TypeHierarchyResolver {
|
||||
|
||||
ClassKind kind = descriptor.getKind();
|
||||
if (kind == ClassKind.ENUM_ENTRY || kind == ClassKind.OBJECT || kind == ClassKind.ENUM_CLASS) {
|
||||
MutableClassDescriptorLite classObject = descriptor.getClassObjectDescriptor();
|
||||
MutableClassDescriptor classObject = descriptor.getClassObjectDescriptor();
|
||||
assert classObject != null : "Enum entries and named objects should have class objects: " + classOrObject.getText();
|
||||
|
||||
JetType supertype;
|
||||
|
||||
-61
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.java.descriptor;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassKind;
|
||||
import org.jetbrains.jet.lang.descriptors.ConstructorDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.ConstructorDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.MutableClassDescriptorLite;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorFactory;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.jetbrains.jet.lang.resolve.name.SpecialNames.getClassObjectName;
|
||||
|
||||
public class JavaEnumClassObjectDescriptor extends MutableClassDescriptorLite {
|
||||
private ConstructorDescriptor constructor;
|
||||
|
||||
public JavaEnumClassObjectDescriptor(@NotNull DeclarationDescriptor enumClass) {
|
||||
super(enumClass, getClassObjectName(enumClass.getName()), ClassKind.CLASS_OBJECT, false);
|
||||
}
|
||||
|
||||
private void initConstructor() {
|
||||
if (constructor == null) {
|
||||
ConstructorDescriptorImpl constructor = DescriptorFactory.createPrimaryConstructorForObject(this);
|
||||
constructor.setReturnType(getDefaultType());
|
||||
this.constructor = constructor;
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<ConstructorDescriptor> getConstructors() {
|
||||
initConstructor();
|
||||
return Collections.singleton(constructor);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ConstructorDescriptor getUnsubstitutedPrimaryConstructor() {
|
||||
initConstructor();
|
||||
return constructor;
|
||||
}
|
||||
}
|
||||
+8
-6
@@ -10,7 +10,6 @@ import org.jetbrains.jet.lang.types.JetType
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor
|
||||
import org.jetbrains.jet.lang.types.TypeConstructor
|
||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor
|
||||
import java.util.Collections
|
||||
import org.jetbrains.jet.lang.resolve.java.lazy.LazyJavaResolverContextWithTypes
|
||||
import org.jetbrains.jet.lang.resolve.java.lazy.child
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.TypeUsage
|
||||
@@ -24,7 +23,6 @@ import org.jetbrains.jet.lang.resolve.java.structure.JavaMethod
|
||||
import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor
|
||||
import org.jetbrains.jet.lang.types.TypeUtils
|
||||
import org.jetbrains.jet.lang.resolve.java.descriptor.JavaClassDescriptor
|
||||
import org.jetbrains.jet.lang.resolve.java.descriptor.JavaEnumClassObjectDescriptor
|
||||
import org.jetbrains.jet.lang.descriptors.Modality
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl
|
||||
import org.jetbrains.jet.lang.resolve.scopes.RedeclarationHandler
|
||||
@@ -36,6 +34,8 @@ import java.util.ArrayList
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.DescriptorResolverUtils
|
||||
import org.jetbrains.jet.lang.resolve.java.descriptor.JavaClassStaticsPackageFragmentDescriptor
|
||||
import org.jetbrains.jet.lang.descriptors.impl.MutableClassDescriptor
|
||||
import org.jetbrains.jet.lang.resolve.name.SpecialNames
|
||||
|
||||
class LazyJavaClassDescriptor(
|
||||
private val outerC: LazyJavaResolverContextWithTypes,
|
||||
@@ -82,12 +82,14 @@ class LazyJavaClassDescriptor(
|
||||
|
||||
private val _classObjectDescriptor = c.storageManager.createNullableLazyValue {
|
||||
if (jClass.isEnum()) {
|
||||
val classObject = JavaEnumClassObjectDescriptor(this)
|
||||
classObject.setSupertypes(Collections.singleton(KotlinBuiltIns.getInstance().getAnyType()))
|
||||
val classObject = MutableClassDescriptor(this, this.getUnsubstitutedInnerClassesScope(), ClassKind.CLASS_OBJECT, false,
|
||||
SpecialNames.getClassObjectName(this.getName()))
|
||||
classObject.setSupertypes(listOf(KotlinBuiltIns.getInstance().getAnyType()))
|
||||
classObject.setModality(Modality.FINAL)
|
||||
classObject.setVisibility(jClass.getVisibility())
|
||||
classObject.setTypeParameterDescriptors(Collections.emptyList<TypeParameterDescriptor>())
|
||||
classObject.setTypeParameterDescriptors(listOf())
|
||||
classObject.createTypeConstructor()
|
||||
classObject.setPrimaryConstructor(DescriptorFactory.createPrimaryConstructorForObject(classObject))
|
||||
|
||||
val scope = LazyJavaClassMemberScope(c, classObject, jClass, enumClassObject = true)
|
||||
val writableScope = WritableScopeImpl(scope, classObject, RedeclarationHandler.THROW_EXCEPTION, "Enum class object scope")
|
||||
@@ -102,7 +104,7 @@ class LazyJavaClassDescriptor(
|
||||
else null
|
||||
}
|
||||
|
||||
private fun createEnumSyntheticMethods(classObject: JavaEnumClassObjectDescriptor, enumType: JetType) {
|
||||
private fun createEnumSyntheticMethods(classObject: MutableClassDescriptor, enumType: JetType) {
|
||||
val valuesReturnType = KotlinBuiltIns.getInstance().getArrayType(enumType)
|
||||
val valuesMethod = DescriptorFactory.createEnumClassObjectValuesMethod(classObject, valuesReturnType)
|
||||
classObject.getBuilder().addFunctionDescriptor(valuesMethod)
|
||||
|
||||
+148
-25
@@ -20,15 +20,32 @@ import com.google.common.collect.Sets;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationsImpl;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.*;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.storage.LockBasedStorageManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class MutableClassDescriptor extends MutableClassDescriptorLite implements ClassDescriptorWithResolutionScopes {
|
||||
public class MutableClassDescriptor extends ClassDescriptorBase implements ClassDescriptorWithResolutionScopes {
|
||||
private final ClassKind kind;
|
||||
private final boolean isInner;
|
||||
|
||||
private Annotations annotations;
|
||||
private Modality modality;
|
||||
private Visibility visibility;
|
||||
private TypeConstructor typeConstructor;
|
||||
private List<TypeParameterDescriptor> typeParameters;
|
||||
private Collection<JetType> supertypes = new ArrayList<JetType>();
|
||||
|
||||
private MutableClassDescriptor classObjectDescriptor;
|
||||
|
||||
private final Set<ConstructorDescriptor> constructors = Sets.newLinkedHashSet();
|
||||
private ConstructorDescriptor primaryConstructor;
|
||||
|
||||
@@ -41,10 +58,18 @@ public class MutableClassDescriptor extends MutableClassDescriptorLite implement
|
||||
// This scope contains type parameters but does not contain inner classes
|
||||
private final WritableScope scopeForSupertypeResolution;
|
||||
private WritableScope scopeForInitializers = null; //contains members + primary constructor value parameters + map for backing fields
|
||||
private JetScope scopeForMemberLookup;
|
||||
|
||||
public MutableClassDescriptor(@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull JetScope outerScope, ClassKind kind, boolean isInner, Name name) {
|
||||
super(containingDeclaration, name, kind, isInner);
|
||||
public MutableClassDescriptor(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull JetScope outerScope,
|
||||
@NotNull ClassKind kind,
|
||||
boolean isInner,
|
||||
@NotNull Name name
|
||||
) {
|
||||
super(LockBasedStorageManager.NO_LOCKS, containingDeclaration, name);
|
||||
this.kind = kind;
|
||||
this.isInner = isInner;
|
||||
|
||||
RedeclarationHandler redeclarationHandler = RedeclarationHandler.DO_NOTHING;
|
||||
|
||||
@@ -64,10 +89,78 @@ public class MutableClassDescriptor extends MutableClassDescriptorLite implement
|
||||
@Nullable
|
||||
@Override
|
||||
public MutableClassDescriptor getClassObjectDescriptor() {
|
||||
return (MutableClassDescriptor) super.getClassObjectDescriptor();
|
||||
return classObjectDescriptor;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Annotations getAnnotations() {
|
||||
if (annotations == null) {
|
||||
annotations = new AnnotationsImpl(new ArrayList<AnnotationDescriptor>(0));
|
||||
}
|
||||
return annotations;
|
||||
}
|
||||
|
||||
public void addAnnotations(@NotNull Iterable<AnnotationDescriptor> annotationsToAdd) {
|
||||
List<AnnotationDescriptor> annotations = ((AnnotationsImpl) getAnnotations()).getAnnotationDescriptors();
|
||||
for (AnnotationDescriptor annotationDescriptor : annotationsToAdd) {
|
||||
annotations.add(annotationDescriptor);
|
||||
}
|
||||
}
|
||||
|
||||
public void setModality(@NotNull Modality modality) {
|
||||
this.modality = modality;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Modality getModality() {
|
||||
return modality;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ClassKind getKind() {
|
||||
return kind;
|
||||
}
|
||||
|
||||
public void setVisibility(@NotNull Visibility visibility) {
|
||||
this.visibility = visibility;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Visibility getVisibility() {
|
||||
return visibility;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInner() {
|
||||
return isInner;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public TypeConstructor getTypeConstructor() {
|
||||
return typeConstructor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Collection<JetType> getSupertypes() {
|
||||
return supertypes;
|
||||
}
|
||||
|
||||
public void setSupertypes(@NotNull Collection<JetType> supertypes) {
|
||||
this.supertypes = supertypes;
|
||||
}
|
||||
|
||||
public void addSupertype(@NotNull JetType supertype) {
|
||||
assert !supertype.isError() : "Error types must be filtered out in DescriptorResolver";
|
||||
if (TypeUtils.getClassDescriptor(supertype) != null) {
|
||||
// See the Errors.SUPERTYPE_NOT_A_CLASS_OR_TRAIT
|
||||
supertypes.add(supertype);
|
||||
}
|
||||
}
|
||||
|
||||
public void setPrimaryConstructor(@NotNull ConstructorDescriptor constructorDescriptor) {
|
||||
assert primaryConstructor == null : "Primary constructor assigned twice " + this;
|
||||
@@ -127,20 +220,27 @@ public class MutableClassDescriptor extends MutableClassDescriptorLite implement
|
||||
return allCallableMembers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTypeParameterDescriptors(List<TypeParameterDescriptor> typeParameters) {
|
||||
super.setTypeParameterDescriptors(typeParameters);
|
||||
public void setTypeParameterDescriptors(@NotNull List<TypeParameterDescriptor> typeParameters) {
|
||||
if (this.typeParameters != null) {
|
||||
throw new IllegalStateException("Type parameters are already set for " + getName());
|
||||
}
|
||||
this.typeParameters = new ArrayList<TypeParameterDescriptor>(typeParameters);
|
||||
for (TypeParameterDescriptor typeParameterDescriptor : typeParameters) {
|
||||
scopeForSupertypeResolution.addTypeParameterDescriptor(typeParameterDescriptor);
|
||||
}
|
||||
scopeForSupertypeResolution.changeLockLevel(WritableScope.LockLevel.READING);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public void createTypeConstructor() {
|
||||
super.createTypeConstructor();
|
||||
assert typeConstructor == null : typeConstructor;
|
||||
this.typeConstructor = new TypeConstructorImpl(
|
||||
this,
|
||||
Annotations.EMPTY, // TODO : pass annotations from the class?
|
||||
!getModality().isOverridable(),
|
||||
getName().asString(),
|
||||
typeParameters,
|
||||
supertypes
|
||||
);
|
||||
for (FunctionDescriptor functionDescriptor : getConstructors()) {
|
||||
((ConstructorDescriptorImpl) functionDescriptor).setReturnType(getDefaultType());
|
||||
}
|
||||
@@ -178,9 +278,27 @@ public class MutableClassDescriptor extends MutableClassDescriptorLite implement
|
||||
.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||
}
|
||||
|
||||
public void setScopeForMemberLookup(@NotNull JetScope scopeForMemberLookup) {
|
||||
this.scopeForMemberLookup = scopeForMemberLookup;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JetScope getScopeForMemberLookup() {
|
||||
return scopeForMemberLookup;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private WritableScope getScopeForMemberLookupAsWritableScope() {
|
||||
// hack
|
||||
return (WritableScope) scopeForMemberLookup;
|
||||
}
|
||||
|
||||
public void lockScopes() {
|
||||
super.lockScopes();
|
||||
getScopeForMemberLookupAsWritableScope().changeLockLevel(WritableScope.LockLevel.READING);
|
||||
if (classObjectDescriptor != null) {
|
||||
classObjectDescriptor.lockScopes();
|
||||
}
|
||||
scopeForSupertypeResolution.changeLockLevel(WritableScope.LockLevel.READING);
|
||||
scopeForMemberResolution.changeLockLevel(WritableScope.LockLevel.READING);
|
||||
getWritableScopeForInitializers().changeLockLevel(WritableScope.LockLevel.READING);
|
||||
@@ -188,26 +306,25 @@ public class MutableClassDescriptor extends MutableClassDescriptorLite implement
|
||||
|
||||
private PackageLikeBuilder builder = null;
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public PackageLikeBuilder getBuilder() {
|
||||
if (builder == null) {
|
||||
final PackageLikeBuilder superBuilder = super.getBuilder();
|
||||
builder = new PackageLikeBuilder() {
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclarationDescriptor getOwnerForChildren() {
|
||||
return superBuilder.getOwnerForChildren();
|
||||
return MutableClassDescriptor.this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addClassifierDescriptor(@NotNull MutableClassDescriptorLite classDescriptor) {
|
||||
superBuilder.addClassifierDescriptor(classDescriptor);
|
||||
public void addClassifierDescriptor(@NotNull MutableClassDescriptor classDescriptor) {
|
||||
getScopeForMemberLookupAsWritableScope().addClassifierDescriptor(classDescriptor);
|
||||
scopeForMemberResolution.addClassifierDescriptor(classDescriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFunctionDescriptor(@NotNull SimpleFunctionDescriptor functionDescriptor) {
|
||||
superBuilder.addFunctionDescriptor(functionDescriptor);
|
||||
getScopeForMemberLookupAsWritableScope().addFunctionDescriptor(functionDescriptor);
|
||||
functions.add(functionDescriptor);
|
||||
if (functionDescriptor.getKind().isReal()) {
|
||||
declaredCallableMembers.add(functionDescriptor);
|
||||
@@ -217,12 +334,18 @@ public class MutableClassDescriptor extends MutableClassDescriptorLite implement
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassObjectStatus setClassObjectDescriptor(@NotNull MutableClassDescriptorLite classObjectDescriptor) {
|
||||
ClassObjectStatus r = superBuilder.setClassObjectDescriptor(classObjectDescriptor);
|
||||
if (r != ClassObjectStatus.OK) {
|
||||
return r;
|
||||
public ClassObjectStatus setClassObjectDescriptor(@NotNull MutableClassDescriptor classObjectDescriptor) {
|
||||
if (getKind() == ClassKind.CLASS_OBJECT || isInner()) {
|
||||
return ClassObjectStatus.NOT_ALLOWED;
|
||||
}
|
||||
|
||||
if (MutableClassDescriptor.this.classObjectDescriptor != null) {
|
||||
return ClassObjectStatus.DUPLICATE;
|
||||
}
|
||||
|
||||
assert classObjectDescriptor.getKind() == ClassKind.CLASS_OBJECT;
|
||||
MutableClassDescriptor.this.classObjectDescriptor = classObjectDescriptor;
|
||||
|
||||
// Members of the class object are accessible from the class
|
||||
// The scope must be lazy, because classObjectDescriptor may not by fully built yet
|
||||
scopeForMemberResolution.importScope(new ClassObjectMixinScope(classObjectDescriptor));
|
||||
@@ -232,7 +355,7 @@ public class MutableClassDescriptor extends MutableClassDescriptorLite implement
|
||||
|
||||
@Override
|
||||
public void addPropertyDescriptor(@NotNull PropertyDescriptor propertyDescriptor) {
|
||||
superBuilder.addPropertyDescriptor(propertyDescriptor);
|
||||
getScopeForMemberLookupAsWritableScope().addPropertyDescriptor(propertyDescriptor);
|
||||
properties.add(propertyDescriptor);
|
||||
if (propertyDescriptor.getKind().isReal()) {
|
||||
declaredCallableMembers.add(propertyDescriptor);
|
||||
|
||||
-249
@@ -1,249 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors.impl;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationsImpl;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeConstructor;
|
||||
import org.jetbrains.jet.lang.types.TypeConstructorImpl;
|
||||
import org.jetbrains.jet.lang.types.TypeUtils;
|
||||
import org.jetbrains.jet.renderer.DescriptorRenderer;
|
||||
import org.jetbrains.jet.storage.LockBasedStorageManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class MutableClassDescriptorLite extends ClassDescriptorBase {
|
||||
|
||||
private Annotations annotations;
|
||||
|
||||
private List<TypeParameterDescriptor> typeParameters;
|
||||
private Collection<JetType> supertypes = Lists.newArrayList();
|
||||
|
||||
private TypeConstructor typeConstructor;
|
||||
|
||||
private Modality modality;
|
||||
private Visibility visibility;
|
||||
|
||||
private final boolean isInner;
|
||||
|
||||
private MutableClassDescriptorLite classObjectDescriptor;
|
||||
private final ClassKind kind;
|
||||
|
||||
private JetScope scopeForMemberLookup;
|
||||
|
||||
public MutableClassDescriptorLite(@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull Name name,
|
||||
@NotNull ClassKind kind,
|
||||
boolean isInner
|
||||
) {
|
||||
super(LockBasedStorageManager.NO_LOCKS, containingDeclaration, name);
|
||||
this.kind = kind;
|
||||
this.isInner = isInner;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public TypeConstructor getTypeConstructor() {
|
||||
return typeConstructor;
|
||||
}
|
||||
|
||||
public void setScopeForMemberLookup(@NotNull JetScope scopeForMemberLookup) {
|
||||
this.scopeForMemberLookup = scopeForMemberLookup;
|
||||
}
|
||||
|
||||
public void createTypeConstructor() {
|
||||
assert typeConstructor == null : typeConstructor;
|
||||
this.typeConstructor = new TypeConstructorImpl(
|
||||
this,
|
||||
Annotations.EMPTY, // TODO : pass annotations from the class?
|
||||
!getModality().isOverridable(),
|
||||
getName().asString(),
|
||||
typeParameters,
|
||||
supertypes);
|
||||
}
|
||||
|
||||
private WritableScope getScopeForMemberLookupAsWritableScope() {
|
||||
// hack
|
||||
return (WritableScope) scopeForMemberLookup;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JetScope getScopeForMemberLookup() {
|
||||
return scopeForMemberLookup;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ClassKind getKind() {
|
||||
return kind;
|
||||
}
|
||||
|
||||
public void setModality(Modality modality) {
|
||||
this.modality = modality;
|
||||
}
|
||||
|
||||
public void setVisibility(Visibility visibility) {
|
||||
this.visibility = visibility;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Modality getModality() {
|
||||
return modality;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Visibility getVisibility() {
|
||||
return visibility;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInner() {
|
||||
return isInner;
|
||||
}
|
||||
|
||||
public Collection<JetType> getSupertypes() {
|
||||
return supertypes;
|
||||
}
|
||||
|
||||
public void setSupertypes(@NotNull Collection<JetType> supertypes) {
|
||||
this.supertypes = supertypes;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public MutableClassDescriptorLite getClassObjectDescriptor() {
|
||||
return classObjectDescriptor;
|
||||
}
|
||||
|
||||
public void addSupertype(@NotNull JetType supertype) {
|
||||
assert !supertype.isError() : "Error types must be filtered out in DescriptorResolver";
|
||||
if (TypeUtils.getClassDescriptor(supertype) != null) {
|
||||
// See the Errors.SUPERTYPE_NOT_A_CLASS_OR_TRAIT
|
||||
supertypes.add(supertype);
|
||||
}
|
||||
}
|
||||
|
||||
public void setTypeParameterDescriptors(List<TypeParameterDescriptor> typeParameters) {
|
||||
if (this.typeParameters != null) {
|
||||
throw new IllegalStateException("Type parameters are already set for " + getName());
|
||||
}
|
||||
this.typeParameters = new ArrayList<TypeParameterDescriptor>();
|
||||
for (TypeParameterDescriptor typeParameterDescriptor : typeParameters) {
|
||||
this.typeParameters.add(typeParameterDescriptor);
|
||||
}
|
||||
}
|
||||
|
||||
public void lockScopes() {
|
||||
getScopeForMemberLookupAsWritableScope().changeLockLevel(WritableScope.LockLevel.READING);
|
||||
if (classObjectDescriptor != null) {
|
||||
classObjectDescriptor.lockScopes();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
try {
|
||||
return DescriptorRenderer.TEXT.render(this) + "[" + getClass().getCanonicalName() + "@" + System.identityHashCode(this) + "]";
|
||||
} catch (Throwable e) {
|
||||
return super.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Annotations getAnnotations() {
|
||||
if (annotations == null) {
|
||||
annotations = new AnnotationsImpl(new ArrayList<AnnotationDescriptor>(0));
|
||||
}
|
||||
return annotations;
|
||||
}
|
||||
|
||||
public void setAnnotations(Annotations annotations) {
|
||||
this.annotations = annotations;
|
||||
}
|
||||
|
||||
public void addAnnotations(@NotNull Iterable<AnnotationDescriptor> annotationDescriptors) {
|
||||
|
||||
AnnotationsImpl annotationsImpl = (AnnotationsImpl) getAnnotations();
|
||||
for (AnnotationDescriptor annotationDescriptor : annotationDescriptors) {
|
||||
annotationsImpl.getAnnotationDescriptors().add(annotationDescriptor);
|
||||
}
|
||||
}
|
||||
|
||||
private PackageLikeBuilder builder = null;
|
||||
|
||||
@NotNull
|
||||
public PackageLikeBuilder getBuilder() {
|
||||
if (builder == null) {
|
||||
builder = new PackageLikeBuilder() {
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclarationDescriptor getOwnerForChildren() {
|
||||
return MutableClassDescriptorLite.this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addClassifierDescriptor(@NotNull MutableClassDescriptorLite classDescriptor) {
|
||||
getScopeForMemberLookupAsWritableScope().addClassifierDescriptor(classDescriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFunctionDescriptor(@NotNull SimpleFunctionDescriptor functionDescriptor) {
|
||||
getScopeForMemberLookupAsWritableScope().addFunctionDescriptor(functionDescriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPropertyDescriptor(@NotNull PropertyDescriptor propertyDescriptor) {
|
||||
getScopeForMemberLookupAsWritableScope().addPropertyDescriptor(propertyDescriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassObjectStatus setClassObjectDescriptor(@NotNull MutableClassDescriptorLite classObjectDescriptor) {
|
||||
if (getKind() == ClassKind.CLASS_OBJECT || isInner()) {
|
||||
return ClassObjectStatus.NOT_ALLOWED;
|
||||
}
|
||||
|
||||
if (MutableClassDescriptorLite.this.classObjectDescriptor != null) {
|
||||
return ClassObjectStatus.DUPLICATE;
|
||||
}
|
||||
|
||||
assert classObjectDescriptor.getKind() == ClassKind.CLASS_OBJECT;
|
||||
MutableClassDescriptorLite.this.classObjectDescriptor = classObjectDescriptor;
|
||||
|
||||
return ClassObjectStatus.OK;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
+2
-3
@@ -22,11 +22,10 @@ import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor;
|
||||
|
||||
public interface PackageLikeBuilder {
|
||||
|
||||
@NotNull
|
||||
DeclarationDescriptor getOwnerForChildren();
|
||||
|
||||
void addClassifierDescriptor(@NotNull MutableClassDescriptorLite classDescriptor);
|
||||
void addClassifierDescriptor(@NotNull MutableClassDescriptor classDescriptor);
|
||||
|
||||
void addFunctionDescriptor(@NotNull SimpleFunctionDescriptor functionDescriptor);
|
||||
|
||||
@@ -38,5 +37,5 @@ public interface PackageLikeBuilder {
|
||||
NOT_ALLOWED
|
||||
}
|
||||
|
||||
ClassObjectStatus setClassObjectDescriptor(@NotNull MutableClassDescriptorLite classObjectDescriptor);
|
||||
ClassObjectStatus setClassObjectDescriptor(@NotNull MutableClassDescriptor classObjectDescriptor);
|
||||
}
|
||||
|
||||
+2
-2
@@ -29,7 +29,7 @@ public class PackageLikeBuilderDummy implements PackageLikeBuilder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addClassifierDescriptor(@NotNull MutableClassDescriptorLite classDescriptor) {
|
||||
public void addClassifierDescriptor(@NotNull MutableClassDescriptor classDescriptor) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public class PackageLikeBuilderDummy implements PackageLikeBuilder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassObjectStatus setClassObjectDescriptor(@NotNull MutableClassDescriptorLite classObjectDescriptor) {
|
||||
public ClassObjectStatus setClassObjectDescriptor(@NotNull MutableClassDescriptor classObjectDescriptor) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -41,7 +41,7 @@ public class ScopeBasedPackageLikeBuilder implements PackageLikeBuilder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addClassifierDescriptor(@NotNull MutableClassDescriptorLite classDescriptor) {
|
||||
public void addClassifierDescriptor(@NotNull MutableClassDescriptor classDescriptor) {
|
||||
scope.addClassifierDescriptor(classDescriptor);
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ public class ScopeBasedPackageLikeBuilder implements PackageLikeBuilder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassObjectStatus setClassObjectDescriptor(@NotNull MutableClassDescriptorLite classObjectDescriptor) {
|
||||
public ClassObjectStatus setClassObjectDescriptor(@NotNull MutableClassDescriptor classObjectDescriptor) {
|
||||
throw new IllegalStateException("Must be guaranteed not to happen by the parser");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user