Skip to content

Commit

Permalink
replace obsolete reflection usage with original method calls
Browse files Browse the repository at this point in the history
  • Loading branch information
mehmet-karaman committed Sep 25, 2024
1 parent 36ee8d1 commit ef1576c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,27 +96,11 @@ public FormatterModifyDialog(Shell parentShell, Profile profile, ProfileManager
// @Override intentionally removed to ensure backward compatibility
@SuppressWarnings({ "rawtypes", "unchecked" })
protected void addPages(final Map values) {
if (isOldAPIVersion()) {
try {
// use reflection to not break API
Method addTabPage = ModifyDialog.class.getDeclaredMethod("addTabPage", String.class, IModifyDialogTabPage.class);
// addTabPage("Indentation", tabFactory.createIndentationTab(this, values));
addTabPage.invoke(this, "Braces", tabFactory.createBracesTab(this, values));
addTabPage.invoke(this, "White Space", tabFactory.createWhiteSpaceTab(this, values));
addTabPage.invoke(this, "Blank Lines", tabFactory.createBlankLinesTab(this, values));
addTabPage.invoke(this, "New Lines", tabFactory.createNewLineTab(this, values));
addTabPage.invoke(this, "Line Wrapping", tabFactory.createLineWrapTab(this, values));
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
| InvocationTargetException e) {
XtendActivator.getInstance().getLog().log(new Status(IStatus.ERROR, XtendActivator.PLUGIN_ID, e.getMessage(), e));
}
} else {
addTabPageNewAPI("Braces", tabFactory.createBracesTab(this, values));
addTabPageNewAPI("White Space", tabFactory.createWhiteSpaceTab(this, values));
addTabPageNewAPI("Blank Lines", tabFactory.createBlankLinesTab(this, values));
addTabPageNewAPI("New Lines", tabFactory.createNewLineTab(this, values));
addTabPageNewAPI("Line Wrapping", tabFactory.createLineWrapTab(this, values));
}
addTabPageNewAPI("Braces", tabFactory.createBracesTab(this, values));
addTabPageNewAPI("White Space", tabFactory.createWhiteSpaceTab(this, values));
addTabPageNewAPI("Blank Lines", tabFactory.createBlankLinesTab(this, values));
addTabPageNewAPI("New Lines", tabFactory.createNewLineTab(this, values));
addTabPageNewAPI("Line Wrapping", tabFactory.createLineWrapTab(this, values));
}

// copied from Eclipse Oxygen to support old dialog in Eclipse Photon
Expand All @@ -131,10 +115,6 @@ private final void addTabPageNewAPI(String title, IModifyDialogTabPage tabPage)

@Override
public void create() {
if (isOldAPIVersion()) {
super.create();
return;
}
// copied from Eclipse Oxygen to support old dialog in Eclipse Photon
super.create();
int lastFocusNr = 0;
Expand Down Expand Up @@ -164,9 +144,6 @@ public void create() {
@Override
@SuppressWarnings("rawtypes")
protected Control createDialogArea(Composite parent) {
if (isOldAPIVersion()) {
return super.createDialogArea(parent);
}
try {
// copied from Eclipse Oxygen to support old dialog in Eclipse Photon
final Composite composite = new Composite(parent, SWT.NONE);
Expand Down Expand Up @@ -257,18 +234,4 @@ protected String getHelpContextId() {
return null;
}

/**
* Check if the old (<= Eclipse Oxygen) API is used or not.
*
* @return true if the Eclipse API is Eclipse Oxygen or older, true for Eclipse Photon or newer.
*/
private boolean isOldAPIVersion() {
try {
ModifyDialog.class.getDeclaredMethod("addPages", Map.class);
return true;
} catch (NoSuchMethodException | SecurityException e) {
return false;
}
}

}
27 changes: 0 additions & 27 deletions org.eclipse.xtext.util/src/org/eclipse/xtext/util/Exceptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
*******************************************************************************/
package org.eclipse.xtext.util;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import org.eclipse.emf.common.util.WrappedException;

/**
Expand All @@ -28,28 +25,4 @@ public static <T> T throwUncheckedException(Throwable e) {
throw new RuntimeException(e);
}

/**
* Invoke {@code Throwable#addSuppressed(Throwable)} reflectively if it is available.
*
* It is not available on JRE &lt; 1.7
*
* @since 2.8
*/
public static void addSuppressed(Throwable owner, Throwable add) {
try {
Method method = owner.getClass().getMethod("addSuppressed", Throwable.class);
method.invoke(owner, add);
} catch (NoSuchMethodException e) {
// ignore, will happen for JRE < 1.7
} catch (SecurityException e) {
throwUncheckedException(e);
} catch (IllegalAccessException e) {
throwUncheckedException(e);
} catch (IllegalArgumentException e) {
throwUncheckedException(e);
} catch (InvocationTargetException e) {
throwUncheckedException(e);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public ConflictingRegionsException(String message, Throwable cause, Collection<R
super(message, cause);
this.traces = traces;
for (RegionTrace trace : traces)
Exceptions.addSuppressed(this, trace);
addSuppressed(trace);
}

@Override
Expand Down

0 comments on commit ef1576c

Please sign in to comment.