Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only allow moving an interface member to another interface #1411

Merged
merged 1 commit into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading