Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace obsolete reflection usage with original method calls #3205

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
cdietrich marked this conversation as resolved.
Show resolved Hide resolved
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
Loading