diff --git a/org.eclipse.jdt.core.manipulation/refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ExtractMethodRefactoring.java b/org.eclipse.jdt.core.manipulation/refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ExtractMethodRefactoring.java index 55b5de431f8..73177041b3d 100644 --- a/org.eclipse.jdt.core.manipulation/refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ExtractMethodRefactoring.java +++ b/org.eclipse.jdt.core.manipulation/refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ExtractMethodRefactoring.java @@ -564,7 +564,7 @@ protected RefactoringStatus checkForMethodOverride() { if (obj instanceof IType resultType) { try { ASTNode typeDecl= null; - if (resultType.isLocal() || resultType.isAnonymous()) { + if (resultType.isLocal() || resultType.isAnonymous() || resultType.isMember()) { ICompilationUnit icu= resultType.getCompilationUnit(); typeDecl= getTypeDeclaration(resultType, icu); } diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/invalidSelection/A_testIssue1758.java b/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/invalidSelection/A_testIssue1758.java new file mode 100644 index 00000000000..be5eebdcf2d --- /dev/null +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/invalidSelection/A_testIssue1758.java @@ -0,0 +1,18 @@ +package invalidSelection; + +public class A_testIssue1758 { + public void foo() { + /*]*/int i;/*[*/ + } +} + +class SubClass { + void extracted() { + } + + class InnerClass extends A_testIssue1758 { + void testMethod() { + extracted(); + } + } +} diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractMethodTests.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractMethodTests.java index 2b08ef27c6f..b070dd7b6d3 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractMethodTests.java +++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractMethodTests.java @@ -2735,4 +2735,9 @@ public void testIssue1357_2() throws Exception { public void testIssue1516() throws Exception { invalidSelectionTest(); } + + @Test + public void testIssue1758() throws Exception { + invalidSelectionTest(); + } }