diff options
| author | Dani Megert | 2012-03-14 10:13:52 +0000 |
|---|---|---|
| committer | Dani Megert | 2012-03-14 10:13:52 +0000 |
| commit | b194caeeec9e921dd0da73661bc8cc46cc1d629c (patch) | |
| tree | cbcaeb501c5aaed7b924864e8d92fb6484530b74 | |
| parent | 298a230997ac9dac0777fd04bd109e741be69962 (diff) | |
| download | eclipse.jdt.ui-b194caeeec9e921dd0da73661bc8cc46cc1d629c.tar.gz eclipse.jdt.ui-b194caeeec9e921dd0da73661bc8cc46cc1d629c.tar.xz eclipse.jdt.ui-b194caeeec9e921dd0da73661bc8cc46cc1d629c.zip | |
Polished fix for bug 350991: [content assist][api] Allow to re-sortv20120314-1013
proposals
3 files changed, 36 insertions, 29 deletions
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/ContentAssistProcessor.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/ContentAssistProcessor.java index 1441339012..5737e48b30 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/ContentAssistProcessor.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/ContentAssistProcessor.java @@ -66,7 +66,6 @@ import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; import org.eclipse.jdt.internal.corext.util.Messages; import org.eclipse.jdt.ui.PreferenceConstants; -import org.eclipse.jdt.ui.text.java.AbstractProposalSorter; import org.eclipse.jdt.ui.text.java.ContentAssistInvocationContext; import org.eclipse.jdt.internal.ui.JavaPlugin; @@ -219,6 +218,15 @@ public class ContentAssistProcessor implements IContentAssistProcessor { */ private CompletionProposalComputerRegistry fComputerRegistry; + /** + * Flag indicating whether any completion engine associated with this processor requests + * resorting of its proposals after filtering is triggered. Filtering is, e.g., triggered when a + * user continues typing with an open completion window. + * + * @since 3.8 + */ + private boolean fNeedsSortingAfterFiltering; + public ContentAssistProcessor(ContentAssistant assistant, String partition) { Assert.isNotNull(partition); @@ -249,11 +257,14 @@ public class ContentAssistProcessor implements IContentAssistProcessor { long collect= DEBUG ? System.currentTimeMillis() : 0; monitor.subTask(JavaTextMessages.ContentAssistProcessor_sorting_proposals); - List<ICompletionProposal> filtered= filterAndSortProposals(proposals, monitor, context); - fNumberOfComputedResults= filtered.size(); + if (fNeedsSortingAfterFiltering) + setContentAssistSorter(); + else + proposals= sortProposals(proposals, monitor, context); + fNumberOfComputedResults= proposals.size(); long filter= DEBUG ? System.currentTimeMillis() : 0; - ICompletionProposal[] result= filtered.toArray(new ICompletionProposal[filtered.size()]); + ICompletionProposal[] result= proposals.toArray(new ICompletionProposal[proposals.size()]); monitor.done(); if (DEBUG) { @@ -292,7 +303,9 @@ public class ContentAssistProcessor implements IContentAssistProcessor { if (fErrorMessage == null) fErrorMessage= cat.getErrorMessage(); } - installProposalSorter(needsSortingAfterFiltering); + if (fNeedsSortingAfterFiltering && !needsSortingAfterFiltering) + fAssistant.setSorter(null); + fNeedsSortingAfterFiltering= needsSortingAfterFiltering; return proposals; } @@ -307,7 +320,7 @@ public class ContentAssistProcessor implements IContentAssistProcessor { * @return the list of filtered and sorted proposals, ready for * display (element type: {@link ICompletionProposal}) */ - protected List<ICompletionProposal> filterAndSortProposals(List<ICompletionProposal> proposals, IProgressMonitor monitor, ContentAssistInvocationContext context) { + protected List<ICompletionProposal> sortProposals(List<ICompletionProposal> proposals, IProgressMonitor monitor, ContentAssistInvocationContext context) { return proposals; } @@ -638,25 +651,15 @@ public class ContentAssistProcessor implements IContentAssistProcessor { } /** - * Installs the proposal sorter to be used by the content assistant for resorting proposals - * after filtering. Sets the sorter to the system's default sorter if - * <code>needsSortingAfterFiltering</code> is <code>true</code>, <code>null</code> otherwise. + * Sets the current proposal sorter into the content assistant. * - * @param needsSortingAfterFiltering the flag indicating whether a sorter should be passed to - * the content assistant * @since 3.8 * @see ProposalSorterRegistry#getCurrentSorter() the sorter used if <code>true</code> */ - private void installProposalSorter(boolean needsSortingAfterFiltering) { - if (!needsSortingAfterFiltering) { - fAssistant.setSorter(null); - return; - } - - AbstractProposalSorter sorter= null; + private void setContentAssistSorter() { ProposalSorterHandle currentSorter= ProposalSorterRegistry.getDefault().getCurrentSorter(); try { - sorter= currentSorter.getSorter(); + fAssistant.setSorter(currentSorter.getSorter()); } catch (InvalidRegistryObjectException x) { JavaPlugin.log(currentSorter.createExceptionStatus(x)); } catch (CoreException x) { @@ -664,7 +667,6 @@ public class ContentAssistProcessor implements IContentAssistProcessor { } catch (RuntimeException x) { JavaPlugin.log(currentSorter.createExceptionStatus(x)); } - fAssistant.setSorter(sorter); } } diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/JavaCompletionProcessor.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/JavaCompletionProcessor.java index f08c01bb06..73b43f5eb3 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/JavaCompletionProcessor.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/JavaCompletionProcessor.java @@ -113,7 +113,7 @@ public class JavaCompletionProcessor extends ContentAssistProcessor { * @see org.eclipse.jdt.internal.ui.text.java.ContentAssistProcessor#filterAndSort(java.util.List, org.eclipse.core.runtime.IProgressMonitor) */ @Override - protected List<ICompletionProposal> filterAndSortProposals(List<ICompletionProposal> proposals, IProgressMonitor monitor, ContentAssistInvocationContext context) { + protected List<ICompletionProposal> sortProposals(List<ICompletionProposal> proposals, IProgressMonitor monitor, ContentAssistInvocationContext context) { ProposalSorterRegistry.getDefault().getCurrentSorter().sortProposals(context, proposals); return proposals; } diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/text/java/AbstractProposalSorter.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/text/java/AbstractProposalSorter.java index ee5a827a81..5052d85f3f 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/text/java/AbstractProposalSorter.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/text/java/AbstractProposalSorter.java @@ -42,13 +42,15 @@ public abstract class AbstractProposalSorter implements Comparator<ICompletionPr } /** - * Called once before initial sorting starts the first time. Note that if a completion engine - * needs subsequent sorting of its proposals (e.g., after some proposals get filtered due to - * changes in the completion prefix), this method is <i>not</i> called again. + * Called once before initial sorting starts the first time. + * <p> + * <strong>Note:</strong> As of 3.8 a completion proposal computer can request that proposals + * are resorted. If such a computer is active, then this method will not be called. + * </p> * <p> * Clients may override, the default implementation does nothing. * </p> - * + * * @param context the context of the content assist invocation */ public void beginSorting(ContentAssistInvocationContext context) { @@ -56,19 +58,22 @@ public abstract class AbstractProposalSorter implements Comparator<ICompletionPr /** * The orderings imposed by an implementation need not be consistent with equals. - * + * * @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 abstract int compare(ICompletionProposal p1, ICompletionProposal p2); /** - * Called once after the initial sorting finished. Note that even if a completion engine causes - * a subsequent sorting of its proposals, this method is <i>not</i> called again. + * Called once after the initial sorting finished. + * <p> + * <strong>Note:</strong> As of 3.8 a completion proposal computer can request that proposals + * are resorted. If such a computer is active, then this method will not be called. + * </p> * <p> * Clients may override, the default implementation does nothing. * </p> |
