Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Vogel2020-07-14 08:27:20 +0000
committerJeff Johnston2020-07-15 00:25:49 +0000
commit97a8a94ee42c4b1f1f62bf0bdaaf22b73a7caa90 (patch)
treef86384fcefe33dbb6c2c23a23bfa940989f280fc
parent66848a3268695de216ab63abdab756024097ef19 (diff)
downloadeclipse.jdt.ui-97a8a94ee42c4b1f1f62bf0bdaaf22b73a7caa90.tar.gz
eclipse.jdt.ui-97a8a94ee42c4b1f1f62bf0bdaaf22b73a7caa90.tar.xz
eclipse.jdt.ui-97a8a94ee42c4b1f1f62bf0bdaaf22b73a7caa90.zip
Bug 564416 - Use lambdas and method references cleanup on JDT UI code
For org.eclipse.jdt.ui - part 4 Change-Id: If094ebdc8d51fa6005efb531178fe82949332b13
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/AllCleanUpsAction.java10
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/CategoryFilterActionGroup.java50
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/ConfigureContainerAction.java15
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/IndentAction.java71
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/LexicalSortingAction.java17
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/OpenBrowserUtil.java49
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/SurroundWithActionGroup.java12
7 files changed, 89 insertions, 135 deletions
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/AllCleanUpsAction.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/AllCleanUpsAction.java
index 36b16bdd71..8ce487fbba 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/AllCleanUpsAction.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/AllCleanUpsAction.java
@@ -19,7 +19,6 @@ import java.lang.reflect.InvocationTargetException;
import org.eclipse.core.runtime.preferences.DefaultScope;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
-import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.ui.IWorkbenchSite;
@@ -90,12 +89,9 @@ public class AllCleanUpsAction extends CleanUpAction {
}
private void installPreferenceListener() {
- fPreferenceChangeListener= new IPreferenceChangeListener() {
- @Override
- public void preferenceChange(PreferenceChangeEvent event) {
- if (event.getKey().equals(CleanUpConstants.SHOW_CLEAN_UP_WIZARD)) {
- updateActionLabel();
- }
+ fPreferenceChangeListener= event -> {
+ if (event.getKey().equals(CleanUpConstants.SHOW_CLEAN_UP_WIZARD)) {
+ updateActionLabel();
}
};
InstanceScope.INSTANCE.getNode(JavaUI.ID_PLUGIN).addPreferenceChangeListener(fPreferenceChangeListener);
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/CategoryFilterActionGroup.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/CategoryFilterActionGroup.java
index f169db5f48..7c1434ff34 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/CategoryFilterActionGroup.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/CategoryFilterActionGroup.java
@@ -342,14 +342,11 @@ public class CategoryFilterActionGroup extends ActionGroup {
public void contributeToViewMenu(IMenuManager menuManager) {
menuManager.add(new Separator(CATEGORY_MENU_GROUP_NAME));
menuManager.appendToGroup(CATEGORY_MENU_GROUP_NAME, fMenuAction);
- fMenuListener= new IMenuListener() {
- @Override
- public void menuAboutToShow(IMenuManager manager) {
- if (!manager.isVisible())
- return;
- updateMenu(manager);
- }
- };
+ fMenuListener= manager -> {
+ if (!manager.isVisible())
+ return;
+ updateMenu(manager);
+ };
menuManager.addMenuListener(fMenuListener);
fMenuManager= menuManager;
}
@@ -395,21 +392,18 @@ public class CategoryFilterActionGroup extends ActionGroup {
final HashSet<String> foundLRUCategories= new HashSet<>();
final boolean hasUncategorizedMember[]= new boolean[] {false};
for (int i= 0; i < fInputElement.length && (!hasUncategorizedMember[0] || (foundLRUCategories.size() < MAX_NUMBER_OF_CATEGORIES_IN_MENU)); i++) {
- collectCategories(fInputElement[i], new IResultCollector() {
- @Override
- public boolean accept(String[] cats) {
- if (cats.length > 0) {
- for (String category : cats) {
- categories.add(category);
- if (fLRUList.containsKey(category)) {
- foundLRUCategories.add(category);
- }
+ collectCategories(fInputElement[i], cats -> {
+ if (cats.length > 0) {
+ for (String category : cats) {
+ categories.add(category);
+ if (fLRUList.containsKey(category)) {
+ foundLRUCategories.add(category);
}
- } else {
- hasUncategorizedMember[0]= true;
}
- return hasUncategorizedMember[0] && foundLRUCategories.size() >= MAX_NUMBER_OF_CATEGORIES_IN_MENU;
+ } else {
+ hasUncategorizedMember[0]= true;
}
+ return hasUncategorizedMember[0] && foundLRUCategories.size() >= MAX_NUMBER_OF_CATEGORIES_IN_MENU;
});
}
int count= 0;
@@ -468,12 +462,7 @@ public class CategoryFilterActionGroup extends ActionGroup {
private void fireSelectionChange() {
fViewer.getControl().setRedraw(false);
- BusyIndicator.showWhile(fViewer.getControl().getDisplay(), new Runnable() {
- @Override
- public void run() {
- fViewer.refresh();
- }
- });
+ BusyIndicator.showWhile(fViewer.getControl().getDisplay(), () -> fViewer.refresh());
fViewer.getControl().setRedraw(true);
}
@@ -484,12 +473,9 @@ public class CategoryFilterActionGroup extends ActionGroup {
private void showCategorySelectionDialog(IJavaElement[] input) {
final HashSet<String> categories= new HashSet<>();
for (IJavaElement i : input) {
- collectCategories(i, new IResultCollector() {
- @Override
- public boolean accept(String[] cats) {
- categories.addAll(Arrays.asList(cats));
- return false;
- }
+ collectCategories(i, cats -> {
+ categories.addAll(Arrays.asList(cats));
+ return false;
});
}
CategoryFilterSelectionDialog dialog= new CategoryFilterSelectionDialog(fViewer.getControl().getShell(), new ArrayList<>(categories), new ArrayList<>(fFilteredCategories));
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/ConfigureContainerAction.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/ConfigureContainerAction.java
index d5a90d03b0..33493f3edc 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/ConfigureContainerAction.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/ConfigureContainerAction.java
@@ -18,11 +18,9 @@ import java.lang.reflect.InvocationTargetException;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.operation.IRunnableContext;
-import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
@@ -94,14 +92,11 @@ public class ConfigureContainerAction implements IObjectActionDelegate {
if (context == null) {
context= PlatformUI.getWorkbench().getProgressService();
}
- context.run(true, true, new IRunnableWithProgress() {
- @Override
- public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
- try {
- project.setRawClasspath(newEntries, project.getOutputLocation(), monitor);
- } catch (CoreException e) {
- throw new InvocationTargetException(e);
- }
+ context.run(true, true, monitor -> {
+ try {
+ project.setRawClasspath(newEntries, project.getOutputLocation(), monitor);
+ } catch (CoreException e) {
+ throw new InvocationTargetException(e);
}
});
} catch (JavaModelException e) {
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/IndentAction.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/IndentAction.java
index aa6947eae6..9a45b9d5b6 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/IndentAction.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/IndentAction.java
@@ -170,47 +170,44 @@ public class IndentAction extends TextEditorAction {
return;
}
- Runnable runnable= new Runnable() {
- @Override
- public void run() {
- IRewriteTarget target= getTextEditor().getAdapter(IRewriteTarget.class);
- if (target != null)
- target.beginCompoundChange();
-
- try {
- JavaHeuristicScanner scanner= new JavaHeuristicScanner(document);
- JavaIndenter indenter= new JavaIndenter(document, scanner, getJavaProject());
- final boolean multiLine= nLines > 1;
- boolean hasChanged= false;
- for (int i= 0; i < nLines; i++) {
- hasChanged |= indentLine(document, firstLine + i, offset, indenter, scanner, multiLine);
- }
+ Runnable runnable= () -> {
+ IRewriteTarget target= getTextEditor().getAdapter(IRewriteTarget.class);
+ if (target != null)
+ target.beginCompoundChange();
+
+ try {
+ JavaHeuristicScanner scanner= new JavaHeuristicScanner(document);
+ JavaIndenter indenter= new JavaIndenter(document, scanner, getJavaProject());
+ final boolean multiLine= nLines > 1;
+ boolean hasChanged= false;
+ for (int i= 0; i < nLines; i++) {
+ hasChanged |= indentLine(document, firstLine + i, offset, indenter, scanner, multiLine);
+ }
- // update caret position: move to new position when indenting just one line
- // keep selection when indenting multiple
- int newOffset, newLength;
- if (!fIsTabAction && multiLine) {
- newOffset= offset;
- newLength= end.getOffset() - offset;
- } else {
- newOffset= fCaretOffset;
- newLength= 0;
- }
+ // update caret position: move to new position when indenting just one line
+ // keep selection when indenting multiple
+ int newOffset, newLength;
+ if (!fIsTabAction && multiLine) {
+ newOffset= offset;
+ newLength= end.getOffset() - offset;
+ } else {
+ newOffset= fCaretOffset;
+ newLength= 0;
+ }
- // always reset the selection if anything was replaced
- // but not when we had a single line non-tab invocation
- if (newOffset != -1 && (hasChanged || newOffset != offset || newLength != length))
- selectAndReveal(newOffset, newLength);
+ // always reset the selection if anything was replaced
+ // but not when we had a single line non-tab invocation
+ if (newOffset != -1 && (hasChanged || newOffset != offset || newLength != length))
+ selectAndReveal(newOffset, newLength);
- document.removePosition(end);
- } catch (BadLocationException e) {
- // will only happen on concurrent modification
- JavaPlugin.log(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IStatus.OK, "ConcurrentModification in IndentAction", e)); //$NON-NLS-1$
+ document.removePosition(end);
+ } catch (BadLocationException e) {
+ // will only happen on concurrent modification
+ JavaPlugin.log(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IStatus.OK, "ConcurrentModification in IndentAction", e)); //$NON-NLS-1$
- } finally {
- if (target != null)
- target.endCompoundChange();
- }
+ } finally {
+ if (target != null)
+ target.endCompoundChange();
}
};
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/LexicalSortingAction.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/LexicalSortingAction.java
index 6b92d5f0d1..a15fc6b449 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/LexicalSortingAction.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/LexicalSortingAction.java
@@ -61,16 +61,13 @@ public class LexicalSortingAction extends Action {
private void valueChanged(final boolean on, boolean store) {
setChecked(on);
- BusyIndicator.showWhile(fViewer.getControl().getDisplay(), new Runnable() {
- @Override
- public void run() {
- if (on) {
- fViewer.setComparator(fComparator);
- fDropSupport.setFeedbackEnabled(false);
- } else {
- fViewer.setComparator(fSourcePositonComparator);
- fDropSupport.setFeedbackEnabled(true);
- }
+ BusyIndicator.showWhile(fViewer.getControl().getDisplay(), () -> {
+ if (on) {
+ fViewer.setComparator(fComparator);
+ fDropSupport.setFeedbackEnabled(false);
+ } else {
+ fViewer.setComparator(fSourcePositonComparator);
+ fDropSupport.setFeedbackEnabled(true);
}
});
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/OpenBrowserUtil.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/OpenBrowserUtil.java
index ea397d5ee5..5e9b92b1ef 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/OpenBrowserUtil.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/OpenBrowserUtil.java
@@ -36,12 +36,7 @@ public class OpenBrowserUtil {
* @since 3.6
*/
public static void open(final URL url, Display display) {
- display.syncExec(new Runnable() {
- @Override
- public void run() {
- internalOpen(url, false);
- }
- });
+ display.syncExec(() -> internalOpen(url, false));
}
/**
@@ -52,34 +47,26 @@ public class OpenBrowserUtil {
* @since 3.6
*/
public static void openExternal(final URL url, Display display) {
- display.syncExec(new Runnable() {
- @Override
- public void run() {
- internalOpen(url, true);
- }
- });
+ display.syncExec(() -> internalOpen(url, true));
}
private static void internalOpen(final URL url, final boolean useExternalBrowser) {
- BusyIndicator.showWhile(null, new Runnable() {
- @Override
- public void run() {
- URL helpSystemUrl= PlatformUI.getWorkbench().getHelpSystem().resolve(url.toExternalForm(), true);
- if (helpSystemUrl == null) { // can happen if org.eclipse.help.ui is not available
- return; // the resolve() method already wrote "Unable to instantiate help UI" to the log
- }
- try {
- IWorkbenchBrowserSupport browserSupport= PlatformUI.getWorkbench().getBrowserSupport();
- IWebBrowser browser;
- if (useExternalBrowser)
- browser= browserSupport.getExternalBrowser();
- else
- browser= browserSupport.createBrowser(null);
- browser.openURL(helpSystemUrl);
- } catch (PartInitException ex) {
- // XXX: show dialog?
- JavaPlugin.logErrorStatus("Opening Javadoc failed", ex.getStatus()); //$NON-NLS-1$
- }
+ BusyIndicator.showWhile(null, () -> {
+ URL helpSystemUrl= PlatformUI.getWorkbench().getHelpSystem().resolve(url.toExternalForm(), true);
+ if (helpSystemUrl == null) { // can happen if org.eclipse.help.ui is not available
+ return; // the resolve() method already wrote "Unable to instantiate help UI" to the log
+ }
+ try {
+ IWorkbenchBrowserSupport browserSupport= PlatformUI.getWorkbench().getBrowserSupport();
+ IWebBrowser browser;
+ if (useExternalBrowser)
+ browser= browserSupport.getExternalBrowser();
+ else
+ browser= browserSupport.createBrowser(null);
+ browser.openURL(helpSystemUrl);
+ } catch (PartInitException ex) {
+ // XXX: show dialog?
+ JavaPlugin.logErrorStatus("Opening Javadoc failed", ex.getStatus()); //$NON-NLS-1$
}
});
}
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/SurroundWithActionGroup.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/SurroundWithActionGroup.java
index 736d7af19e..52427a0f4c 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/SurroundWithActionGroup.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/SurroundWithActionGroup.java
@@ -14,7 +14,6 @@
package org.eclipse.jdt.internal.ui.actions;
import org.eclipse.jface.action.Action;
-import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.viewers.ISelection;
@@ -81,13 +80,10 @@ public class SurroundWithActionGroup extends ActionGroup {
subMenu.setActionDefinitionId(SurroundWithTemplateMenuAction.SURROUND_WITH_QUICK_MENU_ACTION_ID);
menu.appendToGroup(fGroup, subMenu);
subMenu.add(new Action() {});
- subMenu.addMenuListener(new IMenuListener() {
- @Override
- public void menuAboutToShow(IMenuManager manager) {
- manager.removeAll();
- SurroundWithTemplateMenuAction.fillMenu(manager, fEditor, fSurroundWithTryCatchAction,
- fSurroundWithTryMultiCatchAction, fSurroundWithTryWithResourcesAction);
- }
+ subMenu.addMenuListener(manager -> {
+ manager.removeAll();
+ SurroundWithTemplateMenuAction.fillMenu(manager, fEditor, fSurroundWithTryCatchAction,
+ fSurroundWithTryMultiCatchAction, fSurroundWithTryWithResourcesAction);
});
}

Back to the top