Skip to content

Commit

Permalink
Fix push down to allow moving fields/methods to inner/local classes (#…
Browse files Browse the repository at this point in the history
…1693)

- add logic to
  PushDownRefactoringProcessor.checkReferencesToPushedDownMembers()
  to ignore members in the declaring CU that will end up being
  targets of the move (i.e. they extend the declaring class)
- add new test to PushDownTests
- fixes #1691
  • Loading branch information
jjohnstn authored Oct 3, 2024
1 parent 829094c commit 5aad011
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,19 @@ private RefactoringStatus checkReferencesToPushedDownMembers(IProgressMonitor mo
continue;
if (!(element instanceof IMember))
continue;
IType[] destinationTypes= getAbstractDestinations(new NullProgressMonitor());
IMember elementMember= (IMember)element;
IType elementMemberType= elementMember.getDeclaringType();
boolean isMoveDestination= false;
for (IType destinationType : destinationTypes) {
if (destinationType.getFullyQualifiedName().equals(elementMemberType.getFullyQualifiedName())) {
isMoveDestination= true;
break;
}
}
if (isMoveDestination) {
continue;
}
IMember referencingMember= (IMember) element;
Object[] keys= { label, createLabel(referencingMember) };
String msg= Messages.format(RefactoringCoreMessages.PushDownRefactoring_referenced, keys);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package p;

class A {
int f;

void mA() {
class B extends A {
public void mB() {
f = 0;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package p;

class A {
void mA() {
class B extends A {
int f;

public void mB() {
f = 0;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,24 @@ public void test39() throws Exception { //https://github.com/eclipse-jdt/eclipse
namesOfMethodsToDeclareAbstract, signaturesOfMethodsToDeclareAbstract, null, null);
}

@Test
public void test40() throws Exception { //https://github.com/eclipse-jdt/eclipse.jdt.ui/issues/1679
String[] selectedMethodNames= { };
String[][] selectedMethodSignatures= { new String[0] };
String[] selectedFieldNames= { "f" };
String[] namesOfMethodsToPushDown= selectedMethodNames;
String[][] signaturesOfMethodsToPushDown= selectedMethodSignatures;
String[] namesOfFieldsToPushDown= {};
String[] namesOfMethodsToDeclareAbstract= {};
String[][] signaturesOfMethodsToDeclareAbstract= {};

helper(selectedMethodNames, selectedMethodSignatures,
selectedFieldNames,
namesOfMethodsToPushDown, signaturesOfMethodsToPushDown,
namesOfFieldsToPushDown,
namesOfMethodsToDeclareAbstract, signaturesOfMethodsToDeclareAbstract, null, null);
}

@Test
public void testFail0() throws Exception {
String[] selectedMethodNames= {"f"};
Expand Down

0 comments on commit 5aad011

Please sign in to comment.