From 8e9216b90778d6bcf0a1cf429a7b9a3a1ed0774e Mon Sep 17 00:00:00 2001 From: Tagir Valeev Date: Wed, 30 Aug 2017 16:36:42 +0700 Subject: [PATCH] Fix IDEA-178248 WrapWithAdapterMethodCallFix exception on unresolved code --- .../impl/quickfix/WrapWithAdapterMethodCallFix.java | 9 +++++++-- .../quickFix/wrapAdapterCall/beforeUnresolved.java | 6 ++++++ 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/wrapAdapterCall/beforeUnresolved.java diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/WrapWithAdapterMethodCallFix.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/WrapWithAdapterMethodCallFix.java index 1cc0f9b3ea24..d201adb66a02 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/WrapWithAdapterMethodCallFix.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/WrapWithAdapterMethodCallFix.java @@ -61,8 +61,13 @@ public class WrapWithAdapterMethodCallFix extends LocalQuickFixAndIntentionActio !myOutTypeFilter.test(outType)) { return false; } - PsiType resultType = - createReplacement(context, "((" + GenericsUtil.getVariableTypeByExpressionType(inType).getCanonicalText() + ")null)").getType(); + PsiType variableType = GenericsUtil.getVariableTypeByExpressionType(inType); + String typeText = variableType.getCanonicalText(); + if(!variableType.equalsToText(typeText)) { + // Probably some incorrect type like PsiLambdaParameterType + return false; + } + PsiType resultType = createReplacement(context, "((" + typeText + ")null)").getType(); return resultType != null && outType.isAssignableFrom(resultType); } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/wrapAdapterCall/beforeUnresolved.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/wrapAdapterCall/beforeUnresolved.java new file mode 100644 index 000000000000..29bc5f6444a7 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/wrapAdapterCall/beforeUnresolved.java @@ -0,0 +1,6 @@ +// "Wrap parameter using 'new File()'" "false" +class Foo { + private static Y[] parse(Iterable ss) { + return Y.toArray(X.from(ss).transform(s -> parse(s))); + } +} \ No newline at end of file