diff --git a/java/java-impl/src/com/intellij/codeInspection/ReplaceWithTernaryOperatorFix.java b/java/java-impl/src/com/intellij/codeInspection/ReplaceWithTernaryOperatorFix.java index 5c93f3cddcf6..115533f1f047 100644 --- a/java/java-impl/src/com/intellij/codeInspection/ReplaceWithTernaryOperatorFix.java +++ b/java/java-impl/src/com/intellij/codeInspection/ReplaceWithTernaryOperatorFix.java @@ -55,7 +55,7 @@ public class ReplaceWithTernaryOperatorFix implements LocalQuickFix { PsiElement element = descriptor.getPsiElement(); while (true) { PsiElement parent = element.getParent(); - if (parent instanceof PsiReferenceExpression || parent instanceof PsiMethodCallExpression) { + if (parent instanceof PsiReferenceExpression || parent instanceof PsiCallExpression || parent instanceof PsiJavaCodeReferenceElement) { element = parent; } else { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/replaceWithTernaryOperator/afterInnerClass.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/replaceWithTernaryOperator/afterInnerClass.java new file mode 100644 index 000000000000..19598891ea5c --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/replaceWithTernaryOperator/afterInnerClass.java @@ -0,0 +1,9 @@ +// "Replace with 'njc != null ?:'" "true" +public class JC { + class Inner {} + + public static void main(String[] args) { + JC njc = Math.random() > 0.5 ? new JC() : null; + System.out.println(njc != null ? njc.new Inner() : null); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/replaceWithTernaryOperator/beforeInnerClass.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/replaceWithTernaryOperator/beforeInnerClass.java new file mode 100644 index 000000000000..97b54b51fc91 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/replaceWithTernaryOperator/beforeInnerClass.java @@ -0,0 +1,9 @@ +// "Replace with 'njc != null ?:'" "true" +public class JC { + class Inner {} + + public static void main(String[] args) { + JC njc = Math.random() > 0.5 ? new JC() : null; + System.out.println(njc.new Inner()); + } +} \ No newline at end of file