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 211968 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 reordering
bug350991_jdt.ui.patch (text/plain), 16.51 KB, created by
Marcel Bruch
on 2012-03-02 09:52:23 EST
(
hide
)
Description:
patch for jdt.ui to enable reordering
Filename:
MIME Type:
Creator:
Marcel Bruch
Created:
2012-03-02 09:52:23 EST
Size:
16.51 KB
patch
obsolete
>From dd8b7455aedd759d2f95d9ef5b89e4521111285b Mon Sep 17 00:00:00 2001 >From: Marcel Bruch <marcel.bruch@gmail.com> >Date: Fri, 2 Mar 2012 15:51:46 +0100 >Subject: [PATCH] https://bugs.eclipse.org/bugs/show_bug.cgi?id=350991 > >--- > .../schema/javaCompletionProposalComputer.exsd | 9 ++- > .../ui/text/java/CompletionProposalCategory.java | 80 ++++++++++++------- > .../java/CompletionProposalComputerDescriptor.java | 20 +++++ > .../ui/text/java/ContentAssistProcessor.java | 18 ++++- > .../ui/text/java/ProposalSorterHandle.java | 2 +- > .../jdt/ui/text/java/AbstractProposalSorter.java | 4 +- > 6 files changed, 99 insertions(+), 34 deletions(-) > >diff --git a/org.eclipse.jdt.ui/schema/javaCompletionProposalComputer.exsd b/org.eclipse.jdt.ui/schema/javaCompletionProposalComputer.exsd >index c25fcf9..bad37a2 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,13 @@ and must have a public 0-argument constructor. > </appInfo> > </annotation> > </attribute> >+ <attribute name="requiresReordering" type="boolean" use="default" value="false"> >+ <annotation> >+ <documentation> >+ if the attribute is set to "true" it forces the content assist processessor to resort the list of proposals every time a new token is entered or removed to the completion prefix. >+ </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..8d89c8c 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 >@@ -52,7 +52,7 @@ import org.eclipse.jdt.internal.ui.JavaPlugin; > > /** > * Describes a category extension to the "javaCompletionProposalComputer" extension point. >- * >+ * > * @since 3.2 > */ > public final class CompletionProposalCategory { >@@ -60,22 +60,31 @@ public final class CompletionProposalCategory { > private static final String ICON= "icon"; //$NON-NLS-1$ > > private final String fId; >+ > private final String fName; >+ > private final IConfigurationElement fElement; >+ > /** The image descriptor for this category, or <code>null</code> if none specified. */ > private final ImageDescriptor fImage; >- >+ > /** The enablement expression for this category, or <code>null</code> if none specified. */ > private final Expression fEnablementExpression; > > private boolean fIsSeparateCommand= true; >+ > private boolean fIsEnabled= true; >+ > private boolean fIsIncluded= true; >+ > private final CompletionProposalComputerRegistry fRegistry; > > private int fSortOrder= 0xffff - 1; >+ > private String fLastError= null; > >+ private boolean fRequiresReordering; >+ > CompletionProposalCategory(IConfigurationElement element, CompletionProposalComputerRegistry registry) throws CoreException { > fElement= element; > fRegistry= registry; >@@ -87,16 +96,16 @@ public final class CompletionProposalCategory { > fName= fId; > else > fName= name; >- >+ > IConfigurationElement[] children= fElement.getChildren(ExpressionTagNames.ENABLEMENT); > if (children.length == 1) { > ExpressionConverter parser= ExpressionConverter.getDefault(); >- fEnablementExpression = parser.perform(children[0]); >+ fEnablementExpression= parser.perform(children[0]); > } > else { >- fEnablementExpression = null; >+ fEnablementExpression= null; > } >- >+ > String icon= element.getAttribute(ICON); > ImageDescriptor img= null; > if (icon != null) { >@@ -108,7 +117,6 @@ public final class CompletionProposalCategory { > } > } > fImage= img; >- > } > > CompletionProposalCategory(String id, String name, CompletionProposalComputerRegistry registry) { >@@ -116,7 +124,7 @@ public final class CompletionProposalCategory { > fId= id; > fName= name; > fElement= null; >- fEnablementExpression = null; >+ fEnablementExpression= null; > fImage= null; > } > >@@ -128,7 +136,7 @@ public final class CompletionProposalCategory { > > /** > * Checks that the given attribute value is not <code>null</code>. >- * >+ * > * @param value the element to be checked > * @param attribute the attribute > * @throws CoreException if <code>value</code> is <code>null</code> >@@ -142,9 +150,10 @@ public final class CompletionProposalCategory { > } > } > >+ > /** > * Returns the identifier of the described extension. >- * >+ * > * @return Returns the id > */ > public String getId() { >@@ -153,7 +162,7 @@ public final class CompletionProposalCategory { > > /** > * Returns the name of the described extension. >- * >+ * > * @return Returns the name > */ > public String getName() { >@@ -161,10 +170,9 @@ public final class CompletionProposalCategory { > } > > /** >- * Returns the name of the described extension >- * without mnemonic hint in order to be displayed >- * in a message. >- * >+ * Returns the name of the described extension without mnemonic hint in order to be displayed in >+ * a message. >+ * > * @return Returns the name > */ > public String getDisplayName() { >@@ -173,7 +181,7 @@ public final class CompletionProposalCategory { > > /** > * Returns the image descriptor of the described category. >- * >+ * > * @return the image descriptor of the described category > */ > public ImageDescriptor getImageDescriptor() { >@@ -182,7 +190,7 @@ public final class CompletionProposalCategory { > > /** > * Sets the separate command state of the category. >- * >+ * > * @param enabled the new enabled state. > */ > public void setSeparateCommand(boolean enabled) { >@@ -191,7 +199,7 @@ public final class CompletionProposalCategory { > > /** > * Returns the enablement state of the category. >- * >+ * > * @return the enablement state of the category > */ > public boolean isSeparateCommand() { >@@ -223,7 +231,7 @@ public final class CompletionProposalCategory { > /** > * Returns <code>true</code> if the category contains any computers, <code>false</code> > * otherwise. >- * >+ * > * @return <code>true</code> if the category contains any computers, <code>false</code> > * otherwise > */ >@@ -238,9 +246,9 @@ public final class CompletionProposalCategory { > } > > /** >- * Returns <code>true</code> if the category contains any computers in the given partition, <code>false</code> >- * otherwise. >- * >+ * Returns <code>true</code> if the category contains any computers in the given partition, >+ * <code>false</code> otherwise. >+ * > * @param partition the partition > * @return <code>true</code> if the category contains any computers, <code>false</code> > * otherwise >@@ -268,7 +276,7 @@ public final class CompletionProposalCategory { > public void setSortOrder(int sortOrder) { > fSortOrder= sortOrder; > } >- >+ > /** > * Determines if the project matches any enablement expression defined on the extension. > * >@@ -283,11 +291,11 @@ public final class CompletionProposalCategory { > if (fEnablementExpression == null) { > return true; > } >- >+ > if (javaProject == null) { > return false; > } >- >+ > try { > EvaluationContext evalContext= new EvaluationContext(null, javaProject); > evalContext.addVariable("project", javaProject); //$NON-NLS-1$ >@@ -295,7 +303,7 @@ public final class CompletionProposalCategory { > } catch (CoreException e) { > JavaPlugin.log(e); > } >- >+ > return false; > } > >@@ -303,7 +311,7 @@ public final class CompletionProposalCategory { > * Safely computes completion proposals of all computers of this category through their > * extension. If an extension is disabled, throws an exception or otherwise does not adhere to > * the contract described in {@link IJavaCompletionProposalComputer}, it is disabled. >- * >+ * > * @param context the invocation context passed on to the extension > * @param partition the partition type where to invocation occurred > * @param monitor the progress monitor passed on to the extension >@@ -328,7 +336,7 @@ public final class CompletionProposalCategory { > * Safely computes context information objects of all computers of this category through their > * extension. If an extension is disabled, throws an exception or otherwise does not adhere to > * the contract described in {@link IJavaCompletionProposalComputer}, it is disabled. >- * >+ * > * @param context the invocation context passed on to the extension > * @param partition the partition type where to invocation occurred > * @param monitor the progress monitor passed on to the extension >@@ -351,7 +359,7 @@ public final class CompletionProposalCategory { > > /** > * Returns the error message from the computers in this category. >- * >+ * > * @return the error message from the computers in this category > */ > public String getErrorMessage() { >@@ -365,8 +373,10 @@ public final class CompletionProposalCategory { > 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(); >+ fRequiresReordering|= desc.requiresReordering(); >+ } > if (fLastError == null) > fLastError= desc.getErrorMessage(); > } >@@ -386,4 +396,14 @@ public final class CompletionProposalCategory { > } > } > >+ /** >+ * Returns whether any completion proposal computer associated with this category requires >+ * proposals to be reordered. >+ * >+ * @return <code>true</code> if any completion proposal computer in this category requires >+ * proposals to be reordered. >+ */ >+ public boolean requiresReordering() { >+ return fRequiresReordering; >+ } > } >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..1a6dc86 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 >@@ -61,6 +61,8 @@ final class CompletionProposalComputerDescriptor { > 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 requiresReordering attribute. */ >+ private static final String REQUIRES_REORDERING= "requiresReordering"; //$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 +133,13 @@ final class CompletionProposalComputerDescriptor { > * @since 3.4 > */ > boolean fTriedLoadingComputer= false; >+ /** >+ * Tells whether this proposal engine provides dynamic content that needs reordering of its >+ * proposals. >+ * >+ * @since 3.8 >+ */ >+ private boolean fRequiresReordering; > > > /** >@@ -174,6 +183,9 @@ final class CompletionProposalComputerDescriptor { > String activateAttribute= element.getAttribute(ACTIVATE); > fActivate= Boolean.valueOf(activateAttribute).booleanValue(); > >+ String reorderingAttribute= element.getAttribute(REQUIRES_REORDERING); >+ fRequiresReordering= Boolean.valueOf(reorderingAttribute).booleanValue(); >+ > fClass= element.getAttribute(CLASS); > checkNotNull(fClass, CLASS); > >@@ -564,4 +576,12 @@ final class CompletionProposalComputerDescriptor { > } > } > >+ /** >+ * Returns the requiresReordering flag of the described extension. >+ * >+ * @return the requiresReordering flag of the described extension >+ */ >+ public boolean requiresReordering() { >+ return fRequiresReordering; >+ } > } >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..08a5358 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 >@@ -63,6 +63,7 @@ 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; >@@ -277,16 +278,20 @@ public class ContentAssistProcessor implements IContentAssistProcessor { > * @return the list of proposals > */ > private List<ICompletionProposal> collectProposals(ITextViewer viewer, int offset, IProgressMonitor monitor, ContentAssistInvocationContext context) { >+ boolean requiresReordering= 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); >+ requiresReordering|= cat.requiresReordering() && !computed.isEmpty(); > if (fErrorMessage == null) > fErrorMessage= cat.getErrorMessage(); > } >- >+ if (requiresReordering) { >+ installProposalSorter(); >+ } > return proposals; > } > >@@ -630,4 +635,15 @@ public class ContentAssistProcessor implements IContentAssistProcessor { > return (KeySequence) binding; > return null; > } >+ >+ private void installProposalSorter() { >+ AbstractProposalSorter sorter= null; >+ try { >+ sorter= ProposalSorterRegistry.getDefault().getCurrentSorter().getSorter(); >+ } catch (Exception e) { >+ // TODO log? What's the common approach here? >+ } >+ 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..18efab0 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 >@@ -133,7 +133,7 @@ public final class ProposalSorterHandle { > * @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; >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..ff41ccb 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 >@@ -15,6 +15,8 @@ import java.util.Comparator; > 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 @@ import org.eclipse.jface.text.contentassist.ICompletionProposal; > * > * @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 >-- >1.7.5.4 >
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