Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMickael Istria2019-10-22 10:05:38 +0000
committerMickael Istria2019-10-22 13:52:56 +0000
commita357b363a671531459b1c16b99e357aff3d419e7 (patch)
treeefe994bca50febf52d87922ad22fbf7e2f43d31e
parent1d9ab0be7397cec90b590edd547136753efa513f (diff)
downloadeclipse.platform.text-a357b363a671531459b1c16b99e357aff3d419e7.tar.gz
eclipse.platform.text-a357b363a671531459b1c16b99e357aff3d419e7.tar.xz
eclipse.platform.text-a357b363a671531459b1c16b99e357aff3d419e7.zip
Bug 552326 - NPE in non-UI ThreadI20191023-1810I20191022-1800
Change-Id: Ia5a0262b05e723040e10a5b3d9251bac7a279894 Signed-off-by: Mickael Istria <mistria@redhat.com>
-rw-r--r--org.eclipse.text.quicksearch/src/org/eclipse/text/quicksearch/internal/ui/QuickSearchContext.java29
-rw-r--r--org.eclipse.text.quicksearch/src/org/eclipse/text/quicksearch/internal/ui/QuickSearchQuickAccessComputer.java7
2 files changed, 24 insertions, 12 deletions
diff --git a/org.eclipse.text.quicksearch/src/org/eclipse/text/quicksearch/internal/ui/QuickSearchContext.java b/org.eclipse.text.quicksearch/src/org/eclipse/text/quicksearch/internal/ui/QuickSearchContext.java
index 197342eee..4332065e1 100644
--- a/org.eclipse.text.quicksearch/src/org/eclipse/text/quicksearch/internal/ui/QuickSearchContext.java
+++ b/org.eclipse.text.quicksearch/src/org/eclipse/text/quicksearch/internal/ui/QuickSearchContext.java
@@ -29,6 +29,7 @@ import org.eclipse.text.quicksearch.internal.core.priority.PriorityFunction;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorReference;
+import org.eclipse.ui.ISelectionService;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
@@ -95,6 +96,9 @@ public class QuickSearchContext {
}
private Collection<IFile> getOpenFiles() {
+ if (window == null) {
+ return Collections.emptyList();
+ }
try {
IWorkbenchPage page = window.getActivePage();
if (page!=null) {
@@ -105,7 +109,7 @@ public class QuickSearchContext {
try {
IEditorInput input = editor.getEditorInput();
if (input!=null) {
- IFile file = (IFile) input.getAdapter(IFile.class);
+ IFile file = input.getAdapter(IFile.class);
if (file != null) {
files.add(file);
}
@@ -133,13 +137,16 @@ public class QuickSearchContext {
* @return IFile or null if there is no current editor or the editor isn't associated to a file.
*/
private IFile getActiveFile() {
+ if (window == null) {
+ return null;
+ }
IWorkbenchPage page = window.getActivePage();
if (page!=null) {
IEditorPart editor = page.getActiveEditor();
if (editor!=null) {
IEditorInput input = editor.getEditorInput();
if (input!=null) {
- return (IFile) input.getAdapter(IFile.class);
+ return input.getAdapter(IFile.class);
}
}
}
@@ -151,18 +158,22 @@ public class QuickSearchContext {
* a Structured selection (e.g. in navigator or project/package explorer)
*/
private Collection<IResource> getSelectedResources() {
- ISelection _s = window.getSelectionService().getSelection();
- if (_s!=null && _s instanceof IStructuredSelection) {
- IStructuredSelection s = (IStructuredSelection) _s;
- if (s!=null && !s.isEmpty()) {
- Object[] elements = s.toArray();
- List<IResource> resources = new ArrayList<IResource>(elements.length);
+ if (window == null) {
+ return Collections.emptyList();
+ }
+ ISelectionService selectionService = window.getSelectionService();
+ ISelection selection = selectionService.getSelection();
+ if (selection instanceof IStructuredSelection) {
+ IStructuredSelection structuredSelection = (IStructuredSelection) selection;
+ if (!structuredSelection.isEmpty()) {
+ Object[] elements = structuredSelection.toArray();
+ List<IResource> resources = new ArrayList<>(elements.length);
for (Object e : elements) {
if (e instanceof IResource) {
resources.add((IResource) e);
} else if (e instanceof IAdaptable) {
IAdaptable ae = (IAdaptable) e;
- IResource r = (IResource) ae.getAdapter(IResource.class);
+ IResource r = ae.getAdapter(IResource.class);
if (r!=null) {
resources.add(r);
}
diff --git a/org.eclipse.text.quicksearch/src/org/eclipse/text/quicksearch/internal/ui/QuickSearchQuickAccessComputer.java b/org.eclipse.text.quicksearch/src/org/eclipse/text/quicksearch/internal/ui/QuickSearchQuickAccessComputer.java
index 96ca299a9..d2c190f85 100644
--- a/org.eclipse.text.quicksearch/src/org/eclipse/text/quicksearch/internal/ui/QuickSearchQuickAccessComputer.java
+++ b/org.eclipse.text.quicksearch/src/org/eclipse/text/quicksearch/internal/ui/QuickSearchQuickAccessComputer.java
@@ -21,6 +21,7 @@ import org.eclipse.text.quicksearch.internal.core.LineItem;
import org.eclipse.text.quicksearch.internal.core.QuickTextQuery;
import org.eclipse.text.quicksearch.internal.core.QuickTextSearchRequestor;
import org.eclipse.text.quicksearch.internal.core.QuickTextSearcher;
+import org.eclipse.text.quicksearch.internal.core.priority.PriorityFunction;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
@@ -33,15 +34,15 @@ import org.eclipse.ui.texteditor.ITextEditor;
public class QuickSearchQuickAccessComputer extends QuickTextSearchRequestor implements IQuickAccessComputer, IQuickAccessComputerExtension {
private static final int MAX_ENTRIES = 20;
- private QuickSearchContext context;
+ private PriorityFunction priorities;
public QuickSearchQuickAccessComputer() {
- context = new QuickSearchContext(PlatformUI.getWorkbench().getActiveWorkbenchWindow());
+ priorities = new QuickSearchContext(PlatformUI.getWorkbench().getActiveWorkbenchWindow()).createPriorityFun();
}
@Override public QuickAccessElement[] computeElements(String query, IProgressMonitor monitor) {
List<LineItem> matches = Collections.synchronizedList(new ArrayList<>());
- QuickTextSearcher searcher = new QuickTextSearcher(new QuickTextQuery("", false), context.createPriorityFun(), 100, new QuickTextSearchRequestor() { //$NON-NLS-1$
+ QuickTextSearcher searcher = new QuickTextSearcher(new QuickTextQuery("", false), priorities, 100, new QuickTextSearchRequestor() { //$NON-NLS-1$
@Override public void add(LineItem match) {
matches.add(match);
}

Back to the top