Polish bug 251156: [content assist] Asynchronous code completion [with patch]
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/AsyncCompletionProposalPopup.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/AsyncCompletionProposalPopup.java
index f46384c..efb19eb 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/AsyncCompletionProposalPopup.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/AsyncCompletionProposalPopup.java
@@ -37,10 +37,11 @@
 import org.eclipse.jface.text.TextUtilities;
 
 /**
- * This is the controller for the completion proposal list, which is used
- * by the {@link AsyncContentAssistant}. It is aimed at orchestrating all operations
- * from {@link IContentAssistProcessor} asynchronously and to provide a good user
- * experience, including reporting and eye-candies.
+ * This class is used to present proposals asynchronously to the user. If additional information
+ * exists for a proposal, then selecting that proposal will result in the information being
+ * displayed in a secondary window.
+ * 
+ * @since 3.12
  */
 class AsyncCompletionProposalPopup extends CompletionProposalPopup {
 
@@ -81,7 +82,7 @@
 
 		@Override
 		public String getDisplayString() {
-			return NLS.bind(JFaceTextMessages.getString("CompletionProposalPopup.computing"), Integer.valueOf(fSize - fRemaining), Integer.valueOf(fSize)); //$NON-NLS-1$
+			return NLS.bind(JFaceTextMessages.getString("AsyncCompletionProposalPopup.computing"), Integer.valueOf(fSize - fRemaining), Integer.valueOf(fSize)); //$NON-NLS-1$
 		}
 
 		@Override
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/AsyncContentAssistSubjectControlAdapter.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/AsyncContentAssistSubjectControlAdapter.java
deleted file mode 100644
index d0d3cfd..0000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/AsyncContentAssistSubjectControlAdapter.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2016 Red Hat Inc. and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *     Mickael Istria (Red Hat Inc.) - [251156] async content assist
- *******************************************************************************/
-package org.eclipse.jface.text.contentassist;
-
-import org.eclipse.jface.text.ITextViewer;
-
-class AsyncContentAssistSubjectControlAdapter extends ContentAssistSubjectControlAdapter {
-
-	public AsyncContentAssistSubjectControlAdapter(ITextViewer viewer) {
-		super(viewer);
-	}
-	
-	@Override
-	CompletionProposalPopup createCompletionProposalPopup(ContentAssistant contentAssistant, AdditionalInfoController controller) {
-		if (fContentAssistSubjectControl != null)
-			return new AsyncCompletionProposalPopup(contentAssistant, fContentAssistSubjectControl, controller);
-		return new AsyncCompletionProposalPopup(contentAssistant, fViewer, controller);
-	}
-
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/AsyncContentAssistant.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/AsyncContentAssistant.java
deleted file mode 100644
index 22aa3ca..0000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/AsyncContentAssistant.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2016 Red Hat Inc. and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *     Mickael Istria (Red Hat Inc.) - [251156] async content assist
- *******************************************************************************/
-package org.eclipse.jface.text.contentassist;
-
-import org.eclipse.jface.text.ITextViewer;
-
-/**
- * A content assistant allowing multiple {@link IContentAssistProcessor}s and invoking their methods
- * asynchronously whenever possible.
- * @since 3.12
- */
-public class AsyncContentAssistant extends ContentAssistant {
-
-	@Override
-	public void addContentAssistProcessor(IContentAssistProcessor processor, String contentType) {
-		super.addContentAssistProcessor(processor, contentType);
-	}
-
-	@Override
-	public void install(ITextViewer textViewer) {
-		fViewer= textViewer;
-		fContentAssistSubjectControlAdapter= new AsyncContentAssistSubjectControlAdapter(fViewer);
-		install();
-	}
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistSubjectControlAdapter.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistSubjectControlAdapter.java
index 6a8dd15..8d648d9 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistSubjectControlAdapter.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistSubjectControlAdapter.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2016 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -261,17 +261,24 @@
 	}
 
 	/**
-	* Creates and returns a completion proposal popup for the given content assistant.
-	*
-	* @param contentAssistant the content assistant
-	* @param controller the additional info controller, or <code>null</code>
-	* @return the completion proposal popup
-	*/
-	CompletionProposalPopup createCompletionProposalPopup(ContentAssistant contentAssistant, AdditionalInfoController controller) {
-		if (fContentAssistSubjectControl != null)
-			return new CompletionProposalPopup(contentAssistant, fContentAssistSubjectControl, controller);
-		return new CompletionProposalPopup(contentAssistant, fViewer, controller);
-
+	 * Creates and returns a completion proposal popup for the given content assistant.
+	 *
+	 * @param contentAssistant the content assistant
+	 * @param controller the additional info controller, or <code>null</code>
+	 * @param asynchronous <true> if this content assistant should present the proposals
+	 *            asynchronously, <code>false</code> otherwise
+	 * @return the completion proposal popup
+	 */
+	CompletionProposalPopup createCompletionProposalPopup(ContentAssistant contentAssistant, AdditionalInfoController controller, boolean asynchronous) {
+		if (asynchronous) {
+			if (fContentAssistSubjectControl != null)
+				return new AsyncCompletionProposalPopup(contentAssistant, fContentAssistSubjectControl, controller);
+			return new AsyncCompletionProposalPopup(contentAssistant, fViewer, controller);
+		} else {
+			if (fContentAssistSubjectControl != null)
+				return new CompletionProposalPopup(contentAssistant, fContentAssistSubjectControl, controller);
+			return new CompletionProposalPopup(contentAssistant, fViewer, controller);
+		}
 	}
 
 	/**
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistant.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistant.java
index 3697b01..84eee07 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistant.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistant.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2016 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -81,8 +81,11 @@
 
 
 /**
- * The standard implementation of the <code>IContentAssistant</code> interface. Usually, clients
+ * The standard implementation of the {@link IContentAssistant} interface. Usually, clients
  * instantiate this class and configure it before using it.
+ * 
+ * Since 3.12, it can compute and display the proposals asynchronously when invoking
+ * {@link #ContentAssistant(boolean)} with <code>true</code>.
  */
 public class ContentAssistant implements IContentAssistant, IContentAssistantExtension, IContentAssistantExtension2, IContentAssistantExtension3, IContentAssistantExtension4, IWidgetTokenKeeper, IWidgetTokenKeeperExtension {
 
@@ -926,7 +929,7 @@
 	private Color fProposalSelectorBackground;
 	private Color fProposalSelectorForeground;
 
-	ITextViewer fViewer;
+	private ITextViewer fViewer;
 	private String fLastErrorMessage;
 
 	private Closer fCloser;
@@ -966,7 +969,7 @@
 	 *
 	 * @since 3.0
 	 */
-	ContentAssistSubjectControlAdapter fContentAssistSubjectControlAdapter;
+	private ContentAssistSubjectControlAdapter fContentAssistSubjectControlAdapter;
 	/**
 	 * The dialog settings for the control's bounds.
 	 *
@@ -1045,6 +1048,13 @@
 	private ICompletionProposalSorter fSorter;
 
 	/**
+	 * Tells whether this content assistant allows to run asynchronous
+	 * 
+	 * @since 3.12
+	 */
+	private boolean fAsynchronous;
+
+	/**
 	 * Creates a new content assistant. The content assistant is not automatically activated,
 	 * overlays the completion proposals with context information list if necessary, and shows the
 	 * context information above the location at which it was activated. If auto activation will be
@@ -1052,7 +1062,23 @@
 	 * milliseconds delay. It uses the default partitioning.
 	 */
 	public ContentAssistant() {
+		this(false);
+	}
+
+	/**
+	 * Creates a new content assistant. The content assistant is not automatically activated,
+	 * overlays the completion proposals with context information list if necessary, and shows the
+	 * context information above the location at which it was activated. If auto activation will be
+	 * enabled, without further configuration steps, this content assistant is activated after a 500
+	 * milliseconds delay. It uses the default partitioning.
+	 * 
+	 * @param asynchronous <true> if this content assistant should present the proposals
+	 *            asynchronously, <code>false</code> otherwise
+	 * @since 3.12
+	 */
+	public ContentAssistant(boolean asynchronous) {
 		fPartitioning= IDocumentExtension3.DEFAULT_PARTITIONING;
+		fAsynchronous= asynchronous;
 	}
 
 	/**
@@ -1101,7 +1127,7 @@
 	 * @param contentType Document token content-type it applies to
 	 * @since 3.12
 	 */
-	protected void addContentAssistProcessor(IContentAssistProcessor processor, String contentType) {
+	public void addContentAssistProcessor(IContentAssistProcessor processor, String contentType) {
 		Assert.isNotNull(contentType);
 
 		if (fProcessors == null)
@@ -1134,11 +1160,15 @@
 	}
 
 	/**
-	 * @param contentType Document token content-type it applies to
-	 * @return the available content-assist processors for provide token content-type.
+	 * Returns the content assist processors to be used for the given content type.
+	 *
+	 * @param contentType the type of the content for which this content assistant is to be
+	 *            requested
+	 * @return the content assist processors or <code>null</code> if none exists for the specified
+	 *         content type
 	 * @since 3.12
 	 */
-	protected Set<IContentAssistProcessor> getContentAssistProcessors(String contentType) {
+	Set<IContentAssistProcessor> getContentAssistProcessors(String contentType) {
 		if (fProcessors == null)
 			return null;
 
@@ -1501,7 +1531,7 @@
 			controller= new AdditionalInfoController(fInformationControlCreator, OpenStrategy.getPostSelectionDelay());
 
 		fContextInfoPopup= fContentAssistSubjectControlAdapter.createContextInfoPopup(this);
-		fProposalPopup= fContentAssistSubjectControlAdapter.createCompletionProposalPopup(this, controller);
+		fProposalPopup= fContentAssistSubjectControlAdapter.createCompletionProposalPopup(this, controller, fAsynchronous);
 		fProposalPopup.setSorter(fSorter);
 
 		registerHandler(SELECT_NEXT_PROPOSAL_COMMAND_ID, fProposalPopup.createProposalSelectionHandler(CompletionProposalPopup.ProposalSelectionHandler.SELECT_NEXT));
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/JFaceTextMessages.properties b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/JFaceTextMessages.properties
index 73584bd..543ab27 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/JFaceTextMessages.properties
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/JFaceTextMessages.properties
@@ -1,5 +1,5 @@
 ###############################################################################
-# Copyright (c) 2000, 2014 IBM Corporation and others.
+# Copyright (c) 2000, 2017 IBM Corporation and others.
 # All rights reserved. This program and the accompanying materials
 # are made available under the terms of the Eclipse Public License v1.0
 # which accompanies this distribution, and is available at
@@ -19,6 +19,6 @@
 ContentAssistant.error_computing_completion=Error computing completion proposals.
 ContentAssistant.error_computing_context=Error computing context information.
 CompletionProposalPopup.no_proposals=no proposals
-CompletionProposalPopup.computing=Computing ({0}/{1})...
 CompletionProposalPopup.error_retrieving_proposal=Error retrieving proposal text
 CompletionProposalPopup.unexpected_error=Unexpected error while retrieving text for a content assistance proposal.
+AsyncCompletionProposalPopup.computing=Computing ({0}/{1}) ...
diff --git a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/ExtensionBasedTextViewerConfiguration.java b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/ExtensionBasedTextViewerConfiguration.java
index 61b3c08..0b5aa83 100644
--- a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/ExtensionBasedTextViewerConfiguration.java
+++ b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/ExtensionBasedTextViewerConfiguration.java
@@ -17,27 +17,32 @@
 import java.util.Queue;
 import java.util.Set;
 
+import org.eclipse.swt.widgets.Shell;
+
 import org.eclipse.core.runtime.Platform;
 import org.eclipse.core.runtime.content.IContentType;
+
 import org.eclipse.jface.preference.IPreferenceStore;
+
 import org.eclipse.jface.text.AbstractReusableInformationControlCreator;
 import org.eclipse.jface.text.DefaultInformationControl;
 import org.eclipse.jface.text.IDocument;
 import org.eclipse.jface.text.IDocumentPartitioningListener;
 import org.eclipse.jface.text.IInformationControl;
 import org.eclipse.jface.text.ITextHover;
-import org.eclipse.jface.text.contentassist.AsyncContentAssistant;
 import org.eclipse.jface.text.contentassist.ContentAssistant;
 import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
 import org.eclipse.jface.text.contentassist.IContentAssistant;
 import org.eclipse.jface.text.presentation.IPresentationReconciler;
 import org.eclipse.jface.text.source.ISourceViewer;
-import org.eclipse.swt.widgets.Shell;
+
 import org.eclipse.ui.IEditorPart;
 import org.eclipse.ui.IPropertyListener;
-import org.eclipse.ui.editors.text.TextSourceViewerConfiguration;
+
 import org.eclipse.ui.texteditor.ITextEditor;
 
+import org.eclipse.ui.editors.text.TextSourceViewerConfiguration;
+
 /**
  * The configuration of the {@link ExtensionBasedTextEditor}. It registers the proxy composite
  * for hover, completion, syntax highlighting, and then those proxy take care of resolving to
@@ -50,7 +55,8 @@
 	private ITextEditor editor;
 	private Set<IContentType> contentTypes;
 	private IDocument document;
-	private AsyncContentAssistant contentAssistant;
+
+	private ContentAssistant contentAssistant;
 	private List<IContentAssistProcessor> processors;
 
 	/**
@@ -96,7 +102,7 @@
 	@Override
 	public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
 		ContentAssistProcessorRegistry registry= GenericEditorPlugin.getDefault().getContentAssistProcessorRegistry();
-		contentAssistant = new AsyncContentAssistant();
+		contentAssistant= new ContentAssistant(true);
 		contentAssistant.setContextInformationPopupOrientation(ContentAssistant.CONTEXT_INFO_BELOW);
 		contentAssistant.setProposalPopupOrientation(ContentAssistant.PROPOSAL_REMOVE);
 		contentAssistant.enableColoredLabels(true);