Using references to new type parameter descriptors in types when replacing signatures using alternative annotations.
This commit is contained in:
+23
-8
@@ -36,7 +36,9 @@ import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
|||||||
import org.jetbrains.jet.resolve.DescriptorRenderer;
|
import org.jetbrains.jet.resolve.DescriptorRenderer;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Evgeny Gerashchenko
|
* @author Evgeny Gerashchenko
|
||||||
@@ -53,6 +55,9 @@ class AlternativeSignatureData {
|
|||||||
private JetType altReturnType;
|
private JetType altReturnType;
|
||||||
private List<TypeParameterDescriptor> altTypeParameters;
|
private List<TypeParameterDescriptor> altTypeParameters;
|
||||||
|
|
||||||
|
private Map<TypeParameterDescriptor, TypeParameterDescriptorImpl> originalToAltTypeParameters =
|
||||||
|
new HashMap<TypeParameterDescriptor, TypeParameterDescriptorImpl>();
|
||||||
|
|
||||||
AlternativeSignatureData(
|
AlternativeSignatureData(
|
||||||
@NotNull PsiMethodWrapper method,
|
@NotNull PsiMethodWrapper method,
|
||||||
@NotNull JavaDescriptorResolver.ValueParameterDescriptors valueParameterDescriptors,
|
@NotNull JavaDescriptorResolver.ValueParameterDescriptors valueParameterDescriptors,
|
||||||
@@ -68,12 +73,18 @@ class AlternativeSignatureData {
|
|||||||
Project project = method.getPsiMethod().getProject();
|
Project project = method.getPsiMethod().getProject();
|
||||||
altFunDeclaration = JetPsiFactory.createFunction(project, signature);
|
altFunDeclaration = JetPsiFactory.createFunction(project, signature);
|
||||||
|
|
||||||
|
for (TypeParameterDescriptor tp : methodTypeParameters) {
|
||||||
|
originalToAltTypeParameters.put(tp, TypeParameterDescriptorImpl
|
||||||
|
.createForFurtherModification(tp.getContainingDeclaration(), tp.getAnnotations(),
|
||||||
|
tp.isReified(), tp.getVariance(), tp.getName(), tp.getIndex()));
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
checkForSyntaxErrors();
|
checkForSyntaxErrors();
|
||||||
|
|
||||||
|
computeTypeParameters(methodTypeParameters);
|
||||||
computeValueParameters(valueParameterDescriptors);
|
computeValueParameters(valueParameterDescriptors);
|
||||||
computeReturnType(returnType);
|
computeReturnType(returnType);
|
||||||
computeTypeParameters(methodTypeParameters);
|
|
||||||
}
|
}
|
||||||
catch (AlternativeSignatureMismatchException e) {
|
catch (AlternativeSignatureMismatchException e) {
|
||||||
error = e.getMessage();
|
error = e.getMessage();
|
||||||
@@ -113,7 +124,7 @@ class AlternativeSignatureData {
|
|||||||
return altTypeParameters;
|
return altTypeParameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
static JetType computeType(JetTypeElement alternativeTypeElement, final JetType autoType) {
|
JetType computeType(JetTypeElement alternativeTypeElement, final JetType autoType) {
|
||||||
//noinspection NullableProblems
|
//noinspection NullableProblems
|
||||||
return alternativeTypeElement.accept(new JetVisitor<JetType, Void>() {
|
return alternativeTypeElement.accept(new JetVisitor<JetType, Void>() {
|
||||||
@Override
|
@Override
|
||||||
@@ -154,7 +165,8 @@ class AlternativeSignatureData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private JetType visitCommonType(@NotNull String expectedFqNamePostfix, @NotNull JetTypeElement type) {
|
private JetType visitCommonType(@NotNull String expectedFqNamePostfix, @NotNull JetTypeElement type) {
|
||||||
ClassifierDescriptor declarationDescriptor = autoType.getConstructor().getDeclarationDescriptor();
|
TypeConstructor originalTypeConstructor = autoType.getConstructor();
|
||||||
|
ClassifierDescriptor declarationDescriptor = originalTypeConstructor.getDeclarationDescriptor();
|
||||||
assert declarationDescriptor != null;
|
assert declarationDescriptor != null;
|
||||||
String fqName = DescriptorUtils.getFQName(declarationDescriptor).toSafe().getFqName();
|
String fqName = DescriptorUtils.getFQName(declarationDescriptor).toSafe().getFqName();
|
||||||
if (!fqName.endsWith(expectedFqNamePostfix)) {
|
if (!fqName.endsWith(expectedFqNamePostfix)) {
|
||||||
@@ -196,7 +208,13 @@ class AlternativeSignatureData {
|
|||||||
}
|
}
|
||||||
altArguments.add(new TypeProjection(variance, alternativeType));
|
altArguments.add(new TypeProjection(variance, alternativeType));
|
||||||
}
|
}
|
||||||
return new JetTypeImpl(autoType.getAnnotations(), autoType.getConstructor(), false,
|
|
||||||
|
TypeConstructor typeConstructor = originalTypeConstructor;
|
||||||
|
if (typeConstructor.getDeclarationDescriptor() instanceof TypeParameterDescriptor
|
||||||
|
&& originalToAltTypeParameters.containsKey(typeConstructor.getDeclarationDescriptor())) {
|
||||||
|
typeConstructor = originalToAltTypeParameters.get(typeConstructor.getDeclarationDescriptor()).getTypeConstructor();
|
||||||
|
}
|
||||||
|
return new JetTypeImpl(autoType.getAnnotations(), typeConstructor, false,
|
||||||
altArguments, autoType.getMemberScope());
|
altArguments, autoType.getMemberScope());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -274,10 +292,7 @@ class AlternativeSignatureData {
|
|||||||
altTypeParameters = new ArrayList<TypeParameterDescriptor>();
|
altTypeParameters = new ArrayList<TypeParameterDescriptor>();
|
||||||
for (int i = 0, size = typeParameters.size(); i < size; i++) {
|
for (int i = 0, size = typeParameters.size(); i < size; i++) {
|
||||||
TypeParameterDescriptor pd = typeParameters.get(i);
|
TypeParameterDescriptor pd = typeParameters.get(i);
|
||||||
DeclarationDescriptor containingDeclaration = pd.getContainingDeclaration();
|
TypeParameterDescriptorImpl altParamDescriptor = originalToAltTypeParameters.get(pd);
|
||||||
TypeParameterDescriptorImpl altParamDescriptor = TypeParameterDescriptorImpl
|
|
||||||
.createForFurtherModification(containingDeclaration, pd.getAnnotations(),
|
|
||||||
pd.isReified(), pd.getVariance(), pd.getName(), pd.getIndex());
|
|
||||||
int upperBoundIndex = 0;
|
int upperBoundIndex = 0;
|
||||||
for (JetType upperBound : pd.getUpperBounds()) {
|
for (JetType upperBound : pd.getUpperBounds()) {
|
||||||
JetTypeElement altTypeElement;
|
JetTypeElement altTypeElement;
|
||||||
|
|||||||
Reference in New Issue
Block a user