No bug - Improve FilteredTypesSelectionDialog
Change-Id: Ie5fc85b6dbd0aa01a1f060c7797fecdcd373062d
Signed-off-by: Dawid Pakuła <zulus@w3des.net>
diff --git a/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/ui/dialogs/FilteredTypesSelectionDialog.java b/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/ui/dialogs/FilteredTypesSelectionDialog.java
index 3c48916..3dacf4d 100644
--- a/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/ui/dialogs/FilteredTypesSelectionDialog.java
+++ b/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/ui/dialogs/FilteredTypesSelectionDialog.java
@@ -3,7 +3,7 @@
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
- *
+ *
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
@@ -28,7 +28,7 @@
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.jobs.IJobManager;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.dltk.ast.Modifiers;
@@ -100,8 +100,7 @@
*
* @since 3.3
*/
-public class FilteredTypesSelectionDialog extends FilteredItemsSelectionDialog
- implements ITypeSelectionComponent {
+public class FilteredTypesSelectionDialog extends FilteredItemsSelectionDialog implements ITypeSelectionComponent {
private static final String DIALOG_SETTINGS = "org.eclipse.jdt.internal.ui.dialogs.FilteredTypesSelectionDialog"; //$NON-NLS-1$
@@ -138,68 +137,50 @@
/**
* Creates new FilteredTypesSelectionDialog instance
*
- * @param parent
- * shell to parent the dialog on
- * @param multi
- * <code>true</code> if multiple selection is
- * allowed
- * @param context
- * context used to execute long-running operations
- * associated with this dialog
- * @param scope
- * scope used when searching for types
- * @param elementKinds
- * flags defining nature of searched elements; the
- * only valid values are:
- * <code>IJavaSearchConstants.TYPE</code>
- * <code>IJavaSearchConstants.ANNOTATION_TYPE</code>
- * <code>IJavaSearchConstants.INTERFACE</code>
- * <code>IJavaSearchConstants.ENUM</code>
- * <code>IJavaSearchConstants.CLASS_AND_INTERFACE</code>
- * <code>IJavaSearchConstants.CLASS_AND_ENUM</code>.
- * Please note that the bitwise OR combination of
- * the elementary constants is not supported.
+ * @param parent shell to parent the dialog on
+ * @param multi <code>true</code> if multiple selection is allowed
+ * @param context context used to execute long-running operations
+ * associated with this dialog
+ * @param scope scope used when searching for types
+ * @param elementKinds flags defining nature of searched elements; the only
+ * valid values are: <code>IJavaSearchConstants.TYPE</code>
+ * <code>IJavaSearchConstants.ANNOTATION_TYPE</code>
+ * <code>IJavaSearchConstants.INTERFACE</code>
+ * <code>IJavaSearchConstants.ENUM</code>
+ * <code>IJavaSearchConstants.CLASS_AND_INTERFACE</code>
+ * <code>IJavaSearchConstants.CLASS_AND_ENUM</code>. Please
+ * note that the bitwise OR combination of the elementary
+ * constants is not supported.
*/
- public FilteredTypesSelectionDialog(Shell parent, boolean multi,
- IRunnableContext context, IDLTKSearchScope scope, int elementKinds,
- IDLTKLanguageToolkit toolkit) {
+ public FilteredTypesSelectionDialog(Shell parent, boolean multi, IRunnableContext context, IDLTKSearchScope scope,
+ int elementKinds, IDLTKLanguageToolkit toolkit) {
this(parent, multi, context, scope, elementKinds, null, toolkit);
}
/**
* Creates new FilteredTypesSelectionDialog instance.
*
- * @param shell
- * shell to parent the dialog on
- * @param multi
- * <code>true</code> if multiple selection is
- * allowed
- * @param context
- * context used to execute long-running operations
- * associated with this dialog
- * @param scope
- * scope used when searching for types. If the scope
- * is <code>null</code>, then workspace is scope is
- * used as default, and the user can choose a
- * working set as scope.
- * @param elementKinds
- * flags defining nature of searched elements; the
- * only valid values are:
- * <code>IJavaSearchConstants.TYPE</code>
- * <code>IJavaSearchConstants.ANNOTATION_TYPE</code>
- * <code>IJavaSearchConstants.INTERFACE</code>
- * <code>IJavaSearchConstants.ENUM</code>
- * <code>IJavaSearchConstants.CLASS_AND_INTERFACE</code>
- * <code>IJavaSearchConstants.CLASS_AND_ENUM</code>.
- * Please note that the bitwise OR combination of
- * the elementary constants is not supported.
- * @param extension
- * an extension of the standard type selection
- * dialog; See {@link TypeSelectionExtension}
+ * @param shell shell to parent the dialog on
+ * @param multi <code>true</code> if multiple selection is allowed
+ * @param context context used to execute long-running operations
+ * associated with this dialog
+ * @param scope scope used when searching for types. If the scope is
+ * <code>null</code>, then workspace is scope is used as
+ * default, and the user can choose a working set as scope.
+ * @param elementKinds flags defining nature of searched elements; the only
+ * valid values are: <code>IJavaSearchConstants.TYPE</code>
+ * <code>IJavaSearchConstants.ANNOTATION_TYPE</code>
+ * <code>IJavaSearchConstants.INTERFACE</code>
+ * <code>IJavaSearchConstants.ENUM</code>
+ * <code>IJavaSearchConstants.CLASS_AND_INTERFACE</code>
+ * <code>IJavaSearchConstants.CLASS_AND_ENUM</code>. Please
+ * note that the bitwise OR combination of the elementary
+ * constants is not supported.
+ * @param extension an extension of the standard type selection dialog; See
+ * {@link TypeSelectionExtension}
*/
- public FilteredTypesSelectionDialog(Shell shell, boolean multi,
- IRunnableContext context, IDLTKSearchScope scope, int elementKinds,
- TypeSelectionExtension extension, IDLTKLanguageToolkit toolkit) {
+ public FilteredTypesSelectionDialog(Shell shell, boolean multi, IRunnableContext context, IDLTKSearchScope scope,
+ int elementKinds, TypeSelectionExtension extension, IDLTKLanguageToolkit toolkit) {
super(shell, multi);
this.fToolkit = toolkit;
@@ -215,23 +196,20 @@
fElementKinds = elementKinds;
fExtension = extension;
- fFilterExtension = (extension == null) ? null
- : extension.getFilterExtension();
+ fFilterExtension = (extension == null) ? null : extension.getFilterExtension();
fSearchScope = scope;
if (extension != null) {
fValidator = extension.getSelectionValidator();
}
- fTypeInfoUtil = new TypeInfoUtil(
- extension != null ? extension.getImageProvider() : null);
+ fTypeInfoUtil = new TypeInfoUtil(extension != null ? extension.getImageProvider() : null);
fTypeInfoLabelProvider = new TypeItemLabelProvider();
setListLabelProvider(fTypeInfoLabelProvider);
setListSelectionLabelDecorator(fTypeInfoLabelProvider);
- setDetailsLabelProvider(
- new TypeItemDetailsLabelProvider(fTypeInfoUtil));
+ setDetailsLabelProvider(new TypeItemDetailsLabelProvider(fTypeInfoUtil));
fTypeItemsComparator = new TypeItemsComparator();
}
@@ -245,27 +223,22 @@
/**
* Adds or replaces subtitle of the dialog
*
- * @param text
- * the new subtitle for this dialog
+ * @param text the new subtitle for this dialog
*/
private void setSubtitle(String text) {
if (text == null || text.length() == 0) {
getShell().setText(fTitle);
} else {
- getShell().setText(Messages.format(
- DLTKUIMessages.FilteredTypeSelectionDialog_titleFormat,
- fTitle, text));
+ getShell().setText(Messages.format(DLTKUIMessages.FilteredTypeSelectionDialog_titleFormat, fTitle, text));
}
}
@Override
protected IDialogSettings getDialogSettings() {
- IDialogSettings settings = DLTKUIPlugin.getDefault().getDialogSettings()
- .getSection(DIALOG_SETTINGS);
+ IDialogSettings settings = DLTKUIPlugin.getDefault().getDialogSettings().getSection(DIALOG_SETTINGS);
if (settings == null) {
- settings = DLTKUIPlugin.getDefault().getDialogSettings()
- .addNewSection(DIALOG_SETTINGS);
+ settings = DLTKUIPlugin.getDefault().getDialogSettings().addNewSection(DIALOG_SETTINGS);
}
return settings;
@@ -282,8 +255,7 @@
StringWriter writer = new StringWriter();
try {
memento.save(writer);
- settings.put(WORKINGS_SET_SETTINGS,
- writer.getBuffer().toString());
+ settings.put(WORKINGS_SET_SETTINGS, writer.getBuffer().toString());
} catch (IOException e) {
// don't do anything. Simply don't store the settings
DLTKUIPlugin.log(e);
@@ -301,8 +273,7 @@
String setting = settings.get(WORKINGS_SET_SETTINGS);
if (setting != null) {
try {
- IMemento memento = XMLMemento
- .createReadRoot(new StringReader(setting));
+ IMemento memento = XMLMemento.createReadRoot(new StringReader(setting));
fFilterActionGroup.restoreState(memento);
} catch (WorkbenchException e) {
// don't do anything. Simply don't restore the settings
@@ -314,8 +285,7 @@
setSearchScope(SearchEngine.createWorkspaceScope(fToolkit));
setSubtitle(null);
} else {
- setSearchScope(DLTKSearchScopeFactory.getInstance()
- .createSearchScope(ws, true, fToolkit));
+ setSearchScope(DLTKSearchScopeFactory.getInstance().createSearchScope(ws, true, fToolkit));
setSubtitle(ws.getLabel());
}
}
@@ -333,22 +303,18 @@
super.fillViewMenu(menuManager);
if (fAllowScopeSwitching) {
- fFilterActionGroup = new WorkingSetFilterActionGroup(getShell(),
- DLTKUIPlugin.getActivePage(), event -> {
- IWorkingSet ws = (IWorkingSet) event.getNewValue();
- if (ws == null || (ws.isAggregateWorkingSet()
- && ws.isEmpty())) {
- setSearchScope(SearchEngine
- .createWorkspaceScope(fToolkit));
- setSubtitle(null);
- } else {
- setSearchScope(DLTKSearchScopeFactory.getInstance()
- .createSearchScope(ws, true, fToolkit));
- setSubtitle(ws.getLabel());
- }
+ fFilterActionGroup = new WorkingSetFilterActionGroup(getShell(), DLTKUIPlugin.getActivePage(), event -> {
+ IWorkingSet ws = (IWorkingSet) event.getNewValue();
+ if (ws == null || (ws.isAggregateWorkingSet() && ws.isEmpty())) {
+ setSearchScope(SearchEngine.createWorkspaceScope(fToolkit));
+ setSubtitle(null);
+ } else {
+ setSearchScope(DLTKSearchScopeFactory.getInstance().createSearchScope(ws, true, fToolkit));
+ setSubtitle(ws.getLabel());
+ }
- applyFilter();
- });
+ applyFilter();
+ });
fFilterActionGroup.fillViewMenu(menuManager);
}
@@ -379,7 +345,7 @@
@Override
protected void setResult(List newResult) {
- List resultToReturn = new ArrayList();
+ List<IType> resultToReturn = new ArrayList<>();
for (int i = 0; i < newResult.size(); i++) {
if (newResult.get(i) instanceof TypeNameMatch) {
@@ -392,14 +358,10 @@
} else {
TypeNameMatch typeInfo = (TypeNameMatch) newResult.get(i);
IProjectFragment root = typeInfo.getProjectFragment();
- IDLTKUILanguageToolkit uiToolkit = DLTKUILanguageManager
- .getLanguageToolkit(fToolkit.getNatureId());
- ScriptElementLabels labels = uiToolkit
- .getScriptElementLabels();
- String containerName = labels.getElementLabel(root,
- ScriptElementLabels.ALL_FULLY_QUALIFIED);
- String message = Messages.format(
- DLTKUIMessages.FilteredTypesSelectionDialog_dialogMessage,
+ IDLTKUILanguageToolkit uiToolkit = DLTKUILanguageManager.getLanguageToolkit(fToolkit.getNatureId());
+ ScriptElementLabels labels = uiToolkit.getScriptElementLabels();
+ String containerName = labels.getElementLabel(root, ScriptElementLabels.ALL_FULLY_QUALIFIED);
+ String message = Messages.format(DLTKUIMessages.FilteredTypesSelectionDialog_dialogMessage,
typeInfo.getFullyQualifiedName(), containerName);
MessageDialog.openError(getShell(), fTitle, message);
getSelectionHistory().remove(typeInfo);
@@ -424,8 +386,7 @@
if (getInitialPattern() == null) {
IWorkbenchWindow window = DLTKUIPlugin.getActiveWorkbenchWindow();
if (window != null) {
- ISelection selection = window.getSelectionService()
- .getSelection();
+ ISelection selection = window.getSelectionService().getSelection();
if (selection instanceof ITextSelection) {
String text = ((ITextSelection) selection).getText();
if (text != null) {
@@ -443,8 +404,7 @@
/**
* Sets a new validator.
*
- * @param validator
- * the new validator
+ * @param validator the new validator
*/
public void setValidator(ISelectionStatusValidator validator) {
fValidator = validator;
@@ -452,8 +412,7 @@
@Override
protected ItemsFilter createFilter() {
- return new TypeItemsFilter(fSearchScope, fElementKinds,
- fFilterExtension);
+ return new TypeItemsFilter(fSearchScope, fElementKinds, fFilterExtension);
}
@Override
@@ -470,64 +429,21 @@
return contents;
}
- // private void installOwnerDraw(Table tableControl) {
- // new OwnerDrawSupport(tableControl) { // installs the owner draw
- // // listeners
- // public ColoredString getColoredLabel(Item item) {
- // String text = item.getText();
- // ColoredString str = new ColoredString(text);
- // int index = text.indexOf('-');
- // if (index != -1) {
- // str.colorize(index, str.length() - index,
- // ColoredJavaElementLabels.QUALIFIER_STYLE);
- // }
- // return str;
- // }
- //
- // public Color getColor(String foregroundColorName, Display display) {
- // return PlatformUI.getWorkbench().getThemeManager()
- // .getCurrentTheme().getColorRegistry().get(
- // foregroundColorName);
- // }
- // };
- // }
- //
- // private Table findTableControl(Composite composite) {
- // Control[] children = composite.getChildren();
- // for (int i = 0; i < children.length; i++) {
- // Control curr = children[i];
- // if (curr instanceof Table) {
- // return (Table) curr;
- // } else if (curr instanceof Composite) {
- // Table res = findTableControl((Composite) curr);
- // if (res != null) {
- // return res;
- // }
- // }
- // }
- // return null;
- // }
-
@Override
- protected void fillContentProvider(AbstractContentProvider provider,
- ItemsFilter itemsFilter, IProgressMonitor progressMonitor)
- throws CoreException {
+ protected void fillContentProvider(AbstractContentProvider provider, ItemsFilter itemsFilter,
+ IProgressMonitor progressMonitor) throws CoreException {
TypeItemsFilter typeSearchFilter = (TypeItemsFilter) itemsFilter;
- TypeSearchRequestor requestor = new TypeSearchRequestor(provider,
- typeSearchFilter);
+ TypeSearchRequestor requestor = new TypeSearchRequestor(provider, typeSearchFilter);
String typePattern = itemsFilter.getPattern();
- progressMonitor.setTaskName(
- DLTKUIMessages.FilteredTypesSelectionDialog_searchJob_taskName);
+ progressMonitor.setTaskName(DLTKUIMessages.FilteredTypesSelectionDialog_searchJob_taskName);
IType[] types = new ModelAccess().findTypes(typePattern,
- ModelAccess.convertSearchRule(itemsFilter.getMatchRule()), 0,
- Modifiers.AccNameSpace, typeSearchFilter.getSearchScope(),
- progressMonitor);
+ ModelAccess.convertSearchRule(itemsFilter.getMatchRule()), 0, Modifiers.AccNameSpace,
+ typeSearchFilter.getSearchScope(), progressMonitor);
if (types != null) {
for (IType type : types) {
- requestor.acceptTypeNameMatch(
- new DLTKSearchTypeNameMatch(type, type.getFlags()));
+ requestor.acceptTypeNameMatch(new DLTKSearchTypeNameMatch(type, type.getFlags()));
}
} else {
@@ -535,12 +451,11 @@
String packPattern = typeSearchFilter.getPackagePattern();
/*
- * Setting the filter into match everything mode avoids filtering
- * twice by the same pattern (the search engine only provides
- * filtered matches). For the case when the pattern is a camel case
- * pattern with a terminator, the filter is not set to match
- * everything mode because jdt.core's SearchPattern does not support
- * that case.
+ * Setting the filter into match everything mode avoids filtering twice by the
+ * same pattern (the search engine only provides filtered matches). For the case
+ * when the pattern is a camel case pattern with a terminator, the filter is not
+ * set to match everything mode because jdt.core's SearchPattern does not
+ * support that case.
*/
int matchRule = typeSearchFilter.getMatchRule();
if (matchRule == SearchPattern.RULE_CAMELCASE_MATCH) {
@@ -550,8 +465,7 @@
char lastChar = typePattern.charAt(typePattern.length() - 1);
if (lastChar == '<' || lastChar == ' ') {
- typePattern = typePattern.substring(0,
- typePattern.length() - 1);
+ typePattern = typePattern.substring(0, typePattern.length() - 1);
} else {
typeSearchFilter.setMatchEverythingMode(true);
}
@@ -560,16 +474,10 @@
}
try {
- engine.searchAllTypeNames(
- packPattern == null ? null : packPattern.toCharArray(),
- typeSearchFilter.getPackageFlags(), // TODO:
- // https://bugs.eclipse.org/bugs/show_bug.cgi?id=176017
- typePattern.toCharArray(), matchRule, // TODO:
- // https://bugs.eclipse.org/bugs/show_bug.cgi?id=176017
- typeSearchFilter.getElementKind(),
- typeSearchFilter.getSearchScope(), requestor,
- IDLTKSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
- progressMonitor);
+ engine.searchAllTypeNames(packPattern == null ? null : packPattern.toCharArray(),
+ typeSearchFilter.getPackageFlags(), typePattern.toCharArray(), matchRule,
+ typeSearchFilter.getElementKind(), typeSearchFilter.getSearchScope(), requestor,
+ IDLTKSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, progressMonitor);
} finally {
typeSearchFilter.setMatchEverythingMode(false);
}
@@ -591,50 +499,43 @@
protected IStatus validateItem(Object item) {
if (item == null)
- return new Status(IStatus.ERROR, DLTKUIPlugin.getPluginId(),
- IStatus.ERROR, "", null); //$NON-NLS-1$
+ return new Status(IStatus.ERROR, DLTKUIPlugin.getPluginId(), IStatus.ERROR, "", null); //$NON-NLS-1$
if (fValidator != null) {
IType type = ((TypeNameMatch) item).getType();
if (!type.exists())
- return new Status(IStatus.ERROR, DLTKUIPlugin.getPluginId(),
- IStatus.ERROR,
- Messages.format(
- DLTKUIMessages.FilteredTypesSelectionDialog_error_type_doesnot_exist,
+ return new Status(IStatus.ERROR, DLTKUIPlugin.getPluginId(), IStatus.ERROR,
+ Messages.format(DLTKUIMessages.FilteredTypesSelectionDialog_error_type_doesnot_exist,
((TypeNameMatch) item).getFullyQualifiedName()),
null);
Object[] elements = { type };
return fValidator.validate(elements);
}
- return new Status(IStatus.OK, DLTKUIPlugin.getPluginId(), IStatus.OK,
- "", null); //$NON-NLS-1$
+ return new Status(IStatus.OK, DLTKUIPlugin.getPluginId(), IStatus.OK, "", null); //$NON-NLS-1$
}
/**
* Sets search scope used when searching for types.
*
- * @param scope
- * the new scope
+ * @param scope the new scope
*/
private void setSearchScope(IDLTKSearchScope scope) {
fSearchScope = scope;
}
/*
- * We only have to ensure history consistency here since the search engine
- * takes care of working copies.
+ * We only have to ensure history consistency here since the search engine takes
+ * care of working copies.
*/
private static class ConsistencyRunnable implements IRunnableWithProgress {
private IDLTKUILanguageToolkit tookit;
ConsistencyRunnable(IDLTKLanguageToolkit toolkit) {
- this.tookit = DLTKUILanguageManager
- .getLanguageToolkit(toolkit.getNatureId());
+ this.tookit = DLTKUILanguageManager.getLanguageToolkit(toolkit.getNatureId());
}
@Override
- public void run(IProgressMonitor monitor)
- throws InvocationTargetException, InterruptedException {
+ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
if (fgFirstTime) {
// Join the initialize after load job.
IJobManager manager = Job.getJobManager();
@@ -643,16 +544,13 @@
OpenTypeHistory history = OpenTypeHistory.getInstance(tookit);
if (fgFirstTime || history.isEmpty()) {
if (history.needConsistencyCheck()) {
- monitor.beginTask(
- DLTKUIMessages.TypeSelectionDialog_progress_consistency,
- 100);
- refreshSearchIndices(new SubProgressMonitor(monitor, 90));
- history.checkConsistency(
- new SubProgressMonitor(monitor, 10));
+ SubMonitor subMonitor = SubMonitor.convert(monitor,
+ DLTKUIMessages.TypeSelectionDialog_progress_consistency, 100);
+ refreshSearchIndices(subMonitor.split(90));
+ history.checkConsistency(subMonitor.split(10));
} else {
refreshSearchIndices(monitor);
}
- monitor.done();
fgFirstTime = false;
} else {
history.checkConsistency(monitor);
@@ -661,27 +559,19 @@
public static boolean needsExecution(IDLTKLanguageToolkit toolkit) {
OpenTypeHistory history = OpenTypeHistory
- .getInstance(DLTKUILanguageManager
- .getLanguageToolkit(toolkit.getNatureId()));
- return fgFirstTime || history.isEmpty()
- || history.needConsistencyCheck();
+ .getInstance(DLTKUILanguageManager.getLanguageToolkit(toolkit.getNatureId()));
+ return fgFirstTime || history.isEmpty() || history.needConsistencyCheck();
}
- private void refreshSearchIndices(IProgressMonitor monitor)
- throws InvocationTargetException {
+ private void refreshSearchIndices(IProgressMonitor monitor) throws InvocationTargetException {
try {
new SearchEngine().searchAllTypeNames(null, 0,
// make sure we search a concrete name. This is faster
// according to Kent
"_______________".toCharArray(), //$NON-NLS-1$
- SearchPattern.RULE_EXACT_MATCH
- | SearchPattern.RULE_CASE_SENSITIVE,
- IDLTKSearchConstants.TYPE,
- SearchEngine
- .createWorkspaceScope(tookit.getCoreToolkit()),
- new NopTypeNameRequestor(),
- IDLTKSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
- monitor);
+ SearchPattern.RULE_EXACT_MATCH | SearchPattern.RULE_CASE_SENSITIVE, IDLTKSearchConstants.TYPE,
+ SearchEngine.createWorkspaceScope(tookit.getCoreToolkit()), new NopTypeNameRequestor(),
+ IDLTKSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, monitor);
} catch (ModelException e) {
throw new InvocationTargetException(e);
}
@@ -691,17 +581,14 @@
@Override
public void reloadCache(boolean checkDuplicates, IProgressMonitor monitor) {
IProgressMonitor remainingMonitor;
+ SubMonitor subMonitor = SubMonitor.convert(monitor, DLTKUIMessages.TypeSelectionDialog_progress_consistency,
+ 10);
if (ConsistencyRunnable.needsExecution(fToolkit)) {
- monitor.beginTask(
- DLTKUIMessages.TypeSelectionDialog_progress_consistency,
- 10);
try {
- ConsistencyRunnable runnable = new ConsistencyRunnable(
- fToolkit);
- runnable.run(new SubProgressMonitor(monitor, 1));
+ ConsistencyRunnable runnable = new ConsistencyRunnable(fToolkit);
+ runnable.run(subMonitor.split(1));
} catch (InvocationTargetException e) {
- ExceptionHandler.handle(e,
- DLTKUIMessages.TypeSelectionDialog_error3Title,
+ ExceptionHandler.handle(e, DLTKUIMessages.TypeSelectionDialog_error3Title,
DLTKUIMessages.TypeSelectionDialog_error3Message);
close();
return;
@@ -710,12 +597,11 @@
close();
return;
}
- remainingMonitor = new SubProgressMonitor(monitor, 9);
+ remainingMonitor = subMonitor.split(9);
} else {
- remainingMonitor = monitor;
+ remainingMonitor = subMonitor;
}
super.reloadCache(checkDuplicates, remainingMonitor);
- monitor.done();
}
@Override
@@ -727,8 +613,7 @@
/**
* A <code>LabelProvider</code> for (the table of) types.
*/
- private class TypeItemLabelProvider extends LabelProvider
- implements ILabelDecorator {
+ private class TypeItemLabelProvider extends LabelProvider implements ILabelDecorator {
private boolean fContainerInfo;
@@ -752,8 +637,7 @@
TypeNameMatch type = (TypeNameMatch) element;
- ImageDescriptor iD = ScriptElementImageProvider
- .getTypeImageDescriptor(type.getModifiers(), false);
+ ImageDescriptor iD = ScriptElementImageProvider.getTypeImageDescriptor(type.getModifiers(), false);
return DLTKUIPlugin.getImageDescriptorRegistry().get(iD);
}
@@ -765,8 +649,7 @@
}
if (fContainerInfo && isDuplicateElement(element)) {
- return fTypeInfoUtil
- .getFullyQualifiedText((TypeNameMatch) element);
+ return fTypeInfoUtil.getFullyQualifiedText((TypeNameMatch) element);
}
if (!fContainerInfo && isDuplicateElement(element)) {
@@ -788,8 +671,7 @@
}
if (fContainerInfo && isDuplicateElement(element)) {
- return fTypeInfoUtil
- .getFullyQualifiedText((TypeNameMatch) element);
+ return fTypeInfoUtil.getFullyQualifiedText((TypeNameMatch) element);
}
return fTypeInfoUtil.getQualifiedText((TypeNameMatch) element);
@@ -810,10 +692,8 @@
fTypeInfoUtil = typeInfoUtil;
fLabelProvider = new TypeNameMatchLabelProvider(
- TypeNameMatchLabelProvider.SHOW_TYPE_ONLY
- + TypeNameMatchLabelProvider.SHOW_FULLYQUALIFIED,
- DLTKUILanguageManager
- .getLanguageToolkit(fToolkit.getNatureId()));
+ TypeNameMatchLabelProvider.SHOW_TYPE_ONLY + TypeNameMatchLabelProvider.SHOW_FULLYQUALIFIED,
+ DLTKUILanguageManager.getLanguageToolkit(fToolkit.getNatureId()));
}
@Override
@@ -828,8 +708,7 @@
@Override
public String getText(Object element) {
if (element instanceof TypeNameMatch) {
- return fTypeInfoUtil
- .getQualificationText((TypeNameMatch) element);
+ return fTypeInfoUtil.getQualificationText((TypeNameMatch) element);
}
return super.getText(element);
@@ -842,20 +721,17 @@
private final TypeInfoRequestorAdapter fAdapter = new TypeInfoRequestorAdapter();
- private final Map fLib2Name = new HashMap();
+ private final Map<String, String> fLib2Name = new HashMap<>();
private final String[] fInstallLocations;
private final String[] fVMNames;
- private boolean fFullyQualifyDuplicates;
-
public TypeInfoUtil(ITypeInfoImageProvider extension) {
fProviderExtension = extension;
List<String> locations = new ArrayList<>();
List<String> labels = new ArrayList<>();
- IInterpreterInstallType[] installs = ScriptRuntime
- .getInterpreterInstallTypes(fToolkit.getNatureId());
+ IInterpreterInstallType[] installs = ScriptRuntime.getInterpreterInstallTypes(fToolkit.getNatureId());
for (int i = 0; i < installs.length; i++) {
processInterpreterInstallType(installs[i], locations, labels);
}
@@ -864,30 +740,24 @@
}
- private void processInterpreterInstallType(
- IInterpreterInstallType installType, List<String> locations,
+ private void processInterpreterInstallType(IInterpreterInstallType installType, List<String> locations,
List<String> labels) {
if (installType != null) {
- IInterpreterInstall[] installs = installType
- .getInterpreterInstalls();
+ IInterpreterInstall[] installs = installType.getInterpreterInstalls();
boolean isMac = Platform.OS_MACOSX.equals(Platform.getOS());
final String HOME_SUFFIX = "/Home"; //$NON-NLS-1$
for (int i = 0; i < installs.length; i++) {
String label = getFormattedLabel(installs[i].getName());
- LibraryLocation[] libLocations = installs[i]
- .getLibraryLocations();
+ LibraryLocation[] libLocations = installs[i].getLibraryLocations();
if (libLocations != null) {
processLibraryLocation(libLocations, label);
} else {
- String filePath = installs[i].getInstallLocation()
- .toOSString();
+ String filePath = installs[i].getInstallLocation().toOSString();
if (filePath != null) {
// on MacOS X install locations end in an additional
// "/Home" segment; remove it
if (isMac && filePath.endsWith(HOME_SUFFIX))
- filePath = filePath.substring(0,
- filePath.length() - HOME_SUFFIX.length()
- + 1);
+ filePath = filePath.substring(0, filePath.length() - HOME_SUFFIX.length() + 1);
locations.add(filePath);
labels.add(label);
}
@@ -896,8 +766,7 @@
}
}
- private void processLibraryLocation(LibraryLocation[] libLocations,
- String label) {
+ private void processLibraryLocation(LibraryLocation[] libLocations, String label) {
for (int l = 0; l < libLocations.length; l++) {
LibraryLocation location = libLocations[l];
fLib2Name.put(location.getLibraryPath().toOSString(), label);
@@ -905,9 +774,7 @@
}
private String getFormattedLabel(String name) {
- return Messages.format(
- DLTKUIMessages.FilteredTypesSelectionDialog_library_name_format,
- name);
+ return Messages.format(DLTKUIMessages.FilteredTypesSelectionDialog_library_name_format, name);
}
public String getText(Object element) {
@@ -963,20 +830,18 @@
return fVMNames[i];
}
}
- String lib = (String) fLib2Name.get(name);
+ String lib = fLib2Name.get(name);
if (lib != null)
return lib;
}
StringBuffer buf = new StringBuffer();
- ScriptElementLabels labels = DLTKUILanguageManager
- .getLanguageToolkit(fToolkit.getNatureId())
+ ScriptElementLabels labels = DLTKUILanguageManager.getLanguageToolkit(fToolkit.getNatureId())
.getScriptElementLabels();
- labels.getProjectFragmentLabel(root,
- ScriptElementLabels.ROOT_QUALIFIED
- | ScriptElementLabels.ROOT_VARIABLE,
+ labels.getProjectFragmentLabel(root, ScriptElementLabels.ROOT_QUALIFIED | ScriptElementLabels.ROOT_VARIABLE,
buf);
return buf.toString();
}
+
}
/**
@@ -984,8 +849,7 @@
*/
private class TypeItemsFilter extends ItemsFilter {
- private static final int TYPE_MODIFIERS = Flags.AccAnnotation
- | Flags.AccInterface;
+ private static final int TYPE_MODIFIERS = Flags.AccAnnotation | Flags.AccInterface;
private final IDLTKSearchScope fScope;
@@ -1010,16 +874,13 @@
* @param elementKind
* @param extension
*/
- public TypeItemsFilter(IDLTKSearchScope scope, int elementKind,
- ITypeInfoFilterExtension extension) {
+ public TypeItemsFilter(IDLTKSearchScope scope, int elementKind, ITypeInfoFilterExtension extension) {
super(new TypeSearchPattern());
fScope = scope;
- fIsWorkspaceScope = scope == null ? false
- : scope.equals(SearchEngine.createWorkspaceScope(fToolkit));
+ fIsWorkspaceScope = scope == null ? false : scope.equals(SearchEngine.createWorkspaceScope(fToolkit));
fElemKind = elementKind;
fFilterExt = extension;
- String stringPackage = ((TypeSearchPattern) patternMatcher)
- .getPackagePattern();
+ String stringPackage = ((TypeSearchPattern) patternMatcher).getPackagePattern();
if (stringPackage != null) {
fPackageMatcher = new SearchPattern();
fPackageMatcher.setPattern(stringPackage);
@@ -1035,11 +896,9 @@
TypeItemsFilter typeItemsFilter = (TypeItemsFilter) filter;
if (fScope != typeItemsFilter.getSearchScope())
return false;
- if (fMyTypeFilterVersion != typeItemsFilter
- .getMyTypeFilterVersion())
+ if (fMyTypeFilterVersion != typeItemsFilter.getMyTypeFilterVersion())
return false;
- return getPattern().indexOf('.',
- filter.getPattern().length()) == -1;
+ return getPattern().indexOf('.', filter.getPattern().length()) == -1;
}
@Override
@@ -1051,8 +910,7 @@
TypeItemsFilter typeItemsFilter = (TypeItemsFilter) iFilter;
if (fScope != typeItemsFilter.getSearchScope())
return false;
- if (fMyTypeFilterVersion != typeItemsFilter
- .getMyTypeFilterVersion())
+ if (fMyTypeFilterVersion != typeItemsFilter.getMyTypeFilterVersion())
return false;
return true;
}
@@ -1083,8 +941,7 @@
}
public boolean matchesRawNamePattern(TypeNameMatch type) {
- return Strings.startsWithIgnoreCase(type.getSimpleTypeName(),
- getPattern());
+ return Strings.startsWithIgnoreCase(type.getSimpleTypeName(), getPattern());
}
public boolean matchesFilterExtension(TypeNameMatch type) {
@@ -1128,11 +985,9 @@
/**
* Set filter to "match everything" mode.
*
- * @param matchEverything
- * if <code>true</code>,
- * {@link #matchItem(Object)} always returns
- * true. If <code>false</code>, the filter is
- * enabled.
+ * @param matchEverything if <code>true</code>, {@link #matchItem(Object)}
+ * always returns true. If <code>false</code>, the filter
+ * is enabled.
*/
public void setMatchEverythingMode(boolean matchEverything) {
this.fMatchEverything = matchEverything;
@@ -1150,8 +1005,7 @@
return true;
TypeNameMatch type = (TypeNameMatch) item;
- if (!(matchesPackage(type) && matchesModifiers(type)
- && matchesScope(type) && matchesFilterExtension(type)))
+ if (!(matchesPackage(type) && matchesModifiers(type) && matchesScope(type) && matchesFilterExtension(type)))
return false;
return matchesName(type);
}
@@ -1177,8 +1031,7 @@
String packPattern = null;
int index = stringPattern.lastIndexOf("."); //$NON-NLS-1$
if (index != -1) {
- packPattern = evaluatePackagePattern(
- stringPattern.substring(0, index));
+ packPattern = evaluatePackagePattern(stringPattern.substring(0, index));
pattern = stringPattern.substring(index + 1);
if (pattern.length() == 0)
pattern = "**"; //$NON-NLS-1$
@@ -1237,9 +1090,8 @@
/**
* A <code>TypeSearchRequestor</code> collects matches filtered using
- * <code>TypeItemsFilter</code>. The attached content provider is filled on
- * the basis of the collected entries (instances of
- * <code>TypeNameMatch</code>).
+ * <code>TypeItemsFilter</code>. The attached content provider is filled on the
+ * basis of the collected entries (instances of <code>TypeNameMatch</code>).
*/
private class TypeSearchRequestor extends TypeNameMatchRequestor {
private volatile boolean fStop;
@@ -1247,10 +1099,9 @@
private final AbstractContentProvider fContentProvider;
private final TypeItemsFilter fTypeItemsFilter;
- Set addedNames = new HashSet();
+ Set<String> addedNames = new HashSet<>();
- public TypeSearchRequestor(AbstractContentProvider contentProvider,
- TypeItemsFilter typeItemsFilter) {
+ public TypeSearchRequestor(AbstractContentProvider contentProvider, TypeItemsFilter typeItemsFilter) {
super();
fContentProvider = contentProvider;
fTypeItemsFilter = typeItemsFilter;
@@ -1260,9 +1111,7 @@
public void acceptTypeNameMatch(TypeNameMatch match) {
if (fStop)
return;
- if (new TypeFilter(DLTKUILanguageManager
- .getLanguageToolkit(fToolkit.getNatureId()))
- .isFiltered(match))
+ if (new TypeFilter(DLTKUILanguageManager.getLanguageToolkit(fToolkit.getNatureId())).isFiltered(match))
return;
if (!addedNames.contains(match.getTypeQualifiedName())) {
addedNames.add(match.getTypeQualifiedName());
@@ -1275,9 +1124,9 @@
/**
* Compares TypeItems is used during sorting
*/
- private class TypeItemsComparator implements Comparator {
+ private class TypeItemsComparator implements Comparator<TypeNameMatch> {
- private final Map fLib2Name = new HashMap();
+ private final Map<String, String> fLib2Name = new HashMap<>();
private final String[] fInstallLocations;
@@ -1289,8 +1138,7 @@
public TypeItemsComparator() {
List<String> locations = new ArrayList<>();
List<String> labels = new ArrayList<>();
- IInterpreterInstallType[] installs = ScriptRuntime
- .getInterpreterInstallTypes();
+ IInterpreterInstallType[] installs = ScriptRuntime.getInterpreterInstallTypes();
for (int i = 0; i < installs.length; i++) {
processVMInstallType(installs[i], locations, labels);
}
@@ -1298,27 +1146,23 @@
fVMNames = labels.toArray(new String[labels.size()]);
}
- private void processVMInstallType(IInterpreterInstallType installType,
- List<String> locations, List<String> labels) {
+ private void processVMInstallType(IInterpreterInstallType installType, List<String> locations,
+ List<String> labels) {
if (installType != null) {
- IInterpreterInstall[] installs = installType
- .getInterpreterInstalls();
+ IInterpreterInstall[] installs = installType.getInterpreterInstalls();
boolean isMac = Platform.OS_MACOSX.equals(Platform.getOS());
final String HOME_SUFFIX = "/Home"; //$NON-NLS-1$
for (int i = 0; i < installs.length; i++) {
String label = getFormattedLabel(installs[i].getName());
- LibraryLocation[] libLocations = installs[i]
- .getLibraryLocations();
+ LibraryLocation[] libLocations = installs[i].getLibraryLocations();
if (libLocations != null) {
processLibraryLocation(libLocations, label);
} else {
- String filePath = installs[i].getInstallLocation()
- .toOSString();
+ String filePath = installs[i].getInstallLocation().toOSString();
// on MacOS X install locations end in an additional
// "/Home" segment; remove it
if (isMac && filePath.endsWith(HOME_SUFFIX))
- filePath = filePath.substring(0, filePath.length()
- - HOME_SUFFIX.length() + 1);
+ filePath = filePath.substring(0, filePath.length() - HOME_SUFFIX.length() + 1);
locations.add(filePath);
labels.add(label);
}
@@ -1326,8 +1170,7 @@
}
}
- private void processLibraryLocation(LibraryLocation[] libLocations,
- String label) {
+ private void processLibraryLocation(LibraryLocation[] libLocations, String label) {
for (int l = 0; l < libLocations.length; l++) {
LibraryLocation location = libLocations[l];
fLib2Name.put(location.getLibraryPath().toString(), label);
@@ -1335,23 +1178,16 @@
}
private String getFormattedLabel(String name) {
- return NLS.bind(
- DLTKUIMessages.FilteredTypesSelectionDialog_library_name_format,
- name);
+ return NLS.bind(DLTKUIMessages.FilteredTypesSelectionDialog_library_name_format, name);
}
@Override
- public int compare(Object left, Object right) {
+ public int compare(TypeNameMatch leftInfo, TypeNameMatch rightInfo) {
- TypeNameMatch leftInfo = (TypeNameMatch) left;
- TypeNameMatch rightInfo = (TypeNameMatch) right;
-
- int result = compareName(leftInfo.getSimpleTypeName(),
- rightInfo.getSimpleTypeName());
+ int result = compareName(leftInfo.getSimpleTypeName(), rightInfo.getSimpleTypeName());
if (result != 0)
return result;
- result = compareTypeContainerName(leftInfo.getTypeContainerName(),
- rightInfo.getTypeContainerName());
+ result = compareTypeContainerName(leftInfo.getTypeContainerName(), rightInfo.getTypeContainerName());
if (result != 0)
return result;
@@ -1368,19 +1204,16 @@
int result = leftString.compareToIgnoreCase(rightString);
if (result != 0 || rightString.length() == 0) {
return result;
- } else if (Strings.isLowerCase(leftString.charAt(0))
- && !Strings.isLowerCase(rightString.charAt(0))) {
+ } else if (Strings.isLowerCase(leftString.charAt(0)) && !Strings.isLowerCase(rightString.charAt(0))) {
return +1;
- } else if (Strings.isLowerCase(rightString.charAt(0))
- && !Strings.isLowerCase(leftString.charAt(0))) {
+ } else if (Strings.isLowerCase(rightString.charAt(0)) && !Strings.isLowerCase(leftString.charAt(0))) {
return -1;
} else {
return leftString.compareTo(rightString);
}
}
- private int compareTypeContainerName(String leftString,
- String rightString) {
+ private int compareTypeContainerName(String leftString, String rightString) {
int leftLength = leftString.length();
int rightLength = rightString.length();
if (leftLength == 0 && rightLength > 0)
@@ -1392,10 +1225,8 @@
return compareName(leftString, rightString);
}
- private int compareContainerName(TypeNameMatch leftType,
- TypeNameMatch rightType) {
- return getContainerName(leftType)
- .compareTo(getContainerName(rightType));
+ private int compareContainerName(TypeNameMatch leftType, TypeNameMatch rightType) {
+ return getContainerName(leftType).compareTo(getContainerName(rightType));
}
private String getContainerName(TypeNameMatch type) {
@@ -1407,24 +1238,20 @@
return fVMNames[i];
}
}
- String lib = (String) fLib2Name.get(name);
+ String lib = fLib2Name.get(name);
if (lib != null)
return lib;
}
StringBuffer buf = new StringBuffer();
- ScriptElementLabels labels = getUIToolkit()
- .getScriptElementLabels();
- labels.getProjectFragmentLabel(root,
- ScriptElementLabels.ROOT_QUALIFIED
- | ScriptElementLabels.ROOT_VARIABLE,
+ ScriptElementLabels labels = getUIToolkit().getScriptElementLabels();
+ labels.getProjectFragmentLabel(root, ScriptElementLabels.ROOT_QUALIFIED | ScriptElementLabels.ROOT_VARIABLE,
buf);
return buf.toString();
}
private int getElementTypeCategory(TypeNameMatch type) {
try {
- if (type.getProjectFragment()
- .getKind() == IProjectFragment.K_SOURCE)
+ if (type.getProjectFragment().getKind() == IProjectFragment.K_SOURCE)
return 0;
} catch (ModelException e) {
DLTKUIPlugin.log(e);
@@ -1458,15 +1285,13 @@
@Override
public synchronized boolean remove(Object element) {
- OpenTypeHistory.getInstance(getUIToolkit())
- .remove((TypeNameMatch) element);
+ OpenTypeHistory.getInstance(getUIToolkit()).remove((TypeNameMatch) element);
return super.remove(element);
}
@Override
public void load(IMemento memento) {
- TypeNameMatch[] types = OpenTypeHistory.getInstance(getUIToolkit())
- .getTypeInfos();
+ TypeNameMatch[] types = OpenTypeHistory.getInstance(getUIToolkit()).getTypeInfos();
for (int i = 0; i < types.length; i++) {
TypeNameMatch type = types[i];
@@ -1480,15 +1305,13 @@
}
/**
- * Stores contents of the local history into persistent history
- * container.
+ * Stores contents of the local history into persistent history container.
*/
private synchronized void persistHistory() {
if (getReturnCode() == OK) {
Object[] items = getHistoryItems();
for (int i = 0; i < items.length; i++) {
- OpenTypeHistory.getInstance(getUIToolkit())
- .accessed((TypeNameMatch) items[i]);
+ OpenTypeHistory.getInstance(getUIToolkit()).accessed((TypeNameMatch) items[i]);
}
}
}