Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMickael Istria2019-12-12 07:57:05 +0000
committerMickael Istria2019-12-12 08:24:23 +0000
commit53921d098c5aaa810e52e3b3a2cd702e64fffdf5 (patch)
treef0d50440f2fab884d6eade0c5d03528e856fa8f3
parent90e69fcf2b64d43dade977d6b1de50ae70c9d2f4 (diff)
downloadeclipse.platform.text-53921d098c5aaa810e52e3b3a2cd702e64fffdf5.tar.gz
eclipse.platform.text-53921d098c5aaa810e52e3b3a2cd702e64fffdf5.tar.xz
eclipse.platform.text-53921d098c5aaa810e52e3b3a2cd702e64fffdf5.zip
Bug 558247 - HippieProposalProcessor NPE in non-UI Thread
Change-Id: I1a17e046ca2f75102d978e23ea2f67087eb5e0be Signed-off-by: Mickael Istria <mistria@redhat.com>
-rw-r--r--org.eclipse.ui.workbench.texteditor/META-INF/MANIFEST.MF2
-rw-r--r--org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/HippieProposalProcessor.java66
2 files changed, 41 insertions, 27 deletions
diff --git a/org.eclipse.ui.workbench.texteditor/META-INF/MANIFEST.MF b/org.eclipse.ui.workbench.texteditor/META-INF/MANIFEST.MF
index d0305f87d1e..32d965405e6 100644
--- a/org.eclipse.ui.workbench.texteditor/META-INF/MANIFEST.MF
+++ b/org.eclipse.ui.workbench.texteditor/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.ui.workbench.texteditor; singleton:=true
-Bundle-Version: 3.14.0.qualifier
+Bundle-Version: 3.14.100.qualifier
Bundle-Activator: org.eclipse.ui.internal.texteditor.TextEditorPlugin
Bundle-ActivationPolicy: lazy
Bundle-Vendor: %providerName
diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/HippieProposalProcessor.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/HippieProposalProcessor.java
index 3f9561015ae..46ef069e906 100644
--- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/HippieProposalProcessor.java
+++ b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/HippieProposalProcessor.java
@@ -15,8 +15,14 @@
package org.eclipse.ui.texteditor;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
import java.util.Iterator;
import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
@@ -40,9 +46,6 @@ import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
import org.eclipse.jface.text.contentassist.IContextInformation;
import org.eclipse.jface.text.contentassist.IContextInformationValidator;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IEditorReference;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.internal.texteditor.HippieCompletionEngine;
@@ -284,39 +287,50 @@ public final class HippieProposalProcessor implements IContentAssistProcessor {
}
/**
- * Create the array of suggestions. It scans all open text editors and prefers suggestions from
- * the currently open editor. It also adds the empty suggestion at the end.
+ * Create the array of suggestions. It scans for other documents or editors,
+ * and prefers suggestions from the currently open editor. It also adds the
+ * empty suggestion at the end.
*
- * @param viewer the viewer
- * @param offset the offset
- * @param prefix the prefix to search for
- * @return the list of all possible suggestions in the currently open editors
- * @throws BadLocationException if accessing the current document fails
+ * @param viewer
+ * the viewer
+ * @param offset
+ * the offset
+ * @param prefix
+ * the prefix to search for
+ * @return the list of all possible suggestions in the currently open
+ * editors
+ * @throws BadLocationException
+ * if accessing the current document fails
*/
private List<String> getSuggestions(ITextViewer viewer, int offset, String prefix) throws BadLocationException {
-
ArrayList<String> suggestions= createSuggestionsFromOpenDocument(viewer, offset, prefix);
IDocument currentDocument= viewer.getDocument();
-
- IWorkbenchWindow window= PlatformUI.getWorkbench().getActiveWorkbenchWindow();
- IEditorReference editorReferences[]= window.getActivePage().getEditorReferences();
-
- for (int i= 0; i < editorReferences.length; i++) {
- IEditorPart editor= editorReferences[i].getEditor(false); // don't create!
- if (editor instanceof ITextEditor) {
- ITextEditor textEditor= (ITextEditor) editor;
- IEditorInput input= textEditor.getEditorInput();
- IDocument doc= textEditor.getDocumentProvider().getDocument(input);
- if (!currentDocument.equals(doc))
- suggestions.addAll(fEngine.getCompletionsForward(doc, prefix, 0, false));
+ for (ITextEditor editor : findTextEditors()) {
+ IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput());
+ if (doc != null && !doc.equals(currentDocument)) {
+ suggestions.addAll(fEngine.getCompletionsForward(doc, prefix, 0, false));
}
}
// add the empty suggestion
suggestions.add(""); //$NON-NLS-1$
+ return fEngine.makeUnique(suggestions);
+ }
- List<String> uniqueSuggestions= fEngine.makeUnique(suggestions);
-
- return uniqueSuggestions;
+ private Collection<ITextEditor> findTextEditors() {
+ IWorkbenchWindow window= PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ Stream<IWorkbenchWindow> windows = null;
+ if (window != null) {
+ windows = Collections.singleton(window).stream();
+ } else {
+ windows = Arrays.stream(PlatformUI.getWorkbench().getWorkbenchWindows());
+ }
+ return windows.flatMap(aWindow -> Arrays.stream(aWindow.getPages())) //
+ .flatMap(workbenchPage -> Arrays.stream(workbenchPage.getEditorReferences())) //
+ .map(editorRef -> editorRef.getEditor(false)) //
+ .filter(Objects::nonNull) //
+ .filter(ITextEditor.class::isInstance) //
+ .map(ITextEditor.class::cast) //
+ .collect(Collectors.toSet());
}
@Override

Back to the top