Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 212506 Details for
Bug 350991
[content assist][api] Allow to re-sort proposals
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
patch for jdt.ui to enable proposal resorting after filtering
eclipse.jdt.ui.patch (text/plain), 15.75 KB, created by
Marcel Bruch
on 2012-03-12 17:25:29 EDT
(
hide
)
Description:
patch for jdt.ui to enable proposal resorting after filtering
Filename:
MIME Type:
Creator:
Marcel Bruch
Created:
2012-03-12 17:25:29 EDT
Size:
15.75 KB
patch
obsolete
>diff --git a/org.eclipse.jdt.ui/schema/javaCompletionProposalComputer.exsd b/org.eclipse.jdt.ui/schema/javaCompletionProposalComputer.exsd >index c25fcf9..0197988 100644 >--- a/org.eclipse.jdt.ui/schema/javaCompletionProposalComputer.exsd >+++ b/org.eclipse.jdt.ui/schema/javaCompletionProposalComputer.exsd >@@ -1,6 +1,6 @@ > <?xml version='1.0' encoding='UTF-8'?> > <!-- Schema file written by PDE --> >-<schema targetNamespace="org.eclipse.jdt.ui"> >+<schema targetNamespace="org.eclipse.jdt.ui" xmlns="http://www.w3.org/2001/XMLSchema"> > <annotation> > <appInfo> > <meta.schema plugin="org.eclipse.jdt.ui" id="javaCompletionProposalComputer" name="Java Completion Proposal Computer"/> >@@ -95,6 +95,15 @@ > </appInfo> > </annotation> > </attribute> >+ <attribute name="needsSortingAfterFiltering" type="boolean" use="default" value="false"> >+ <annotation> >+ <documentation> >+ if the attribute is set to "true" it forces the content assist processor to resort the list of proposals every time a new token is entered or removed to the completion prefix. >+ >+@since 3.8 >+ </documentation> >+ </annotation> >+ </attribute> > </complexType> > </element> > >diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/CompletionProposalCategory.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/CompletionProposalCategory.java >index ddccc31..0cf61fd 100644 >--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/CompletionProposalCategory.java >+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/CompletionProposalCategory.java >@@ -8,6 +8,7 @@ > * Contributors: > * IBM Corporation - initial API and implementation > * Paul Fullbright <paul.fullbright@oracle.com> - content assist category enablement - http://bugs.eclipse.org/345213 >+ * Marcel Bruch <bruch@cs.tu-darmstadt.de> - [content assist] Allow to re-sort proposals - https://bugs.eclipse.org/bugs/show_bug.cgi?id=350991 > *******************************************************************************/ > package org.eclipse.jdt.internal.ui.text.java; > >@@ -75,6 +76,15 @@ > > private int fSortOrder= 0xffff - 1; > private String fLastError= null; >+ >+ /** >+ * Flag indicating whether any completion engine associated with this category 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; > > CompletionProposalCategory(IConfigurationElement element, CompletionProposalComputerRegistry registry) throws CoreException { > fElement= element; >@@ -365,8 +375,10 @@ > List<CompletionProposalComputerDescriptor> descriptors= new ArrayList<CompletionProposalComputerDescriptor>(fRegistry.getProposalComputerDescriptors()); > for (Iterator<CompletionProposalComputerDescriptor> it= descriptors.iterator(); it.hasNext();) { > CompletionProposalComputerDescriptor desc= it.next(); >- if (desc.getCategory() == this) >+ if (desc.getCategory() == this){ > desc.sessionStarted(); >+ fNeedsSortingAfterFiltering= fNeedsSortingAfterFiltering || desc.isSortingAfterFilteringNeeded(); >+ } > if (fLastError == null) > fLastError= desc.getErrorMessage(); > } >@@ -376,6 +388,7 @@ > * Notifies the computers in this category of a proposal computation session end. > */ > public void sessionEnded() { >+ fNeedsSortingAfterFiltering= false; > List<CompletionProposalComputerDescriptor> descriptors= new ArrayList<CompletionProposalComputerDescriptor>(fRegistry.getProposalComputerDescriptors()); > for (Iterator<CompletionProposalComputerDescriptor> it= descriptors.iterator(); it.hasNext();) { > CompletionProposalComputerDescriptor desc= it.next(); >@@ -386,4 +399,14 @@ > } > } > >+ /** >+ * Returns whether any completion proposal computer associated with this category requires >+ * proposals to be sorted again after filtering. >+ * >+ * @return <code>true</code> if any completion proposal computer in this category requires >+ * proposals to be sorted. >+ */ >+ public boolean isSortingAfterFilteringNeeded() { >+ return fNeedsSortingAfterFiltering; >+ } > } >diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/CompletionProposalComputerDescriptor.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/CompletionProposalComputerDescriptor.java >index c9dfe2f..fc12607 100644 >--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/CompletionProposalComputerDescriptor.java >+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/CompletionProposalComputerDescriptor.java >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2005, 2011 IBM Corporation and others. >+# * Copyright (c) 2005, 2012 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 >@@ -7,6 +7,7 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >+ * Marcel Bruch <bruch@cs.tu-darmstadt.de> - [content assist] Allow to re-sort proposals - https://bugs.eclipse.org/bugs/show_bug.cgi?id=350991 > *******************************************************************************/ > package org.eclipse.jdt.internal.ui.text.java; > >@@ -61,6 +62,8 @@ > private static final String CLASS= "class"; //$NON-NLS-1$ > /** The extension schema name of the activate attribute. */ > private static final String ACTIVATE= "activate"; //$NON-NLS-1$ >+ /** The extension schema name of the needsSortingAfterFiltering attribute. */ >+ private static final String NEEDS_SORTING_AFTER_FILTERING= "needsSortingAfterFiltering"; //$NON-NLS-1$ > /** The extension schema name of the partition child elements. */ > private static final String PARTITION= "partition"; //$NON-NLS-1$ > /** Set of Java partition types. */ >@@ -131,6 +134,15 @@ > * @since 3.4 > */ > boolean fTriedLoadingComputer= false; >+ >+ /** >+ * Tells whether this proposal engine provides dynamic content that needs to be sorted after its >+ * proposal have been filtered. Filtering happens, e.g., when a user continues typing with an >+ * open completion window. >+ * >+ * @since 3.8 >+ */ >+ private boolean fNeedsSortingAfterFiltering; > > > /** >@@ -173,6 +185,9 @@ > > String activateAttribute= element.getAttribute(ACTIVATE); > fActivate= Boolean.valueOf(activateAttribute).booleanValue(); >+ >+ String needsSortingAfterFilteringAttribute= element.getAttribute(NEEDS_SORTING_AFTER_FILTERING); >+ fNeedsSortingAfterFiltering= Boolean.valueOf(needsSortingAfterFilteringAttribute).booleanValue(); > > fClass= element.getAttribute(CLASS); > checkNotNull(fClass, CLASS); >@@ -564,4 +579,13 @@ > } > } > >+ /** >+ * Returns the <code>needsSortingAfterFiltering</code> flag of the described extension. >+ * >+ * @return the needsSortingAfterFiltering flag of the described extension >+ * @since 3.8 >+ */ >+ public boolean isSortingAfterFilteringNeeded() { >+ return fNeedsSortingAfterFiltering; >+ } > } >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 aba09ea..c345146 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 >@@ -8,6 +8,7 @@ > * Contributors: > * IBM Corporation - initial API and implementation > * Paul Fullbright <paul.fullbright@oracle.com> - content assist category enablement - http://bugs.eclipse.org/345213 >+ * Marcel Bruch <bruch@cs.tu-darmstadt.de> - [content assist] Allow to re-sort proposals - https://bugs.eclipse.org/bugs/show_bug.cgi?id=350991 > *******************************************************************************/ > package org.eclipse.jdt.internal.ui.text.java; > >@@ -29,7 +30,9 @@ > import org.eclipse.swt.widgets.Shell; > > import org.eclipse.core.runtime.Assert; >+import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.InvalidRegistryObjectException; > import org.eclipse.core.runtime.NullProgressMonitor; > import org.eclipse.core.runtime.Platform; > import org.eclipse.core.runtime.SubProgressMonitor; >@@ -63,6 +66,7 @@ > 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; >@@ -277,16 +281,19 @@ > * @return the list of proposals > */ > private List<ICompletionProposal> collectProposals(ITextViewer viewer, int offset, IProgressMonitor monitor, ContentAssistInvocationContext context) { >+ boolean needsSortingAfterFiltering= false; > List<ICompletionProposal> proposals= new ArrayList<ICompletionProposal>(); > List<CompletionProposalCategory> providers= getCategories(); > for (Iterator<CompletionProposalCategory> it= providers.iterator(); it.hasNext();) { > CompletionProposalCategory cat= it.next(); > List<ICompletionProposal> computed= cat.computeCompletionProposals(context, fPartition, new SubProgressMonitor(monitor, 1)); > proposals.addAll(computed); >+ needsSortingAfterFiltering= needsSortingAfterFiltering || (cat.isSortingAfterFilteringNeeded() && !computed.isEmpty()); > if (fErrorMessage == null) > fErrorMessage= cat.getErrorMessage(); > } >- >+ if (needsSortingAfterFiltering) >+ installProposalSorter(); > return proposals; > } > >@@ -630,4 +637,25 @@ > return (KeySequence) binding; > return null; > } >+ >+ /** >+ * Installs the proposal sorter in the current completion assistant. >+ * >+ * @since 3.8 >+ */ >+ private void installProposalSorter() { >+ AbstractProposalSorter sorter= null; >+ ProposalSorterHandle currentSorter= ProposalSorterRegistry.getDefault().getCurrentSorter(); >+ try { >+ sorter= currentSorter.getSorter(); >+ } catch (InvalidRegistryObjectException x) { >+ JavaPlugin.log(currentSorter.createExceptionStatus(x)); >+ } catch (CoreException x) { >+ JavaPlugin.log(currentSorter.createExceptionStatus(x)); >+ } 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/ProposalSorterHandle.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/ProposalSorterHandle.java >index fe59e1c..4eb6c3f 100644 >--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/ProposalSorterHandle.java >+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/ProposalSorterHandle.java >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2005, 2011 IBM Corporation and others. >+ * Copyright (c) 2005, 2012 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 >@@ -7,6 +7,7 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >+ * Marcel Bruch <bruch@cs.tu-darmstadt.de> - [content assist] Allow to re-sort proposals - https://bugs.eclipse.org/bugs/show_bug.cgi?id=350991 > *******************************************************************************/ > package org.eclipse.jdt.internal.ui.text.java; > >@@ -133,7 +134,7 @@ > * @throws InvalidRegistryObjectException if the extension is not valid any longer (e.g. due to > * plug-in unloading) > */ >- private synchronized AbstractProposalSorter getSorter() throws CoreException, InvalidRegistryObjectException { >+ synchronized AbstractProposalSorter getSorter() throws CoreException, InvalidRegistryObjectException { > if (fSorter == null) > fSorter= createSorter(); > return fSorter; >@@ -213,21 +214,21 @@ > return stats; > } > >- private Status createExceptionStatus(InvalidRegistryObjectException x) { >+ Status createExceptionStatus(InvalidRegistryObjectException x) { > // extension has become invalid - log & disable > String disable= createBlameMessage(); > String reason= JavaTextMessages.CompletionProposalComputerDescriptor_reason_invalid; > return new Status(IStatus.INFO, JavaPlugin.getPluginId(), IStatus.OK, disable + " " + reason, x); //$NON-NLS-1$ > } > >- private Status createExceptionStatus(CoreException x) { >+ Status createExceptionStatus(CoreException x) { > // unable to instantiate the extension - log & disable > String disable= createBlameMessage(); > String reason= JavaTextMessages.CompletionProposalComputerDescriptor_reason_instantiation; > return new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IStatus.OK, disable + " " + reason, x); //$NON-NLS-1$ > } > >- private Status createExceptionStatus(RuntimeException x) { >+ Status createExceptionStatus(RuntimeException x) { > // misbehaving extension - log & disable > String disable= createBlameMessage(); > String reason= JavaTextMessages.CompletionProposalComputerDescriptor_reason_runtime_ex; >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 2fd7d79..fccf1cf 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 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2006, 2011 IBM Corporation and others. >+ * Copyright (c) 2006, 2012 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 >@@ -7,6 +7,7 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >+ * Marcel Bruch <bruch@cs.tu-darmstadt.de> - [content assist] Allow to re-sort proposals - https://bugs.eclipse.org/bugs/show_bug.cgi?id=350991 > *******************************************************************************/ > package org.eclipse.jdt.ui.text.java; > >@@ -15,6 +16,7 @@ > import org.eclipse.core.runtime.IConfigurationElement; > > import org.eclipse.jface.text.contentassist.ICompletionProposal; >+import org.eclipse.jface.text.contentassist.ICompletionProposalSorter; > > /** > * Abstract base class for sorters contributed to the >@@ -30,7 +32,7 @@ > * > * @since 3.2 > */ >-public abstract class AbstractProposalSorter implements Comparator<ICompletionProposal> { >+public abstract class AbstractProposalSorter implements Comparator<ICompletionProposal>, ICompletionProposalSorter { > > /** > * Creates a new sorter. Note that subclasses must provide a zero-argument constructor to be >@@ -40,7 +42,9 @@ > } > > /** >- * Called once before sorting. >+ * 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. > * <p> > * Clients may override, the default implementation does nothing. > * </p> >@@ -63,7 +67,8 @@ > public abstract int compare(ICompletionProposal p1, ICompletionProposal p2); > > /** >- * Called once after sorting. >+ * 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. > * <p> > * Clients may override, the default implementation does nothing. > * </p>
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 350991
:
211946
|
211947
|
211966
|
211967
|
211968
|
212115
|
212116
|
212117
|
212506
|
212507
|
212525
|
212588
|
212589