From ef1576c73d72726f680120b7e1e51b1af46ddb8f Mon Sep 17 00:00:00 2001 From: Mehmet Emin Karaman Date: Wed, 25 Sep 2024 14:04:09 +0200 Subject: [PATCH] replace obsolete reflection usage with original method calls --- .../preferences/FormatterModifyDialog.java | 47 ++----------------- .../org/eclipse/xtext/util/Exceptions.java | 27 ----------- .../internal/ConflictingRegionsException.java | 2 +- 3 files changed, 6 insertions(+), 70 deletions(-) diff --git a/org.eclipse.xtend.ide/src/org/eclipse/xtend/ide/formatting/preferences/FormatterModifyDialog.java b/org.eclipse.xtend.ide/src/org/eclipse/xtend/ide/formatting/preferences/FormatterModifyDialog.java index f65f12c2888..549532d577e 100644 --- a/org.eclipse.xtend.ide/src/org/eclipse/xtend/ide/formatting/preferences/FormatterModifyDialog.java +++ b/org.eclipse.xtend.ide/src/org/eclipse/xtend/ide/formatting/preferences/FormatterModifyDialog.java @@ -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 @@ -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; @@ -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); @@ -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; - } - } - } diff --git a/org.eclipse.xtext.util/src/org/eclipse/xtext/util/Exceptions.java b/org.eclipse.xtext.util/src/org/eclipse/xtext/util/Exceptions.java index 8f91da81a5e..289765efbfe 100644 --- a/org.eclipse.xtext.util/src/org/eclipse/xtext/util/Exceptions.java +++ b/org.eclipse.xtext.util/src/org/eclipse/xtext/util/Exceptions.java @@ -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; /** @@ -28,28 +25,4 @@ public static T throwUncheckedException(Throwable e) { throw new RuntimeException(e); } - /** - * Invoke {@code Throwable#addSuppressed(Throwable)} reflectively if it is available. - * - * It is not available on JRE < 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); - } - } - } diff --git a/org.eclipse.xtext/src/org/eclipse/xtext/formatting2/internal/ConflictingRegionsException.java b/org.eclipse.xtext/src/org/eclipse/xtext/formatting2/internal/ConflictingRegionsException.java index 797f9b7f114..0cd59a7368f 100644 --- a/org.eclipse.xtext/src/org/eclipse/xtext/formatting2/internal/ConflictingRegionsException.java +++ b/org.eclipse.xtext/src/org/eclipse/xtext/formatting2/internal/ConflictingRegionsException.java @@ -30,7 +30,7 @@ public ConflictingRegionsException(String message, Throwable cause, Collection