isReified() for type parameters

This commit is contained in:
Andrey Breslav
2011-11-04 20:58:31 +03:00
parent e225bf5e93
commit 0e4a7ebe90
6 changed files with 24 additions and 7 deletions
@@ -189,6 +189,7 @@ public class JavaDescriptorResolver {
TypeParameterDescriptor typeParameterDescriptor = TypeParameterDescriptor.createForFurtherModification( TypeParameterDescriptor typeParameterDescriptor = TypeParameterDescriptor.createForFurtherModification(
owner, owner,
Collections.<AnnotationDescriptor>emptyList(), // TODO Collections.<AnnotationDescriptor>emptyList(), // TODO
false,
Variance.INVARIANT, Variance.INVARIANT,
typeParameter.getName(), typeParameter.getName(),
typeParameter.getIndex() typeParameter.getIndex()
@@ -21,10 +21,11 @@ public class TypeParameterDescriptor extends DeclarationDescriptorImpl implement
public static TypeParameterDescriptor createWithDefaultBound( public static TypeParameterDescriptor createWithDefaultBound(
@NotNull DeclarationDescriptor containingDeclaration, @NotNull DeclarationDescriptor containingDeclaration,
@NotNull List<AnnotationDescriptor> annotations, @NotNull List<AnnotationDescriptor> annotations,
boolean reified,
@NotNull Variance variance, @NotNull Variance variance,
@NotNull String name, @NotNull String name,
int index) { int index) {
TypeParameterDescriptor typeParameterDescriptor = createForFurtherModification(containingDeclaration, annotations, variance, name, index); TypeParameterDescriptor typeParameterDescriptor = createForFurtherModification(containingDeclaration, annotations, reified, variance, name, index);
typeParameterDescriptor.addUpperBound(JetStandardClasses.getDefaultBound()); typeParameterDescriptor.addUpperBound(JetStandardClasses.getDefaultBound());
return typeParameterDescriptor; return typeParameterDescriptor;
} }
@@ -32,10 +33,11 @@ public class TypeParameterDescriptor extends DeclarationDescriptorImpl implement
public static TypeParameterDescriptor createForFurtherModification( public static TypeParameterDescriptor createForFurtherModification(
@NotNull DeclarationDescriptor containingDeclaration, @NotNull DeclarationDescriptor containingDeclaration,
@NotNull List<AnnotationDescriptor> annotations, @NotNull List<AnnotationDescriptor> annotations,
boolean reified,
@NotNull Variance variance, @NotNull Variance variance,
@NotNull String name, @NotNull String name,
int index) { int index) {
return new TypeParameterDescriptor(containingDeclaration, annotations, variance, name, index); return new TypeParameterDescriptor(containingDeclaration, annotations, reified, variance, name, index);
} }
private final int index; private final int index;
@@ -47,9 +49,12 @@ public class TypeParameterDescriptor extends DeclarationDescriptorImpl implement
private final Set<JetType> classObjectUpperBounds = Sets.newLinkedHashSet(); private final Set<JetType> classObjectUpperBounds = Sets.newLinkedHashSet();
private JetType classObjectBoundsAsType; private JetType classObjectBoundsAsType;
private final boolean reified;
private TypeParameterDescriptor( private TypeParameterDescriptor(
@NotNull DeclarationDescriptor containingDeclaration, @NotNull DeclarationDescriptor containingDeclaration,
@NotNull List<AnnotationDescriptor> annotations, @NotNull List<AnnotationDescriptor> annotations,
boolean reified,
@NotNull Variance variance, @NotNull Variance variance,
@NotNull String name, @NotNull String name,
int index) { int index) {
@@ -57,6 +62,7 @@ public class TypeParameterDescriptor extends DeclarationDescriptorImpl implement
this.index = index; this.index = index;
this.variance = variance; this.variance = variance;
this.upperBounds = Sets.newLinkedHashSet(); this.upperBounds = Sets.newLinkedHashSet();
this.reified = reified;
// TODO: Should we actually pass the annotations on to the type constructor? // TODO: Should we actually pass the annotations on to the type constructor?
this.typeConstructor = new TypeConstructorImpl( this.typeConstructor = new TypeConstructorImpl(
this, this,
@@ -67,6 +73,10 @@ public class TypeParameterDescriptor extends DeclarationDescriptorImpl implement
upperBounds); upperBounds);
} }
public boolean isReified() {
return reified;
}
public Variance getVariance() { public Variance getVariance() {
return variance; return variance;
} }
@@ -162,6 +172,6 @@ public class TypeParameterDescriptor extends DeclarationDescriptorImpl implement
@NotNull @NotNull
public TypeParameterDescriptor copy(@NotNull DeclarationDescriptor newOwner) { public TypeParameterDescriptor copy(@NotNull DeclarationDescriptor newOwner) {
return new TypeParameterDescriptor(newOwner, Lists.newArrayList(getAnnotations()), variance, getName(), index); return new TypeParameterDescriptor(newOwner, Lists.newArrayList(getAnnotations()), reified, variance, getName(), index);
} }
} }
@@ -50,6 +50,7 @@ public class ClassDescriptorResolver {
TypeParameterDescriptor typeParameterDescriptor = TypeParameterDescriptor.createForFurtherModification( TypeParameterDescriptor typeParameterDescriptor = TypeParameterDescriptor.createForFurtherModification(
descriptor, descriptor,
annotationResolver.createAnnotationStubs(typeParameter.getModifierList()), annotationResolver.createAnnotationStubs(typeParameter.getModifierList()),
true,
typeParameter.getVariance(), typeParameter.getVariance(),
JetPsiUtil.safeName(typeParameter.getName()), JetPsiUtil.safeName(typeParameter.getName()),
index index
@@ -313,6 +314,7 @@ public class ClassDescriptorResolver {
TypeParameterDescriptor typeParameterDescriptor = TypeParameterDescriptor.createForFurtherModification( TypeParameterDescriptor typeParameterDescriptor = TypeParameterDescriptor.createForFurtherModification(
containingDescriptor, containingDescriptor,
annotationResolver.createAnnotationStubs(typeParameter.getModifierList()), annotationResolver.createAnnotationStubs(typeParameter.getModifierList()),
true,
typeParameter.getVariance(), typeParameter.getVariance(),
JetPsiUtil.safeName(typeParameter.getName()), JetPsiUtil.safeName(typeParameter.getName()),
index index
@@ -40,6 +40,7 @@ public class DescriptorSubstitutor {
TypeParameterDescriptor substituted = TypeParameterDescriptor.createForFurtherModification( TypeParameterDescriptor substituted = TypeParameterDescriptor.createForFurtherModification(
newContainingDeclaration, newContainingDeclaration,
descriptor.getAnnotations(), descriptor.getAnnotations(),
descriptor.isReified(),
descriptor.getVariance(), descriptor.getVariance(),
descriptor.getName(), descriptor.getName(),
descriptor.getIndex()); descriptor.getIndex());
@@ -116,7 +116,7 @@ public class JetStandardClasses {
parameters.add(TypeParameterDescriptor.createWithDefaultBound( parameters.add(TypeParameterDescriptor.createWithDefaultBound(
classDescriptor, classDescriptor,
Collections.<AnnotationDescriptor>emptyList(), Collections.<AnnotationDescriptor>emptyList(),
Variance.OUT_VARIANCE, "T" + j, j)); true, Variance.OUT_VARIANCE, "T" + j, j));
} }
TUPLE[i] = classDescriptor.initialize( TUPLE[i] = classDescriptor.initialize(
true, true,
@@ -159,7 +159,7 @@ public class JetStandardClasses {
parameters.add(0, TypeParameterDescriptor.createWithDefaultBound( parameters.add(0, TypeParameterDescriptor.createWithDefaultBound(
receiverFunction, receiverFunction,
Collections.<AnnotationDescriptor>emptyList(), Collections.<AnnotationDescriptor>emptyList(),
Variance.IN_VARIANCE, "T", 0)); true, Variance.IN_VARIANCE, "T", 0));
RECEIVER_FUNCTION[i] = receiverFunction.initialize( RECEIVER_FUNCTION[i] = receiverFunction.initialize(
false, false,
parameters, parameters,
@@ -174,12 +174,12 @@ public class JetStandardClasses {
parameters.add(TypeParameterDescriptor.createWithDefaultBound( parameters.add(TypeParameterDescriptor.createWithDefaultBound(
function, function,
Collections.<AnnotationDescriptor>emptyList(), Collections.<AnnotationDescriptor>emptyList(),
Variance.IN_VARIANCE, "P" + j, j + 1)); true, Variance.IN_VARIANCE, "P" + j, j + 1));
} }
parameters.add(TypeParameterDescriptor.createWithDefaultBound( parameters.add(TypeParameterDescriptor.createWithDefaultBound(
function, function,
Collections.<AnnotationDescriptor>emptyList(), Collections.<AnnotationDescriptor>emptyList(),
Variance.OUT_VARIANCE, "R", parameterCount + 1)); true, Variance.OUT_VARIANCE, "R", parameterCount + 1));
return parameters; return parameters;
} }
@@ -311,6 +311,9 @@ public class DescriptorRenderer implements Renderer {
} }
protected void renderTypeParameter(TypeParameterDescriptor descriptor, StringBuilder builder) { protected void renderTypeParameter(TypeParameterDescriptor descriptor, StringBuilder builder) {
if (!descriptor.isReified()) {
builder.append(renderKeyword("erased")).append(" ");
}
renderName(descriptor, builder); renderName(descriptor, builder);
if (!descriptor.getUpperBounds().isEmpty()) { if (!descriptor.getUpperBounds().isEmpty()) {
JetType bound = descriptor.getUpperBounds().iterator().next(); JetType bound = descriptor.getUpperBounds().iterator().next();