Skip to content

Commit

Permalink
Merge pull request #3205 from mehmet-karaman/replace_reflection_by_or…
Browse files Browse the repository at this point in the history
…iginal_method_calls

replace obsolete reflection usage with original method calls
  • Loading branch information
cdietrich authored Sep 27, 2024
2 parents 531d040 + 70baf17 commit a41f7bb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 43 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;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ public static <T> T throwUncheckedException(Throwable e) {
* It is not available on JRE &lt; 1.7
*
* @since 2.8
* @deprecated addSuppressed method is exposed in JRE 1.8 and above.
*/
@Deprecated(forRemoval = true)
public static void addSuppressed(Throwable owner, Throwable add) {
try {
Method method = owner.getClass().getMethod("addSuppressed", Throwable.class);
Expand Down
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 a41f7bb

Please sign in to comment.