Skip to content

Commit 324bdfd

Browse files
authored
Fix extract method refactoring to recognize a member class collision (#1761)
- modify ExtractMethodRefactoring.checkForMethodOverride() to also check for a member class - add new test to ExtractMethodTests - fixes #1758
1 parent 26bf480 commit 324bdfd

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

org.eclipse.jdt.core.manipulation/refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ExtractMethodRefactoring.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ protected RefactoringStatus checkForMethodOverride() {
564564
if (obj instanceof IType resultType) {
565565
try {
566566
ASTNode typeDecl= null;
567-
if (resultType.isLocal() || resultType.isAnonymous()) {
567+
if (resultType.isLocal() || resultType.isAnonymous() || resultType.isMember()) {
568568
ICompilationUnit icu= resultType.getCompilationUnit();
569569
typeDecl= getTypeDeclaration(resultType, icu);
570570
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package invalidSelection;
2+
3+
public class A_testIssue1758 {
4+
public void foo() {
5+
/*]*/int i;/*[*/
6+
}
7+
}
8+
9+
class SubClass {
10+
void extracted() {
11+
}
12+
13+
class InnerClass extends A_testIssue1758 {
14+
void testMethod() {
15+
extracted();
16+
}
17+
}
18+
}

org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractMethodTests.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2735,4 +2735,9 @@ public void testIssue1357_2() throws Exception {
27352735
public void testIssue1516() throws Exception {
27362736
invalidSelectionTest();
27372737
}
2738+
2739+
@Test
2740+
public void testIssue1758() throws Exception {
2741+
invalidSelectionTest();
2742+
}
27382743
}

0 commit comments

Comments
 (0)