Skip to content

Commit

Permalink
Only allow moving an interface member to another interface (#1411)
Browse files Browse the repository at this point in the history
- fix
  ReorgPolicyFactory.MoveSubCuElementsPolicy.validateDestination() to
  restrict moving an interface member to anything other than another
  interface
- add new test to MoveMemberTests
- fixes #1299
  • Loading branch information
jjohnstn committed May 16, 2024
1 parent 582704e commit 146659c
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2075,6 +2075,8 @@ public final class RefactoringCoreMessages extends NLS {

public static String ReorgPolicyFactory_cannot_modify;

public static String ReorgPolicyFactory_cannot_move_interface_member;

public static String ReorgPolicyFactory_cannot_move_package_to_parent;

public static String ReorgPolicyFactory_cannot_move_source_to_parent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,7 @@ ReorgPolicyFactory_copy_elements_plural=Copy elements
ReorgPolicyFactory_copy_elements_header_singular=Copy element ''{0}'' to ''{1}''
ReorgPolicyFactory_copy_elements_header_plural=Copy {0} elements to ''{1}''
ReorgPolicyFactory_copy_description_singular=Copy element
ReorgPolicyFactory_cannot_move_interface_member=Interface member cannot be moved to selected destination.
ReorgPolicyFactory_cannot_move_source_to_parent=A source folder cannot be moved to its own parent.
ReorgPolicyFactory_cannot_move_package_to_parent=A package cannot be moved to its own parent.
ReorgPolicyFactory_move_description_plural=Move elements
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2023 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -2367,6 +2367,11 @@ protected RefactoringStatus verifyDestination(IJavaElement destination, int loca
}
parent= parent.getParent();
}
if (element instanceof IMember member && member.getParent() instanceof IType parentType && parentType.isInterface()) {
if (!(destination instanceof IType destType) || !destType.isInterface()) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_cannot_move_interface_member);
}
}
}

RefactoringStatus superStatus= super.verifyDestination(destination, location);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package p;
public interface A{
int m();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package p;
class B{
}
Original file line number Diff line number Diff line change
Expand Up @@ -691,9 +691,12 @@ public void testFail21() throws Exception{
RefactoringStatus.FATAL, "p.B");
}

// Issue 1299
@Test
public void testFail22() throws Exception{
//free slot
fieldMethodTypeHelper_failing(new String[0],
new String[]{"m"}, new String[][]{new String[0]}, new String[0],
RefactoringStatus.FATAL, "p.B");
}

@Test
Expand Down

0 comments on commit 146659c

Please sign in to comment.