Polished fix for bug 350991: [content assist][api] Allow to re-sort
proposals
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/CompletionProposalPopup.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/CompletionProposalPopup.java
index f6fb7de..b748eab 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/CompletionProposalPopup.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/CompletionProposalPopup.java
@@ -433,8 +433,8 @@
 	private boolean fIsColoredLabelsSupportEnabled= false;
 
 	/**
-	 * The most recent sorter. Used when sorting proposals after filtering is requested by a completion engine. The sorter may
-	 * be <code>null</code>.
+	 * The sorter to be used for sorting the proposals or <code>null</code> if no sorting is
+	 * requested.
 	 * 
 	 * @since 3.8
 	 */
@@ -1118,7 +1118,9 @@
 				proposals= new ICompletionProposal[] { fEmptyProposal };
 			}
 
-			sortProposals(proposals);
+			if (fSorter != null)
+				sortProposals(proposals);
+
 			fFilteredProposals= proposals;
 			final int newLen= proposals.length;
 			if (USE_VIRTUAL) {
@@ -1845,29 +1847,29 @@
 	}
 
 	/**
-	 * Sets the sorter to use when resorting is required by one of the completion engines.
+	 * Sets the proposal sorter.
 	 * 
-	 * @param sorter the new sorter to be used, or <code>null</code> if no sorter is needed
+	 * @param sorter the sorter to be used, or <code>null</code> if no sorting is requested
 	 * @since 3.8
+	 * @see ContentAssistant#setSorter(ICompletionProposalSorter)
 	 */
 	public void setSorter(ICompletionProposalSorter sorter) {
 		fSorter= sorter;
 	}
 
 	/**
-	 * Sorts the given proposal array if a sorter is configured. Does nothing otherwise.
+	 * Sorts the given proposal array.
 	 * 
 	 * @param proposals the new proposals to display in the popup window
+	 * @throws NullPointerException if no sorter has been set
 	 * @since 3.8
 	 */
 	private void sortProposals(final ICompletionProposal[] proposals) {
-		if (fSorter != null) {
-			Arrays.sort(proposals, new Comparator() {
-				public int compare(Object o1, Object o2) {
-					return fSorter.compare((ICompletionProposal)o1,
-							(ICompletionProposal)o2);
-				}
-			});
-		}
+		Arrays.sort(proposals, new Comparator() {
+			public int compare(Object o1, Object o2) {
+				return fSorter.compare((ICompletionProposal)o1,
+						(ICompletionProposal)o2);
+			}
+		});
 	}
 }
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 20d78b4..56a03cd 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
@@ -987,7 +987,8 @@
 	private boolean fIsColoredLabelsSupportEnabled= false;
 
 	/**
-	 * The sorter used to sort completion proposals when filtering was triggered.
+	 * The sorter to be used for sorting the proposals or <code>null</code> if no sorting is
+	 * requested.
 	 * 
 	 * @since 3.8
 	 */
@@ -2471,12 +2472,10 @@
 	}
 
 	/**
-	 * Sets the sorter used to sort proposal completions after filtering is triggered.
+	 * Sets the proposal sorter.
 	 * 
-	 * @param sorter the sorter used for reordering the proposals, or <code>null</code> if no
-	 *            proposal reordering is needed
+	 * @param sorter the sorter to be used, or <code>null</code> if no sorting is requested
 	 * @since 3.8
-	 * @see CompletionProposalPopup#setSorter(ICompletionProposalSorter)
 	 */
 	public void setSorter(ICompletionProposalSorter sorter) {
 		fSorter= sorter;
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ICompletionProposalSorter.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ICompletionProposalSorter.java
index 90b08da..3ca673b 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ICompletionProposalSorter.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ICompletionProposalSorter.java
@@ -30,8 +30,7 @@
 	 * @param p1 the first proposal to be compared
 	 * @param p2 the second proposal to be compared
 	 * @return a negative integer, zero, or a positive integer as the first argument is less than,
-	 *         equal to, or greater than the second.
-	 * 
+	 *         equal to, or greater than the second
 	 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
 	 */
 	public int compare(ICompletionProposal p1, ICompletionProposal p2);