Fix invalid usage of descriptorToDeclaration in QuickFixUtil
This commit is contained in:
@@ -26,7 +26,6 @@ import org.jetbrains.jet.lang.diagnostics.DiagnosticWithParameters2;
|
|||||||
import org.jetbrains.jet.lang.diagnostics.Errors;
|
import org.jetbrains.jet.lang.diagnostics.Errors;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
|
||||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage;
|
import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage;
|
||||||
@@ -34,6 +33,7 @@ import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage;
|
|||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
//TODO: should use change signature to deal with cases of multiple overridden descriptors
|
||||||
public class QuickFixFactoryForTypeMismatchError implements JetIntentionActionsFactory {
|
public class QuickFixFactoryForTypeMismatchError implements JetIntentionActionsFactory {
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
@@ -132,14 +132,9 @@ public class QuickFixFactoryForTypeMismatchError implements JetIntentionActionsF
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private static JetFunction getFunctionDeclaration(@NotNull BindingContext context, @NotNull ResolvedCall<?> resolvedCall) {
|
private static JetFunction getFunctionDeclaration(@NotNull BindingContext context, @NotNull ResolvedCall<?> resolvedCall) {
|
||||||
List<PsiElement> declarations = BindingContextUtils.descriptorToDeclarations(context, resolvedCall.getResultingDescriptor());
|
PsiElement result = QuickFixUtil.safeGetDeclaration(context, resolvedCall);
|
||||||
//do not create fix if descriptor has more than one overridden declarations
|
if (result instanceof JetFunction) {
|
||||||
//TODO: use change signature to deal with this case correctly
|
return (JetFunction) result;
|
||||||
if (declarations.size() == 1) {
|
|
||||||
PsiElement result = declarations.iterator().next();
|
|
||||||
if (result instanceof JetFunction) {
|
|
||||||
return (JetFunction) result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ public class QuickFixUtil {
|
|||||||
BindingContext context = ResolvePackage.getBindingContext(callExpression.getContainingJetFile());
|
BindingContext context = ResolvePackage.getBindingContext(callExpression.getContainingJetFile());
|
||||||
ResolvedCall<?> resolvedCall = context.get(BindingContext.RESOLVED_CALL, callExpression.getCalleeExpression());
|
ResolvedCall<?> resolvedCall = context.get(BindingContext.RESOLVED_CALL, callExpression.getCalleeExpression());
|
||||||
if (resolvedCall == null) return null;
|
if (resolvedCall == null) return null;
|
||||||
PsiElement declaration = BindingContextUtils.descriptorToDeclaration(context, resolvedCall.getCandidateDescriptor());
|
PsiElement declaration = safeGetDeclaration(context, resolvedCall);
|
||||||
if (declaration instanceof JetFunction) {
|
if (declaration instanceof JetFunction) {
|
||||||
return ((JetFunction) declaration).getValueParameterList();
|
return ((JetFunction) declaration).getValueParameterList();
|
||||||
}
|
}
|
||||||
@@ -119,6 +119,16 @@ public class QuickFixUtil {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public static PsiElement safeGetDeclaration(@NotNull BindingContext context, @NotNull ResolvedCall<?> resolvedCall) {
|
||||||
|
List<PsiElement> declarations = BindingContextUtils.descriptorToDeclarations(context, resolvedCall.getResultingDescriptor());
|
||||||
|
//do not create fix if descriptor has more than one overridden declaration
|
||||||
|
if (declarations.size() == 1) {
|
||||||
|
return declarations.iterator().next();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static JetParameter getParameterCorrespondingToFunctionLiteralPassedOutsideArgumentList(@NotNull JetFunctionLiteralExpression functionLiteralExpression) {
|
public static JetParameter getParameterCorrespondingToFunctionLiteralPassedOutsideArgumentList(@NotNull JetFunctionLiteralExpression functionLiteralExpression) {
|
||||||
if (!(functionLiteralExpression.getParent() instanceof JetCallExpression)) {
|
if (!(functionLiteralExpression.getParent() instanceof JetCallExpression)) {
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
// "class org.jetbrains.jet.plugin.quickfix.ChangeParameterTypeFix" "false"
|
||||||
|
// ERROR: <html>Type mismatch.<table><tr><td>Required:</td><td>kotlin.Int</td></tr><tr><td>Found:</td><td>kotlin.String</td></tr></table></html>
|
||||||
|
trait A {
|
||||||
|
fun f(i: Int): Boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
open class AA {
|
||||||
|
fun f(i: Int) = true
|
||||||
|
}
|
||||||
|
|
||||||
|
class AAA: AA(), A
|
||||||
|
|
||||||
|
val c = AAA().f("<caret>")
|
||||||
@@ -2263,6 +2263,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
|||||||
doTest("idea/testData/quickfix/typeMismatch/parameterTypeMismatch/beforeChangePrimaryConstructorParameterType.kt");
|
doTest("idea/testData/quickfix/typeMismatch/parameterTypeMismatch/beforeChangePrimaryConstructorParameterType.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("beforeMultiFakeOverride.kt")
|
||||||
|
public void testMultiFakeOverride() throws Exception {
|
||||||
|
doTest("idea/testData/quickfix/typeMismatch/parameterTypeMismatch/beforeMultiFakeOverride.kt");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression")
|
@TestMetadata("idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression")
|
||||||
|
|||||||
Reference in New Issue
Block a user