From 901a6d9afd9d9b1d8de074c55f7c9977d4d9b0b5 Mon Sep 17 00:00:00 2001 From: Christian Dietrich Date: Thu, 23 Nov 2017 08:59:06 +0100 Subject: [PATCH] Avoid unnecessary usages of reflection https://github.com/eclipse/xtext-core/issues/506 Signed-off-by: Christian Dietrich --- ...ctoringWizardOpenOperation_NonForking.java | 46 ++----------------- 1 file changed, 5 insertions(+), 41 deletions(-) diff --git a/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/refactoring/ui/RefactoringWizardOpenOperation_NonForking.java b/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/refactoring/ui/RefactoringWizardOpenOperation_NonForking.java index 068cc92f08..6387a3a7d4 100644 --- a/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/refactoring/ui/RefactoringWizardOpenOperation_NonForking.java +++ b/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/refactoring/ui/RefactoringWizardOpenOperation_NonForking.java @@ -2,7 +2,6 @@ import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.Assert; @@ -17,6 +16,7 @@ import org.eclipse.jface.wizard.IWizardContainer; import org.eclipse.ltk.core.refactoring.CheckConditionsOperation; import org.eclipse.ltk.core.refactoring.Refactoring; +import org.eclipse.ltk.core.refactoring.RefactoringContext; import org.eclipse.ltk.core.refactoring.RefactoringStatus; import org.eclipse.ltk.internal.ui.refactoring.ExceptionHandler; import org.eclipse.ltk.internal.ui.refactoring.RefactoringUIMessages; @@ -129,29 +129,10 @@ public void run() { return result[0]; } - /** - * Only applicable for Eclipse >= 3.7, therefore reflective - */ private void disposeRefactoringContext(RefactoringWizard wizard) { - try { - Field refactoringContextField = getPrivateField(wizard.getClass(), "fRefactoringContext"); - if (refactoringContextField == null) { - return; - } - refactoringContextField.setAccessible(true); - Object refactoringContext = refactoringContextField.get(wizard); - if(refactoringContext != null) { - Method disposeMethod = refactoringContext.getClass().getMethod("dispose"); - disposeMethod.invoke(refactoringContext); - } - } catch (NoSuchFieldException e) { - // ignore - } catch (IllegalAccessException e) { - // ignore - } catch (NoSuchMethodException e) { - // ignore - } catch (InvocationTargetException e) { - // ignore + RefactoringContext refactoringContext = wizard.getRefactoringContext(); + if(refactoringContext != null) { + refactoringContext.dispose(); } } @@ -194,25 +175,8 @@ protected Dialog createRefactoringWizardDialog(RefactoringWizard wizard, Shell p return result; } - /** - * Copied from {@link RefactoringWizard} as the original is package private. - * Once again reflection is used because of getWizardFlags() did not exist back in Galileo. - */ protected boolean needsWizardBasedUserInterface(RefactoringWizard wizard) { - try { - Field flagsField = getPrivateField(wizard.getClass(), "fFlags"); - flagsField.setAccessible(true); - return ((Integer) flagsField.get(wizard) & RefactoringWizard.WIZARD_BASED_USER_INTERFACE) != 0; - } catch (NoSuchFieldException e) { - // ignore - } catch (SecurityException e) { - // ignore - } catch (IllegalArgumentException e) { - // ignore - } catch (IllegalAccessException e) { - // ignore - } - return true; + return (wizard.getWizardFlags() & RefactoringWizard.WIZARD_BASED_USER_INTERFACE) != 0; } protected Field getPrivateField(Class clazz, String name) throws NoSuchFieldException, SecurityException {