Supported type parameters in alternative method signatures.
This commit is contained in:
+58
-2
@@ -16,9 +16,11 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.lang.resolve.java;
|
package org.jetbrains.jet.lang.resolve.java;
|
||||||
|
|
||||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptorImpl;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
import org.jetbrains.jet.lang.types.JetTypeImpl;
|
import org.jetbrains.jet.lang.types.JetTypeImpl;
|
||||||
import org.jetbrains.jet.lang.types.TypeProjection;
|
import org.jetbrains.jet.lang.types.TypeProjection;
|
||||||
@@ -89,4 +91,58 @@ class AlternativeSignatureParsing {
|
|||||||
}
|
}
|
||||||
return new JavaDescriptorResolver.ValueParameterDescriptors(altReceiverType, altParamDescriptors);
|
return new JavaDescriptorResolver.ValueParameterDescriptors(altReceiverType, altParamDescriptors);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static List<TypeParameterDescriptor> computeAlternativeTypeParameters(List<TypeParameterDescriptor> typeParameterDescriptors,
|
||||||
|
JetNamedFunction altFunDeclaration) {
|
||||||
|
List<TypeParameterDescriptor> altParamDescriptors = new ArrayList<TypeParameterDescriptor>();
|
||||||
|
for (int i = 0, size = typeParameterDescriptors.size(); i < size; i++) {
|
||||||
|
TypeParameterDescriptor pd = typeParameterDescriptors.get(i);
|
||||||
|
DeclarationDescriptor containingDeclaration = pd.getContainingDeclaration();
|
||||||
|
assert containingDeclaration != null;
|
||||||
|
TypeParameterDescriptorImpl altParamDescriptor = TypeParameterDescriptorImpl
|
||||||
|
.createForFurtherModification(containingDeclaration, pd.getAnnotations(),
|
||||||
|
pd.isReified(), pd.getVariance(), pd.getName(), pd.getIndex());
|
||||||
|
int upperBoundIndex = 0;
|
||||||
|
for (JetType upperBound : pd.getUpperBounds()) {
|
||||||
|
JetTypeElement altTypeElement;
|
||||||
|
JetTypeParameter parameter = altFunDeclaration.getTypeParameters().get(i);
|
||||||
|
if (upperBoundIndex == 0) {
|
||||||
|
JetTypeReference extendsBound = parameter.getExtendsBound();
|
||||||
|
if (extendsBound == null) { // default upper bound
|
||||||
|
assert pd.getUpperBounds().size() == 1;
|
||||||
|
altParamDescriptor.addDefaultUpperBound();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
altTypeElement = extendsBound.getTypeElement();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
altTypeElement = findTypeParameterConstraint(altFunDeclaration, parameter.getNameAsName(), upperBoundIndex).getBoundTypeReference().getTypeElement();
|
||||||
|
}
|
||||||
|
altParamDescriptor.addUpperBound(computeAlternativeTypeFromAnnotation(altTypeElement, upperBound));
|
||||||
|
upperBoundIndex++;
|
||||||
|
}
|
||||||
|
|
||||||
|
altParamDescriptor.setInitialized();
|
||||||
|
altParamDescriptors.add(altParamDescriptor);
|
||||||
|
}
|
||||||
|
return altParamDescriptors;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private static JetTypeConstraint findTypeParameterConstraint(@NotNull JetFunction function, @NotNull Name typeParameterName, int index) {
|
||||||
|
if (index != 0) {
|
||||||
|
int currentIndex = 0;
|
||||||
|
for (JetTypeConstraint constraint : function.getTypeConstaints()) {
|
||||||
|
if (typeParameterName.equals(constraint.getSubjectTypeParameterName().getReferencedNameAsName())) {
|
||||||
|
currentIndex++;
|
||||||
|
}
|
||||||
|
if (currentIndex == index) {
|
||||||
|
return constraint;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-2
@@ -27,7 +27,10 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetTypeReference;
|
||||||
import org.jetbrains.jet.lang.resolve.*;
|
import org.jetbrains.jet.lang.resolve.*;
|
||||||
import org.jetbrains.jet.lang.resolve.constants.*;
|
import org.jetbrains.jet.lang.resolve.constants.*;
|
||||||
import org.jetbrains.jet.lang.resolve.constants.StringValue;
|
import org.jetbrains.jet.lang.resolve.constants.StringValue;
|
||||||
@@ -1604,7 +1607,7 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes
|
|||||||
|
|
||||||
String context = "method " + method.getName() + " in class " + psiClass.getQualifiedName();
|
String context = "method " + method.getName() + " in class " + psiClass.getQualifiedName();
|
||||||
|
|
||||||
final List<TypeParameterDescriptor> methodTypeParameters = resolveMethodTypeParameters(method, functionDescriptorImpl);
|
List<TypeParameterDescriptor> methodTypeParameters = resolveMethodTypeParameters(method, functionDescriptorImpl);
|
||||||
|
|
||||||
TypeVariableResolver methodTypeVariableResolver = TypeVariableResolvers.typeVariableResolverFromTypeParameters(methodTypeParameters, functionDescriptorImpl, context);
|
TypeVariableResolver methodTypeVariableResolver = TypeVariableResolvers.typeVariableResolverFromTypeParameters(methodTypeParameters, functionDescriptorImpl, context);
|
||||||
|
|
||||||
@@ -1622,6 +1625,7 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes
|
|||||||
if (returnTypeRef != null) {
|
if (returnTypeRef != null) {
|
||||||
returnType = AlternativeSignatureParsing.computeAlternativeTypeFromAnnotation(returnTypeRef.getTypeElement(), returnType);
|
returnType = AlternativeSignatureParsing.computeAlternativeTypeFromAnnotation(returnTypeRef.getTypeElement(), returnType);
|
||||||
}
|
}
|
||||||
|
methodTypeParameters = AlternativeSignatureParsing.computeAlternativeTypeParameters(methodTypeParameters, altFunDeclaration);
|
||||||
}
|
}
|
||||||
|
|
||||||
functionDescriptorImpl.initialize(
|
functionDescriptorImpl.initialize(
|
||||||
|
|||||||
Reference in New Issue
Block a user