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