Indices for type parameters
This commit is contained in:
@@ -16,8 +16,9 @@ public class TypeParameterDescriptor extends DeclarationDescriptorImpl implement
|
|||||||
@NotNull DeclarationDescriptor containingDeclaration,
|
@NotNull DeclarationDescriptor containingDeclaration,
|
||||||
@NotNull List<Annotation> annotations,
|
@NotNull List<Annotation> annotations,
|
||||||
@NotNull Variance variance,
|
@NotNull Variance variance,
|
||||||
@NotNull String name) {
|
@NotNull String name,
|
||||||
TypeParameterDescriptor typeParameterDescriptor = createForFurtherModification(containingDeclaration, annotations, variance, name);
|
int index) {
|
||||||
|
TypeParameterDescriptor typeParameterDescriptor = createForFurtherModification(containingDeclaration, annotations, variance, name, index);
|
||||||
typeParameterDescriptor.addUpperBound(JetStandardClasses.getDefaultBound());
|
typeParameterDescriptor.addUpperBound(JetStandardClasses.getDefaultBound());
|
||||||
return typeParameterDescriptor;
|
return typeParameterDescriptor;
|
||||||
}
|
}
|
||||||
@@ -26,10 +27,12 @@ public class TypeParameterDescriptor extends DeclarationDescriptorImpl implement
|
|||||||
@NotNull DeclarationDescriptor containingDeclaration,
|
@NotNull DeclarationDescriptor containingDeclaration,
|
||||||
@NotNull List<Annotation> annotations,
|
@NotNull List<Annotation> annotations,
|
||||||
@NotNull Variance variance,
|
@NotNull Variance variance,
|
||||||
@NotNull String name) {
|
@NotNull String name,
|
||||||
return new TypeParameterDescriptor(containingDeclaration, annotations, variance, name);
|
int index) {
|
||||||
|
return new TypeParameterDescriptor(containingDeclaration, annotations, variance, name, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final int index;
|
||||||
private final Variance variance;
|
private final Variance variance;
|
||||||
private final Set<JetType> upperBounds;
|
private final Set<JetType> upperBounds;
|
||||||
private final TypeConstructor typeConstructor;
|
private final TypeConstructor typeConstructor;
|
||||||
@@ -40,8 +43,10 @@ public class TypeParameterDescriptor extends DeclarationDescriptorImpl implement
|
|||||||
@NotNull DeclarationDescriptor containingDeclaration,
|
@NotNull DeclarationDescriptor containingDeclaration,
|
||||||
@NotNull List<Annotation> annotations,
|
@NotNull List<Annotation> annotations,
|
||||||
@NotNull Variance variance,
|
@NotNull Variance variance,
|
||||||
@NotNull String name) {
|
@NotNull String name,
|
||||||
|
int index) {
|
||||||
super(containingDeclaration, annotations, name);
|
super(containingDeclaration, annotations, name);
|
||||||
|
this.index = index;
|
||||||
this.variance = variance;
|
this.variance = variance;
|
||||||
this.upperBounds = Sets.newLinkedHashSet();
|
this.upperBounds = Sets.newLinkedHashSet();
|
||||||
// TODO: Should we actually pass the annotations on to the type constructor?
|
// TODO: Should we actually pass the annotations on to the type constructor?
|
||||||
@@ -114,4 +119,8 @@ public class TypeParameterDescriptor extends DeclarationDescriptorImpl implement
|
|||||||
}
|
}
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getIndex() {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -84,16 +84,19 @@ public class ClassDescriptorResolver {
|
|||||||
|
|
||||||
// TODO : Where-clause
|
// TODO : Where-clause
|
||||||
List<TypeParameterDescriptor> typeParameters = Lists.newArrayList();
|
List<TypeParameterDescriptor> typeParameters = Lists.newArrayList();
|
||||||
|
int index = 0;
|
||||||
for (JetTypeParameter typeParameter : classElement.getTypeParameters()) {
|
for (JetTypeParameter typeParameter : classElement.getTypeParameters()) {
|
||||||
TypeParameterDescriptor typeParameterDescriptor = TypeParameterDescriptor.createForFurtherModification(
|
TypeParameterDescriptor typeParameterDescriptor = TypeParameterDescriptor.createForFurtherModification(
|
||||||
descriptor,
|
descriptor,
|
||||||
AnnotationResolver.INSTANCE.resolveAnnotations(typeParameter.getModifierList()),
|
AnnotationResolver.INSTANCE.resolveAnnotations(typeParameter.getModifierList()),
|
||||||
typeParameter.getVariance(),
|
typeParameter.getVariance(),
|
||||||
JetPsiUtil.safeName(typeParameter.getName())
|
JetPsiUtil.safeName(typeParameter.getName()),
|
||||||
|
index
|
||||||
);
|
);
|
||||||
parameterScope.addTypeParameterDescriptor(typeParameterDescriptor);
|
parameterScope.addTypeParameterDescriptor(typeParameterDescriptor);
|
||||||
trace.recordDeclarationResolution(typeParameter, typeParameterDescriptor);
|
trace.recordDeclarationResolution(typeParameter, typeParameterDescriptor);
|
||||||
typeParameters.add(typeParameterDescriptor);
|
typeParameters.add(typeParameterDescriptor);
|
||||||
|
index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean open = classElement.hasModifier(JetTokens.OPEN_KEYWORD);
|
boolean open = classElement.hasModifier(JetTokens.OPEN_KEYWORD);
|
||||||
@@ -301,13 +304,14 @@ public class ClassDescriptorResolver {
|
|||||||
public List<TypeParameterDescriptor> resolveTypeParameters(DeclarationDescriptor containingDescriptor, WritableScope extensibleScope, List<JetTypeParameter> typeParameters) {
|
public List<TypeParameterDescriptor> resolveTypeParameters(DeclarationDescriptor containingDescriptor, WritableScope extensibleScope, List<JetTypeParameter> typeParameters) {
|
||||||
// TODO : Where-clause
|
// TODO : Where-clause
|
||||||
List<TypeParameterDescriptor> result = new ArrayList<TypeParameterDescriptor>();
|
List<TypeParameterDescriptor> result = new ArrayList<TypeParameterDescriptor>();
|
||||||
for (JetTypeParameter typeParameter : typeParameters) {
|
for (int i = 0, typeParametersSize = typeParameters.size(); i < typeParametersSize; i++) {
|
||||||
result.add(resolveTypeParameter(containingDescriptor, extensibleScope, typeParameter));
|
JetTypeParameter typeParameter = typeParameters.get(i);
|
||||||
|
result.add(resolveTypeParameter(containingDescriptor, extensibleScope, typeParameter, i));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private TypeParameterDescriptor resolveTypeParameter(DeclarationDescriptor containingDescriptor, WritableScope extensibleScope, JetTypeParameter typeParameter) {
|
private TypeParameterDescriptor resolveTypeParameter(DeclarationDescriptor containingDescriptor, WritableScope extensibleScope, JetTypeParameter typeParameter, int index) {
|
||||||
// TODO: other bounds from where-clause
|
// TODO: other bounds from where-clause
|
||||||
JetTypeReference extendsBound = typeParameter.getExtendsBound();
|
JetTypeReference extendsBound = typeParameter.getExtendsBound();
|
||||||
JetType bound = extendsBound == null
|
JetType bound = extendsBound == null
|
||||||
@@ -317,7 +321,8 @@ public class ClassDescriptorResolver {
|
|||||||
containingDescriptor,
|
containingDescriptor,
|
||||||
AnnotationResolver.INSTANCE.resolveAnnotations(typeParameter.getModifierList()),
|
AnnotationResolver.INSTANCE.resolveAnnotations(typeParameter.getModifierList()),
|
||||||
typeParameter.getVariance(),
|
typeParameter.getVariance(),
|
||||||
JetPsiUtil.safeName(typeParameter.getName())
|
JetPsiUtil.safeName(typeParameter.getName()),
|
||||||
|
index
|
||||||
);
|
);
|
||||||
typeParameterDescriptor.addUpperBound(bound);
|
typeParameterDescriptor.addUpperBound(bound);
|
||||||
extensibleScope.addTypeParameterDescriptor(typeParameterDescriptor);
|
extensibleScope.addTypeParameterDescriptor(typeParameterDescriptor);
|
||||||
|
|||||||
@@ -125,7 +125,8 @@ public class JavaDescriptorResolver {
|
|||||||
owner,
|
owner,
|
||||||
Collections.<Annotation>emptyList(), // TODO
|
Collections.<Annotation>emptyList(), // TODO
|
||||||
Variance.INVARIANT,
|
Variance.INVARIANT,
|
||||||
typeParameter.getName()
|
typeParameter.getName(),
|
||||||
|
typeParameter.getIndex()
|
||||||
);
|
);
|
||||||
PsiClassType[] referencedTypes = typeParameter.getExtendsList().getReferencedTypes();
|
PsiClassType[] referencedTypes = typeParameter.getExtendsList().getReferencedTypes();
|
||||||
if (referencedTypes.length == 0){
|
if (referencedTypes.length == 0){
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ public class JetStandardClasses {
|
|||||||
parameters.add(TypeParameterDescriptor.createWithDefaultBound(
|
parameters.add(TypeParameterDescriptor.createWithDefaultBound(
|
||||||
classDescriptor,
|
classDescriptor,
|
||||||
Collections.<Annotation>emptyList(),
|
Collections.<Annotation>emptyList(),
|
||||||
Variance.OUT_VARIANCE, "T" + j));
|
Variance.OUT_VARIANCE, "T" + j, j));
|
||||||
}
|
}
|
||||||
TUPLE[i] = classDescriptor.initialize(
|
TUPLE[i] = classDescriptor.initialize(
|
||||||
true,
|
true,
|
||||||
@@ -140,7 +140,7 @@ public class JetStandardClasses {
|
|||||||
parameters.add(0, TypeParameterDescriptor.createWithDefaultBound(
|
parameters.add(0, TypeParameterDescriptor.createWithDefaultBound(
|
||||||
receiverFunction,
|
receiverFunction,
|
||||||
Collections.<Annotation>emptyList(),
|
Collections.<Annotation>emptyList(),
|
||||||
Variance.IN_VARIANCE, "T"));
|
Variance.IN_VARIANCE, "T", 0));
|
||||||
RECEIVER_FUNCTION[i] = receiverFunction.initialize(
|
RECEIVER_FUNCTION[i] = receiverFunction.initialize(
|
||||||
false,
|
false,
|
||||||
parameters,
|
parameters,
|
||||||
@@ -154,12 +154,12 @@ public class JetStandardClasses {
|
|||||||
parameters.add(TypeParameterDescriptor.createWithDefaultBound(
|
parameters.add(TypeParameterDescriptor.createWithDefaultBound(
|
||||||
function,
|
function,
|
||||||
Collections.<Annotation>emptyList(),
|
Collections.<Annotation>emptyList(),
|
||||||
Variance.IN_VARIANCE, "P" + j));
|
Variance.IN_VARIANCE, "P" + j, j + 1));
|
||||||
}
|
}
|
||||||
parameters.add(TypeParameterDescriptor.createWithDefaultBound(
|
parameters.add(TypeParameterDescriptor.createWithDefaultBound(
|
||||||
function,
|
function,
|
||||||
Collections.<Annotation>emptyList(),
|
Collections.<Annotation>emptyList(),
|
||||||
Variance.OUT_VARIANCE, "R"));
|
Variance.OUT_VARIANCE, "R", parameterCount + 1));
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user