diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateClassFromUsageBaseFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateClassFromUsageBaseFix.java index 4042295af3ce..8973c26423ad 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateClassFromUsageBaseFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateClassFromUsageBaseFix.java @@ -65,10 +65,11 @@ public abstract class CreateClassFromUsageBaseFix extends BaseIntentionAction { parent.getParent() instanceof PsiVariable || parent.getParent() instanceof PsiMethod || parent.getParent() instanceof PsiClassObjectAccessExpression || - parent.getParent() instanceof PsiTypeCastExpression || - (parent.getParent() instanceof PsiInstanceOfExpression && ((PsiInstanceOfExpression)parent.getParent()).getCheckType() == parent)) { + parent.getParent() instanceof PsiTypeCastExpression) { return true; } + PsiInstanceOfExpression instanceOfExpression = PsiTreeUtil.getParentOfType(parent, PsiInstanceOfExpression.class); + if (instanceOfExpression != null && instanceOfExpression.getCheckType() == parent) return true; } else if (parent instanceof PsiReferenceList) { if (myKind == CreateClassKind.ENUM || myKind == CreateClassKind.RECORD) return false; diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createInnerClassFromUsage/afterInstanceof.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createInnerClassFromUsage/afterInstanceof.java new file mode 100644 index 000000000000..f557d06adfd6 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createInnerClassFromUsage/afterInstanceof.java @@ -0,0 +1,9 @@ +// "Create inner class 'Foo'" "true" +public class Test { + boolean foo(Object o) { + return o instanceof Foo; + } + + private class Foo { + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createInnerClassFromUsage/beforeInstanceof.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createInnerClassFromUsage/beforeInstanceof.java new file mode 100644 index 000000000000..5031200d60c8 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createInnerClassFromUsage/beforeInstanceof.java @@ -0,0 +1,6 @@ +// "Create inner class 'Foo'" "true" +public class Test { + boolean foo(Object o) { + return o instanceof Foo; + } +} \ No newline at end of file