diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/binding/CodegenAnnotatingVisitor.java b/compiler/backend/src/org/jetbrains/jet/codegen/binding/CodegenAnnotatingVisitor.java index 1d940689e91..e6e07330b09 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/binding/CodegenAnnotatingVisitor.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/binding/CodegenAnnotatingVisitor.java @@ -25,7 +25,6 @@ import org.jetbrains.annotations.Nullable; import org.jetbrains.asm4.Type; import org.jetbrains.jet.codegen.SamCodegenUtil; import org.jetbrains.jet.lang.descriptors.*; -import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; import org.jetbrains.jet.lang.descriptors.impl.ClassDescriptorImpl; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.BindingContext; @@ -93,21 +92,10 @@ class CodegenAnnotatingVisitor extends JetVisitorVoid { @NotNull private ClassDescriptor recordClassForFunction(@NotNull FunctionDescriptor funDescriptor, @NotNull JetType superType) { - ClassDescriptor classDescriptor; - - classDescriptor = new ClassDescriptorImpl( - funDescriptor.getContainingDeclaration(), - Collections.emptyList(), - Modality.FINAL, - Name.special("")); - ((ClassDescriptorImpl)classDescriptor).initialize( - false, - Collections.emptyList(), - Collections.singleton(superType), - JetScope.EMPTY, - Collections.emptySet(), - null, - false); + ClassDescriptorImpl classDescriptor = + new ClassDescriptorImpl(funDescriptor.getContainingDeclaration(), Name.special(""), Modality.FINAL, + Collections.singleton(superType)); + classDescriptor.initialize(JetScope.EMPTY, Collections.emptySet(), null); bindingTrace.record(CLASS_FOR_FUNCTION, funDescriptor, classDescriptor); return classDescriptor; diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/binding/CodegenBinding.java b/compiler/backend/src/org/jetbrains/jet/codegen/binding/CodegenBinding.java index 623a3bc7a23..f1ecf4fcc68 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/binding/CodegenBinding.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/binding/CodegenBinding.java @@ -22,7 +22,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.asm4.Type; import org.jetbrains.jet.lang.descriptors.*; -import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; import org.jetbrains.jet.lang.descriptors.impl.ClassDescriptorImpl; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.BindingContext; @@ -141,19 +140,10 @@ public class CodegenBinding { @NotNull ScriptDescriptor scriptDescriptor, @NotNull Type asmType ) { - ClassDescriptorImpl classDescriptor = new ClassDescriptorImpl( - scriptDescriptor, - Collections.emptyList(), - Modality.FINAL, - Name.special("")); - classDescriptor.initialize( - false, - Collections.emptyList(), - Collections.singletonList(KotlinBuiltIns.getInstance().getAnyType()), - JetScope.EMPTY, - Collections.emptySet(), - null, - false); + ClassDescriptorImpl classDescriptor = + new ClassDescriptorImpl(scriptDescriptor, Name.special(""), Modality.FINAL, + Collections.singleton(KotlinBuiltIns.getInstance().getAnyType())); + classDescriptor.initialize(JetScope.EMPTY, Collections.emptySet(), null); recordClosure(bindingTrace, null, classDescriptor, null, asmType); diff --git a/compiler/frontend/serialization/src/org/jetbrains/jet/descriptors/serialization/DescriptorDeserializer.java b/compiler/frontend/serialization/src/org/jetbrains/jet/descriptors/serialization/DescriptorDeserializer.java index f78bb97fdf8..64bb425799b 100644 --- a/compiler/frontend/serialization/src/org/jetbrains/jet/descriptors/serialization/DescriptorDeserializer.java +++ b/compiler/frontend/serialization/src/org/jetbrains/jet/descriptors/serialization/DescriptorDeserializer.java @@ -27,8 +27,8 @@ import org.jetbrains.jet.lang.resolve.DescriptorFactory; import org.jetbrains.jet.lang.resolve.DescriptorUtils; import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe; import org.jetbrains.jet.lang.resolve.name.Name; -import org.jetbrains.jet.lang.types.ErrorUtils; import org.jetbrains.jet.lang.types.Variance; +import org.jetbrains.jet.lang.types.error.ErrorClassDescriptor; import org.jetbrains.jet.storage.StorageManager; import java.util.ArrayList; @@ -207,7 +207,7 @@ public class DescriptorDeserializer { if (objectClass == null) { // if we are not able to find the class for object property // then something bad has happened since they should be in the same jar - objectClass = ErrorUtils.createErrorClass(objectId.asSingleFqName().asString()); + objectClass = new ErrorClassDescriptor(objectId.asSingleFqName().asString()); } return new PropertyDescriptorForObjectImpl(containingDeclaration, annotations, visibility, name, objectClass); } diff --git a/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/resolver/JavaPropertyResolver.java b/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/resolver/JavaPropertyResolver.java index b9af4dae72d..4aaae995288 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/resolver/JavaPropertyResolver.java +++ b/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/resolver/JavaPropertyResolver.java @@ -145,14 +145,10 @@ public final class JavaPropertyResolver { //TODO: this is a hack to indicate that this enum entry is an object // class descriptor for enum entries is not used by backends so for now this should be safe to use ClassDescriptorImpl dummyClassDescriptorForEnumEntryObject = - new ClassDescriptorImpl(owner, Collections.emptyList(), Modality.FINAL, propertyName); - dummyClassDescriptorForEnumEntryObject.initialize( - true, - Collections.emptyList(), - Collections.emptyList(), JetScope.EMPTY, - Collections.emptySet(), null, - false); - return new JavaPropertyDescriptorForObject(owner, annotations, visibility, propertyName, dummyClassDescriptorForEnumEntryObject); + new ClassDescriptorImpl(owner, propertyName, Modality.FINAL, Collections.emptyList()); + dummyClassDescriptorForEnumEntryObject.initialize(JetScope.EMPTY, Collections.emptySet(), null); + return new JavaPropertyDescriptorForObject(owner, annotations, visibility, propertyName, + dummyClassDescriptorForEnumEntryObject); } return new JavaPropertyDescriptor(owner, annotations, visibility, isVar, propertyName); diff --git a/core/descriptors/src/org/jetbrains/jet/lang/descriptors/ScriptDescriptor.java b/core/descriptors/src/org/jetbrains/jet/lang/descriptors/ScriptDescriptor.java index 1c9d22cccbe..4e288ccc165 100644 --- a/core/descriptors/src/org/jetbrains/jet/lang/descriptors/ScriptDescriptor.java +++ b/core/descriptors/src/org/jetbrains/jet/lang/descriptors/ScriptDescriptor.java @@ -64,21 +64,11 @@ public class ScriptDescriptor extends DeclarationDescriptorNonRootImpl { super(containingDeclaration, Collections.emptyList(), NAME); this.priority = priority; - classDescriptor = new ClassDescriptorImpl( - containingDeclaration, - Collections.emptyList(), - Modality.FINAL, - className); + classDescriptor = new ClassDescriptorImpl(containingDeclaration, className, Modality.FINAL, + Collections.singleton(KotlinBuiltIns.getInstance().getAnyType())); classScope = new WritableScopeImpl(scriptScope, containingDeclaration, RedeclarationHandler.DO_NOTHING, "script members"); classScope.changeLockLevel(WritableScope.LockLevel.BOTH); - classDescriptor.initialize( - false, - Collections.emptyList(), - Collections.singletonList(KotlinBuiltIns.getInstance().getAnyType()), - classScope, - new HashSet(), - null, - false); + classDescriptor.initialize(classScope, new HashSet(), null); } public void initialize( diff --git a/core/descriptors/src/org/jetbrains/jet/lang/descriptors/impl/ClassDescriptorImpl.java b/core/descriptors/src/org/jetbrains/jet/lang/descriptors/impl/ClassDescriptorImpl.java index 843be78b06c..78c79058727 100644 --- a/core/descriptors/src/org/jetbrains/jet/lang/descriptors/impl/ClassDescriptorImpl.java +++ b/core/descriptors/src/org/jetbrains/jet/lang/descriptors/impl/ClassDescriptorImpl.java @@ -16,6 +16,7 @@ package org.jetbrains.jet.lang.descriptors.impl; +import jet.Function0; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.descriptors.*; @@ -23,70 +24,64 @@ import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; import org.jetbrains.jet.lang.resolve.DescriptorFactory; import org.jetbrains.jet.lang.resolve.name.Name; import org.jetbrains.jet.lang.resolve.scopes.JetScope; -import org.jetbrains.jet.lang.resolve.scopes.SubstitutingScope; -import org.jetbrains.jet.lang.types.*; +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.storage.LockBasedStorageManager; +import org.jetbrains.jet.storage.NotNullLazyValue; import java.util.Collection; +import java.util.Collections; import java.util.List; -import java.util.Map; import java.util.Set; -public class ClassDescriptorImpl extends DeclarationDescriptorNonRootImpl implements ClassDescriptor { - private TypeConstructor typeConstructor; +public class ClassDescriptorImpl extends ClassDescriptorBase { + private final Modality modality; + private final TypeConstructor typeConstructor; + private final NotNullLazyValue thisAsReceiverParameter; - private JetScope memberDeclarations; + private JetScope scopeForMemberLookup; private Set constructors; private ConstructorDescriptor primaryConstructor; - private ReceiverParameterDescriptor thisAsReceiverParameter; - private final Modality modality; - private ClassDescriptor classObjectDescriptor; - private final ClassKind kind; - private boolean isInner; - - public ClassDescriptorImpl( - @NotNull DeclarationDescriptor containingDeclaration, - @NotNull List annotations, - @NotNull Modality modality, - @NotNull Name name - ) { - this(containingDeclaration, ClassKind.CLASS, annotations, modality, name); - } public ClassDescriptorImpl( @NotNull DeclarationDescriptor containingDeclaration, - @NotNull ClassKind kind, - @NotNull List annotations, + @NotNull Name name, @NotNull Modality modality, - @NotNull Name name) { - super(containingDeclaration, annotations, name); - this.kind = kind; + @NotNull Collection supertypes + ) { + super(LockBasedStorageManager.NO_LOCKS, containingDeclaration, name); this.modality = modality; + + this.typeConstructor = new TypeConstructorImpl(this, Collections.emptyList(), false, getName().asString(), + Collections.emptyList(), supertypes); + + this.thisAsReceiverParameter = LockBasedStorageManager.NO_LOCKS.createLazyValue(new Function0() { + @Override + public ReceiverParameterDescriptor invoke() { + return DescriptorFactory.createLazyReceiverParameterDescriptor(ClassDescriptorImpl.this); + } + }); } - - public final ClassDescriptorImpl initialize( - boolean isFinal, - @NotNull List typeParameters, - @NotNull Collection supertypes, - @NotNull JetScope memberDeclarations, + public final void initialize( + @NotNull JetScope scopeForMemberLookup, @NotNull Set constructors, - @Nullable ConstructorDescriptor primaryConstructor, - boolean isInner + @Nullable ConstructorDescriptor primaryConstructor ) { - this.typeConstructor = new TypeConstructorImpl(this, getAnnotations(), isFinal, getName().asString(), typeParameters, supertypes); - this.memberDeclarations = memberDeclarations; + this.scopeForMemberLookup = scopeForMemberLookup; this.constructors = constructors; this.primaryConstructor = primaryConstructor; - this.isInner = isInner; - return this; } public void setPrimaryConstructor(@NotNull ConstructorDescriptor primaryConstructor) { this.primaryConstructor = primaryConstructor; } - public void setClassObjectDescriptor(@NotNull ClassDescriptor classObjectDescriptor) { - this.classObjectDescriptor = classObjectDescriptor; + @NotNull + @Override + public List getAnnotations() { + return Collections.emptyList(); } @Override @@ -95,24 +90,6 @@ public class ClassDescriptorImpl extends DeclarationDescriptorNonRootImpl implem return typeConstructor; } - @Override - @NotNull - public JetScope getMemberScope(List typeArguments) { - assert typeArguments.size() == typeConstructor.getParameters().size() : "Wrong number or arguments: " + typeArguments + " for " + this; - if (typeConstructor.getParameters().isEmpty()) { - return memberDeclarations; - } - Map substitutionContext = SubstitutionUtils - .buildSubstitutionContext(typeConstructor.getParameters(), typeArguments); - return new SubstitutingScope(memberDeclarations, TypeSubstitutor.create(substitutionContext)); - } - - @NotNull - @Override - public JetType getDefaultType() { - return TypeUtils.makeUnsubstitutedType(this, memberDeclarations); - } - @NotNull @Override public Collection getConstructors() { @@ -121,29 +98,20 @@ public class ClassDescriptorImpl extends DeclarationDescriptorNonRootImpl implem @NotNull @Override - public ClassDescriptor substitute(@NotNull TypeSubstitutor substitutor) { - throw new UnsupportedOperationException(); // TODO - } - - @Override - public JetType getClassObjectType() { - return getClassObjectDescriptor().getDefaultType(); + protected JetScope getScopeForMemberLookup() { + return scopeForMemberLookup; } + @Nullable @Override public ClassDescriptor getClassObjectDescriptor() { - return classObjectDescriptor; + return null; } @NotNull @Override public ClassKind getKind() { - return kind; - } - - @Override - public R accept(DeclarationDescriptorVisitor visitor, D data) { - return visitor.visitClassDescriptor(this, data); + return ClassKind.CLASS; } @Override @@ -165,21 +133,17 @@ public class ClassDescriptorImpl extends DeclarationDescriptorNonRootImpl implem @Override public boolean isInner() { - return isInner; + return false; } @NotNull @Override public ReceiverParameterDescriptor getThisAsReceiverParameter() { - if (thisAsReceiverParameter == null) { - thisAsReceiverParameter = DescriptorFactory.createLazyReceiverParameterDescriptor(this); - } - return thisAsReceiverParameter; + return thisAsReceiverParameter.invoke(); } - @NotNull @Override - public JetScope getUnsubstitutedInnerClassesScope() { - return JetScope.EMPTY; + public String toString() { + return "class " + getName(); } } diff --git a/core/descriptors/src/org/jetbrains/jet/lang/types/ErrorUtils.java b/core/descriptors/src/org/jetbrains/jet/lang/types/ErrorUtils.java index a68cf7d88c8..559ba5b6d9a 100644 --- a/core/descriptors/src/org/jetbrains/jet/lang/types/ErrorUtils.java +++ b/core/descriptors/src/org/jetbrains/jet/lang/types/ErrorUtils.java @@ -22,7 +22,6 @@ import org.jetbrains.jet.lang.ModuleConfiguration; import org.jetbrains.jet.lang.PlatformToKotlinClassMap; import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; -import org.jetbrains.jet.lang.descriptors.impl.ConstructorDescriptorImpl; import org.jetbrains.jet.lang.descriptors.impl.PropertyDescriptorImpl; import org.jetbrains.jet.lang.descriptors.impl.TypeParameterDescriptorImpl; import org.jetbrains.jet.lang.resolve.ImportPath; @@ -255,24 +254,6 @@ public class ErrorUtils { private static final ErrorClassDescriptor ERROR_CLASS = new ErrorClassDescriptor(""); - private static final Set ERROR_CONSTRUCTOR_GROUP = Collections.singleton(createErrorConstructor()); - - private static final ConstructorDescriptor ERROR_CONSTRUCTOR = new ConstructorDescriptorImpl(ERROR_CLASS, Collections.emptyList(), true); - - static { - ERROR_CLASS.initializeErrorClass(); - } - - @NotNull - public static Set getErrorConstructorGroup() { - return ERROR_CONSTRUCTOR_GROUP; - } - - @NotNull - public static ConstructorDescriptor getErrorConstructor() { - return ERROR_CONSTRUCTOR; - } - @NotNull public static JetScope createErrorScope(@NotNull String debugMessage) { return createErrorScope(debugMessage, false); @@ -316,18 +297,6 @@ public class ErrorUtils { return function; } - @NotNull - private static ConstructorDescriptor createErrorConstructor() { - ConstructorDescriptorImpl r = new ConstructorDescriptorImpl(ERROR_CLASS, Collections.emptyList(), false); - r.initialize( - Collections.emptyList(), // TODO - Collections.emptyList(), // TODO - Visibilities.INTERNAL - ); - r.setReturnType(createErrorType("")); - return r; - } - @NotNull public static JetType createErrorType(@NotNull String debugMessage) { return new ErrorTypeImpl(createErrorTypeConstructor(debugMessage), createErrorScope(debugMessage)); @@ -373,13 +342,6 @@ public class ErrorUtils { return candidate instanceof ErrorClassDescriptor; } - @NotNull - public static ErrorClassDescriptor createErrorClass(@NotNull String debugMessage) { - ErrorClassDescriptor result = new ErrorClassDescriptor(debugMessage); - result.initializeErrorClass(); - return result; - } - private static class ErrorTypeImpl implements JetType { private final TypeConstructor constructor; private final JetScope memberScope; diff --git a/core/descriptors/src/org/jetbrains/jet/lang/types/error/ErrorClassDescriptor.java b/core/descriptors/src/org/jetbrains/jet/lang/types/error/ErrorClassDescriptor.java index 4fa01e93e9c..115aa51ea0b 100644 --- a/core/descriptors/src/org/jetbrains/jet/lang/types/error/ErrorClassDescriptor.java +++ b/core/descriptors/src/org/jetbrains/jet/lang/types/error/ErrorClassDescriptor.java @@ -17,38 +17,33 @@ package org.jetbrains.jet.lang.types.error; import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.lang.descriptors.ClassDescriptor; -import org.jetbrains.jet.lang.descriptors.ConstructorDescriptor; -import org.jetbrains.jet.lang.descriptors.Modality; -import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor; +import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; import org.jetbrains.jet.lang.descriptors.impl.ClassDescriptorImpl; +import org.jetbrains.jet.lang.descriptors.impl.ConstructorDescriptorImpl; import org.jetbrains.jet.lang.resolve.name.Name; -import org.jetbrains.jet.lang.types.ErrorUtils; import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.TypeSubstitutor; -import java.util.Collection; import java.util.Collections; import static org.jetbrains.jet.lang.types.ErrorUtils.*; public final class ErrorClassDescriptor extends ClassDescriptorImpl { public ErrorClassDescriptor(@NotNull String debugMessage) { - super(ErrorUtils.getErrorModule(), Collections.emptyList(), Modality.OPEN, - Name.special("")); - } + super(getErrorModule(), Name.special(""), Modality.OPEN, Collections.emptyList()); - @NotNull - @Override - public Collection getConstructors() { - return getErrorConstructorGroup(); - } + ConstructorDescriptorImpl errorConstructor = + new ConstructorDescriptorImpl(this, Collections.emptyList(), true); - @NotNull - @Override - public Modality getModality() { - return Modality.OPEN; + errorConstructor.initialize( + Collections.emptyList(), // TODO + Collections.emptyList(), // TODO + Visibilities.INTERNAL + ); + errorConstructor.setReturnType(createErrorType("")); + + initialize(createErrorScope("ERROR_CLASS"), Collections.singleton(errorConstructor), errorConstructor); } @NotNull @@ -61,9 +56,4 @@ public final class ErrorClassDescriptor extends ClassDescriptorImpl { public String toString() { return getName().asString(); } - - public void initializeErrorClass() { - initialize(true, Collections.emptyList(), Collections.emptyList(), - createErrorScope("ERROR_CLASS"), getErrorConstructorGroup(), getErrorConstructor(), false); - } }