From 68d60f2b8b2e05d144d709ccd8d177df3155e806 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Tue, 15 Mar 2011 13:52:16 +0300 Subject: [PATCH] DeclarationDescriptors returned from type constructors --- .../lang/resolve/ClassDescriptorResolver.java | 1 + .../jet/lang/types/ClassDescriptorImpl.java | 2 +- .../jetbrains/jet/lang/types/ErrorType.java | 2 +- .../jet/lang/types/TypeConstructor.java | 21 ++++++++++++++++++- .../lang/types/TypeParameterDescriptor.java | 1 + .../jetbrains/jet/lang/types/TypeUtils.java | 2 +- 6 files changed, 25 insertions(+), 4 deletions(-) diff --git a/idea/src/org/jetbrains/jet/lang/resolve/ClassDescriptorResolver.java b/idea/src/org/jetbrains/jet/lang/resolve/ClassDescriptorResolver.java index 39c51898779..362b07bb968 100644 --- a/idea/src/org/jetbrains/jet/lang/resolve/ClassDescriptorResolver.java +++ b/idea/src/org/jetbrains/jet/lang/resolve/ClassDescriptorResolver.java @@ -70,6 +70,7 @@ public class ClassDescriptorResolver { descriptor.setTypeConstructor( new TypeConstructor( + descriptor, AttributeResolver.INSTANCE.resolveAttributes(classElement.getModifierList()), !open, classElement.getName(), diff --git a/idea/src/org/jetbrains/jet/lang/types/ClassDescriptorImpl.java b/idea/src/org/jetbrains/jet/lang/types/ClassDescriptorImpl.java index ee13b809591..af7d0c4fefd 100644 --- a/idea/src/org/jetbrains/jet/lang/types/ClassDescriptorImpl.java +++ b/idea/src/org/jetbrains/jet/lang/types/ClassDescriptorImpl.java @@ -33,7 +33,7 @@ public class ClassDescriptorImpl extends DeclarationDescriptorImpl implements Cl public final ClassDescriptorImpl initialize(boolean sealed, List typeParameters, Collection superclasses, JetScope memberDeclarations) { - this.typeConstructor = new TypeConstructor(getAttributes(), sealed, getName(), typeParameters, superclasses); + this.typeConstructor = new TypeConstructor(this, getAttributes(), sealed, getName(), typeParameters, superclasses); this.memberDeclarations = memberDeclarations; return this; } diff --git a/idea/src/org/jetbrains/jet/lang/types/ErrorType.java b/idea/src/org/jetbrains/jet/lang/types/ErrorType.java index 0fb7031f5cd..2cd67569608 100644 --- a/idea/src/org/jetbrains/jet/lang/types/ErrorType.java +++ b/idea/src/org/jetbrains/jet/lang/types/ErrorType.java @@ -63,7 +63,7 @@ public class ErrorType { } private static JetType createErrorType(String debugMessage, JetScope memberScope) { - return new ErrorTypeImpl(new TypeConstructor(Collections.emptyList(), false, "[ERROR : " + debugMessage + "]", Collections.emptyList(), Collections.emptyList()), memberScope); + return new ErrorTypeImpl(new TypeConstructor(null, Collections.emptyList(), false, "[ERROR : " + debugMessage + "]", Collections.emptyList(), Collections.emptyList()), memberScope); } public static JetType createWrongVarianceErrorType(TypeProjection value) { diff --git a/idea/src/org/jetbrains/jet/lang/types/TypeConstructor.java b/idea/src/org/jetbrains/jet/lang/types/TypeConstructor.java index cc1d6420b62..c49d544d4b4 100644 --- a/idea/src/org/jetbrains/jet/lang/types/TypeConstructor.java +++ b/idea/src/org/jetbrains/jet/lang/types/TypeConstructor.java @@ -1,5 +1,8 @@ package org.jetbrains.jet.lang.types; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -13,18 +16,30 @@ public class TypeConstructor extends AnnotatedImpl { private final String debugName; private final boolean sealed; - public TypeConstructor(List attributes, boolean sealed, String debugName, List parameters, Collection supertypes) { + @Nullable + private final DeclarationDescriptor declarationDescriptor; + + public TypeConstructor( + @Nullable DeclarationDescriptor declarationDescriptor, + @NotNull List attributes, + boolean sealed, + @NotNull String debugName, + @NotNull List parameters, + @NotNull Collection supertypes) { super(attributes); + this.declarationDescriptor = declarationDescriptor; this.sealed = sealed; this.debugName = debugName; this.parameters = new ArrayList(parameters); this.supertypes = supertypes; } + @NotNull public List getParameters() { return parameters; } + @NotNull public Collection getSupertypes() { return supertypes; } @@ -38,4 +53,8 @@ public class TypeConstructor extends AnnotatedImpl { return sealed; } + @Nullable + public DeclarationDescriptor getDeclarationDescriptor() { + return declarationDescriptor; + } } diff --git a/idea/src/org/jetbrains/jet/lang/types/TypeParameterDescriptor.java b/idea/src/org/jetbrains/jet/lang/types/TypeParameterDescriptor.java index 66155c96b66..f3bfd1da048 100644 --- a/idea/src/org/jetbrains/jet/lang/types/TypeParameterDescriptor.java +++ b/idea/src/org/jetbrains/jet/lang/types/TypeParameterDescriptor.java @@ -20,6 +20,7 @@ public class TypeParameterDescriptor extends DeclarationDescriptorImpl { this.upperBounds = upperBounds; // TODO: Should we actually pass the attributes on to the type constructor? this.typeConstructor = new TypeConstructor( + this, attributes, false, "&" + name, diff --git a/idea/src/org/jetbrains/jet/lang/types/TypeUtils.java b/idea/src/org/jetbrains/jet/lang/types/TypeUtils.java index b047a3685a0..5b2d571bddf 100644 --- a/idea/src/org/jetbrains/jet/lang/types/TypeUtils.java +++ b/idea/src/org/jetbrains/jet/lang/types/TypeUtils.java @@ -56,7 +56,7 @@ public class TypeUtils { } List noAttributes = Collections.emptyList(); - TypeConstructor constructor = new TypeConstructor(noAttributes, false, debugName.toString(), Collections.emptyList(), types); + TypeConstructor constructor = new TypeConstructor(null, noAttributes, false, debugName.toString(), Collections.emptyList(), types); return new JetTypeImpl( noAttributes, constructor,