Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Johnston2022-03-28 21:07:18 +0000
committerJeff Johnston2022-03-28 22:15:28 +0000
commitcdf5589c767aac592b3ef21dc3baebc88cccb596 (patch)
treea725cdd51a7d9dda432d977773165ba49f9f8770
parentc8ab3558cf8d482557e53d04f26e2713535580ed (diff)
downloadeclipse.jdt.ui-cdf5589c767aac592b3ef21dc3baebc88cccb596.tar.gz
eclipse.jdt.ui-cdf5589c767aac592b3ef21dc3baebc88cccb596.tar.xz
eclipse.jdt.ui-cdf5589c767aac592b3ef21dc3baebc88cccb596.zip
Bug 99622 - Rename method misses ambiguously overridden method
- restore RenameMethodUserInterfaceStarter class and use in RenameUserInterfaceManager as before - restore original method logic in RenameVirtualMethodProcessor Change-Id: Id2d60ac5badda1111e0a423173184e815115a923 Reviewed-on: https://git.eclipse.org/r/c/jdt/eclipse.jdt.ui/+/192294 Tested-by: JDT Bot <jdt-bot@eclipse.org> Tested-by: Jeff Johnston <jjohnstn@redhat.com> Reviewed-by: Jeff Johnston <jjohnstn@redhat.com>
-rw-r--r--org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/rename/RenameVirtualMethodProcessor.java22
-rw-r--r--org.eclipse.jdt.ui/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/reorg/RenameMethodUserInterfaceStarter.java71
-rw-r--r--org.eclipse.jdt.ui/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/reorg/RenameUserInterfaceManager.java4
3 files changed, 94 insertions, 3 deletions
diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/rename/RenameVirtualMethodProcessor.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/rename/RenameVirtualMethodProcessor.java
index 8c52643a94..043c360996 100644
--- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/rename/RenameVirtualMethodProcessor.java
+++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/rename/RenameVirtualMethodProcessor.java
@@ -47,6 +47,7 @@ import org.eclipse.jdt.internal.corext.util.Messages;
public class RenameVirtualMethodProcessor extends RenameMethodProcessor {
+ private IMethod fOriginalMethod;
private boolean fActivationChecked;
private ITypeHierarchy fCachedHierarchy= null;
@@ -57,6 +58,7 @@ public class RenameVirtualMethodProcessor extends RenameMethodProcessor {
*/
public RenameVirtualMethodProcessor(IMethod method) {
super(method);
+ fOriginalMethod= getMethod();
}
/**
@@ -70,6 +72,7 @@ public class RenameVirtualMethodProcessor extends RenameMethodProcessor {
this(method);
RefactoringStatus initializeStatus= initialize(arguments);
status.merge(initializeStatus);
+ fOriginalMethod= getMethod();
}
/*
@@ -82,6 +85,7 @@ public class RenameVirtualMethodProcessor extends RenameMethodProcessor {
*/
RenameVirtualMethodProcessor(IMethod topLevel, IMethod[] ripples, TextChangeManager changeManager, ITypeHierarchy hierarchy, GroupCategorySet categorySet) {
super(topLevel, changeManager, categorySet);
+ fOriginalMethod= getMethod();
fActivationChecked= true; // is top level
fCachedHierarchy= hierarchy; // may be null
setMethodsToRename(ripples);
@@ -94,6 +98,10 @@ public class RenameVirtualMethodProcessor extends RenameMethodProcessor {
return fCachedHierarchy;
}
+ public IMethod getOriginalMethod() {
+ return fOriginalMethod;
+ }
+
@Override
public boolean isApplicable() throws CoreException {
return RefactoringAvailabilityTester.isRenameVirtualMethodAvailable(getMethod());
@@ -110,7 +118,19 @@ public class RenameVirtualMethodProcessor extends RenameMethodProcessor {
monitor.beginTask("", 3); //$NON-NLS-1$
if (!fActivationChecked) {
// the following code may change the method to be changed.
- initialize(getMethod());
+ IMethod method= getMethod();
+ fOriginalMethod= method;
+
+ ITypeHierarchy hierarchy= null;
+ IType declaringType= method.getDeclaringType();
+ if (!declaringType.isInterface())
+ hierarchy= getCachedHierarchy(declaringType, new SubProgressMonitor(monitor, 1));
+
+ IMethod topmost= getMethod();
+ if (MethodChecks.isVirtual(topmost))
+ topmost= MethodChecks.getTopmostMethod(getMethod(), hierarchy, monitor);
+ if (topmost != null)
+ initialize(topmost);
fActivationChecked= true;
}
} finally{
diff --git a/org.eclipse.jdt.ui/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/reorg/RenameMethodUserInterfaceStarter.java b/org.eclipse.jdt.ui/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/reorg/RenameMethodUserInterfaceStarter.java
new file mode 100644
index 0000000000..d8a87e4028
--- /dev/null
+++ b/org.eclipse.jdt.ui/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/reorg/RenameMethodUserInterfaceStarter.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2011 IBM Corporation and others.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jdt.internal.ui.refactoring.reorg;
+
+import org.eclipse.swt.widgets.Shell;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+
+import org.eclipse.jface.dialogs.MessageDialog;
+
+import org.eclipse.ltk.core.refactoring.Refactoring;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+
+import org.eclipse.jdt.core.IMethod;
+
+import org.eclipse.jdt.internal.corext.refactoring.RefactoringCoreMessages;
+import org.eclipse.jdt.internal.corext.refactoring.rename.RenameVirtualMethodProcessor;
+import org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil;
+import org.eclipse.jdt.internal.corext.util.Messages;
+
+import org.eclipse.jdt.ui.JavaElementLabels;
+
+public class RenameMethodUserInterfaceStarter extends RenameUserInterfaceStarter {
+ @Override
+ public boolean activate(Refactoring refactoring, Shell parent, int saveMode) throws CoreException {
+ RenameVirtualMethodProcessor processor= refactoring.getAdapter(RenameVirtualMethodProcessor.class);
+ if (processor != null) {
+ RefactoringStatus status= processor.checkInitialConditions(new NullProgressMonitor());
+ if (!status.hasFatalError()) {
+ IMethod method= processor.getMethod();
+ if (!method.equals(processor.getOriginalMethod())) {
+ String message= null;
+ if (method.getDeclaringType().isInterface()) {
+ message= Messages.format(
+ RefactoringCoreMessages.MethodChecks_implements,
+ new String[]{
+ JavaElementUtil.createMethodSignature(method),
+ JavaElementLabels.getElementLabel(method.getDeclaringType(), JavaElementLabels.ALL_FULLY_QUALIFIED)});
+ } else {
+ message= Messages.format(
+ RefactoringCoreMessages.MethodChecks_overrides,
+ new String[]{
+ JavaElementUtil.createMethodSignature(method),
+ JavaElementLabels.getElementLabel(method.getDeclaringType(), JavaElementLabels.ALL_FULLY_QUALIFIED)});
+ }
+ message= Messages.format(
+ ReorgMessages.RenameMethodUserInterfaceStarter_message,
+ message);
+ if (!MessageDialog.openQuestion(parent,
+ ReorgMessages.RenameMethodUserInterfaceStarter_name,
+ message)) {
+ return false;
+ }
+ }
+ }
+ }
+ return super.activate(refactoring, parent, saveMode);
+ }
+}
diff --git a/org.eclipse.jdt.ui/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/reorg/RenameUserInterfaceManager.java b/org.eclipse.jdt.ui/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/reorg/RenameUserInterfaceManager.java
index dd59a6fa30..0ab33b7512 100644
--- a/org.eclipse.jdt.ui/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/reorg/RenameUserInterfaceManager.java
+++ b/org.eclipse.jdt.ui/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/reorg/RenameUserInterfaceManager.java
@@ -45,8 +45,8 @@ public class RenameUserInterfaceManager extends UserInterfaceManager {
put(RenameFieldProcessor.class, RenameUserInterfaceStarter.class, RenameFieldWizard.class);
put(RenameEnumConstProcessor.class, RenameUserInterfaceStarter.class, RenameEnumConstWizard.class);
put(RenameTypeParameterProcessor.class, RenameUserInterfaceStarter.class, RenameTypeParameterWizard.class);
- put(RenameNonVirtualMethodProcessor.class, RenameUserInterfaceStarter.class, RenameMethodWizard.class);
- put(RenameVirtualMethodProcessor.class, RenameUserInterfaceStarter.class, RenameMethodWizard.class);
+ put(RenameNonVirtualMethodProcessor.class, RenameMethodUserInterfaceStarter.class, RenameMethodWizard.class);
+ put(RenameVirtualMethodProcessor.class, RenameMethodUserInterfaceStarter.class, RenameMethodWizard.class);
put(RenameLocalVariableProcessor.class, RenameUserInterfaceStarter.class, RenameLocalVariableWizard.class);
put(RenameModuleProcessor.class, RenameUserInterfaceStarter.class, RenameModuleWizard.class);
}

Back to the top