Skip to content
This repository has been archived by the owner on Apr 21, 2023. It is now read-only.

Commit

Permalink
Avoid unnecessary usages of reflection
Browse files Browse the repository at this point in the history
eclipse/xtext-core#506

Signed-off-by: Christian Dietrich <[email protected]>
  • Loading branch information
cdietrich committed Nov 23, 2017
1 parent 8adc76c commit 901a6d9
Showing 1 changed file with 5 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 901a6d9

Please sign in to comment.