Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 350991 | Differences between
and this patch

Collapse All | Expand All

(-)a/org.eclipse.jdt.ui/schema/javaCompletionProposalComputer.exsd (-1 / +8 lines)
Lines 1-6 Link Here
1
<?xml version='1.0' encoding='UTF-8'?>
1
<?xml version='1.0' encoding='UTF-8'?>
2
<!-- Schema file written by PDE -->
2
<!-- Schema file written by PDE -->
3
<schema targetNamespace="org.eclipse.jdt.ui">
3
<schema targetNamespace="org.eclipse.jdt.ui" xmlns="http://www.w3.org/2001/XMLSchema">
4
<annotation>
4
<annotation>
5
      <appInfo>
5
      <appInfo>
6
         <meta.schema plugin="org.eclipse.jdt.ui" id="javaCompletionProposalComputer" name="Java Completion Proposal Computer"/>
6
         <meta.schema plugin="org.eclipse.jdt.ui" id="javaCompletionProposalComputer" name="Java Completion Proposal Computer"/>
Lines 95-100 and must have a public 0-argument constructor. Link Here
95
               </appInfo>
95
               </appInfo>
96
            </annotation>
96
            </annotation>
97
         </attribute>
97
         </attribute>
98
         <attribute name="requiresReordering" type="boolean" use="default" value="false">
99
            <annotation>
100
               <documentation>
101
                  if the attribute is set to &quot;true&quot; 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.
102
               </documentation>
103
            </annotation>
104
         </attribute>
98
      </complexType>
105
      </complexType>
99
   </element>
106
   </element>
100
107
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/CompletionProposalCategory.java (-1 / +16 lines)
Lines 8-13 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Paul Fullbright <paul.fullbright@oracle.com> - content assist category enablement - http://bugs.eclipse.org/345213
10
 *     Paul Fullbright <paul.fullbright@oracle.com> - content assist category enablement - http://bugs.eclipse.org/345213
11
 *     Marcel Bruch <bruch@cs.tu-darmstadt.de> - [content assist] Allow to re-sort proposals - https://bugs.eclipse.org/bugs/show_bug.cgi?id=350991
11
 *******************************************************************************/
12
 *******************************************************************************/
12
package org.eclipse.jdt.internal.ui.text.java;
13
package org.eclipse.jdt.internal.ui.text.java;
13
14
Lines 76-81 public final class CompletionProposalCategory { Link Here
76
	private int fSortOrder= 0xffff - 1;
77
	private int fSortOrder= 0xffff - 1;
77
	private String fLastError= null;
78
	private String fLastError= null;
78
79
80
	private boolean fRequiresReordering;
81
79
	CompletionProposalCategory(IConfigurationElement element, CompletionProposalComputerRegistry registry) throws CoreException {
82
	CompletionProposalCategory(IConfigurationElement element, CompletionProposalComputerRegistry registry) throws CoreException {
80
		fElement= element;
83
		fElement= element;
81
		fRegistry= registry;
84
		fRegistry= registry;
Lines 365-372 public final class CompletionProposalCategory { Link Here
365
		List<CompletionProposalComputerDescriptor> descriptors= new ArrayList<CompletionProposalComputerDescriptor>(fRegistry.getProposalComputerDescriptors());
368
		List<CompletionProposalComputerDescriptor> descriptors= new ArrayList<CompletionProposalComputerDescriptor>(fRegistry.getProposalComputerDescriptors());
366
		for (Iterator<CompletionProposalComputerDescriptor> it= descriptors.iterator(); it.hasNext();) {
369
		for (Iterator<CompletionProposalComputerDescriptor> it= descriptors.iterator(); it.hasNext();) {
367
			CompletionProposalComputerDescriptor desc= it.next();
370
			CompletionProposalComputerDescriptor desc= it.next();
368
			if (desc.getCategory() == this)
371
			if (desc.getCategory() == this){
369
				desc.sessionStarted();
372
				desc.sessionStarted();
373
				fRequiresReordering|= desc.requiresReordering();
374
			}
370
			if (fLastError == null)
375
			if (fLastError == null)
371
				fLastError= desc.getErrorMessage();
376
				fLastError= desc.getErrorMessage();
372
		}
377
		}
Lines 386-389 public final class CompletionProposalCategory { Link Here
386
		}
391
		}
387
	}
392
	}
388
393
394
	/**
395
	 * Returns whether any completion proposal computer associated with this category requires
396
	 * proposals to be reordered.
397
	 * 
398
	 * @return <code>true</code> if any completion proposal computer in this category requires
399
	 *         proposals to be reordered.
400
	 */
401
	public boolean requiresReordering() {
402
		return fRequiresReordering;
403
	}
389
}
404
}
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/CompletionProposalComputerDescriptor.java (+21 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Marcel Bruch <bruch@cs.tu-darmstadt.de> - [content assist] Allow to re-sort proposals - https://bugs.eclipse.org/bugs/show_bug.cgi?id=350991
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.internal.ui.text.java;
12
package org.eclipse.jdt.internal.ui.text.java;
12
13
Lines 61-66 final class CompletionProposalComputerDescriptor { Link Here
61
	private static final String CLASS= "class"; //$NON-NLS-1$
62
	private static final String CLASS= "class"; //$NON-NLS-1$
62
	/** The extension schema name of the activate attribute. */
63
	/** The extension schema name of the activate attribute. */
63
	private static final String ACTIVATE= "activate"; //$NON-NLS-1$
64
	private static final String ACTIVATE= "activate"; //$NON-NLS-1$
65
	/** The extension schema name of the requiresReordering attribute. */
66
	private static final String REQUIRES_REORDERING= "requiresReordering"; //$NON-NLS-1$
64
	/** The extension schema name of the partition child elements. */
67
	/** The extension schema name of the partition child elements. */
65
	private static final String PARTITION= "partition"; //$NON-NLS-1$
68
	private static final String PARTITION= "partition"; //$NON-NLS-1$
66
	/** Set of Java partition types. */
69
	/** Set of Java partition types. */
Lines 131-136 final class CompletionProposalComputerDescriptor { Link Here
131
	 * @since 3.4
134
	 * @since 3.4
132
	 */
135
	 */
133
	boolean fTriedLoadingComputer= false;
136
	boolean fTriedLoadingComputer= false;
137
	/**
138
	 * Tells whether this proposal engine provides dynamic content that needs reordering of its
139
	 * proposals.
140
	 * 
141
	 * @since 3.8
142
	 */
143
	private boolean fRequiresReordering;
134
144
135
145
136
	/**
146
	/**
Lines 174-179 final class CompletionProposalComputerDescriptor { Link Here
174
		String activateAttribute= element.getAttribute(ACTIVATE);
184
		String activateAttribute= element.getAttribute(ACTIVATE);
175
		fActivate= Boolean.valueOf(activateAttribute).booleanValue();
185
		fActivate= Boolean.valueOf(activateAttribute).booleanValue();
176
186
187
		String reorderingAttribute= element.getAttribute(REQUIRES_REORDERING);
188
		fRequiresReordering= Boolean.valueOf(reorderingAttribute).booleanValue();
189
177
		fClass= element.getAttribute(CLASS);
190
		fClass= element.getAttribute(CLASS);
178
		checkNotNull(fClass, CLASS);
191
		checkNotNull(fClass, CLASS);
179
192
Lines 564-567 final class CompletionProposalComputerDescriptor { Link Here
564
        }
577
        }
565
    }
578
    }
566
579
580
	/**
581
	 * Returns the requiresReordering flag of the described extension.
582
	 * 
583
	 * @return the requiresReordering flag of the described extension
584
	 */
585
	public boolean requiresReordering() {
586
		return fRequiresReordering;
587
	}
567
}
588
}
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/ContentAssistProcessor.java (-1 / +17 lines)
Lines 63-68 import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; Link Here
63
import org.eclipse.jdt.internal.corext.util.Messages;
63
import org.eclipse.jdt.internal.corext.util.Messages;
64
64
65
import org.eclipse.jdt.ui.PreferenceConstants;
65
import org.eclipse.jdt.ui.PreferenceConstants;
66
import org.eclipse.jdt.ui.text.java.AbstractProposalSorter;
66
import org.eclipse.jdt.ui.text.java.ContentAssistInvocationContext;
67
import org.eclipse.jdt.ui.text.java.ContentAssistInvocationContext;
67
68
68
import org.eclipse.jdt.internal.ui.JavaPlugin;
69
import org.eclipse.jdt.internal.ui.JavaPlugin;
Lines 277-292 public class ContentAssistProcessor implements IContentAssistProcessor { Link Here
277
	 * @return the list of proposals
278
	 * @return the list of proposals
278
	 */
279
	 */
279
	private List<ICompletionProposal> collectProposals(ITextViewer viewer, int offset, IProgressMonitor monitor, ContentAssistInvocationContext context) {
280
	private List<ICompletionProposal> collectProposals(ITextViewer viewer, int offset, IProgressMonitor monitor, ContentAssistInvocationContext context) {
281
		boolean requiresReordering= false;
280
		List<ICompletionProposal> proposals= new ArrayList<ICompletionProposal>();
282
		List<ICompletionProposal> proposals= new ArrayList<ICompletionProposal>();
281
		List<CompletionProposalCategory> providers= getCategories();
283
		List<CompletionProposalCategory> providers= getCategories();
282
		for (Iterator<CompletionProposalCategory> it= providers.iterator(); it.hasNext();) {
284
		for (Iterator<CompletionProposalCategory> it= providers.iterator(); it.hasNext();) {
283
			CompletionProposalCategory cat= it.next();
285
			CompletionProposalCategory cat= it.next();
284
			List<ICompletionProposal> computed= cat.computeCompletionProposals(context, fPartition, new SubProgressMonitor(monitor, 1));
286
			List<ICompletionProposal> computed= cat.computeCompletionProposals(context, fPartition, new SubProgressMonitor(monitor, 1));
285
			proposals.addAll(computed);
287
			proposals.addAll(computed);
288
			requiresReordering|= cat.requiresReordering() && !computed.isEmpty();
286
			if (fErrorMessage == null)
289
			if (fErrorMessage == null)
287
				fErrorMessage= cat.getErrorMessage();
290
				fErrorMessage= cat.getErrorMessage();
288
		}
291
		}
289
292
		if (requiresReordering) {
293
			installProposalSorter();
294
		}
290
		return proposals;
295
		return proposals;
291
	}
296
	}
292
297
Lines 630-633 public class ContentAssistProcessor implements IContentAssistProcessor { Link Here
630
			return (KeySequence) binding;
635
			return (KeySequence) binding;
631
		return null;
636
		return null;
632
    }
637
    }
638
639
	private void installProposalSorter() {
640
		AbstractProposalSorter sorter= null;
641
		try {
642
			sorter= ProposalSorterRegistry.getDefault().getCurrentSorter().getSorter();
643
		} catch (Exception e) {
644
			// TODO log? What's the common approach here?
645
		}
646
		fAssistant.setSorter(sorter);
647
	}
648
633
}
649
}
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/ProposalSorterHandle.java (-1 / +2 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Marcel Bruch <bruch@cs.tu-darmstadt.de> - [content assist] Allow to re-sort proposals - https://bugs.eclipse.org/bugs/show_bug.cgi?id=350991
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.internal.ui.text.java;
12
package org.eclipse.jdt.internal.ui.text.java;
12
13
Lines 133-139 public final class ProposalSorterHandle { Link Here
133
	 * @throws InvalidRegistryObjectException if the extension is not valid any longer (e.g. due to
134
	 * @throws InvalidRegistryObjectException if the extension is not valid any longer (e.g. due to
134
	 *         plug-in unloading)
135
	 *         plug-in unloading)
135
	 */
136
	 */
136
	private synchronized AbstractProposalSorter getSorter() throws CoreException, InvalidRegistryObjectException {
137
	synchronized AbstractProposalSorter getSorter() throws CoreException, InvalidRegistryObjectException {
137
		if (fSorter == null)
138
		if (fSorter == null)
138
			fSorter= createSorter();
139
			fSorter= createSorter();
139
		return fSorter;
140
		return fSorter;
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/text/java/AbstractProposalSorter.java (-2 / +3 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Marcel Bruch <bruch@cs.tu-darmstadt.de> - [content assist] Allow to re-sort proposals - https://bugs.eclipse.org/bugs/show_bug.cgi?id=350991
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.ui.text.java;
12
package org.eclipse.jdt.ui.text.java;
12
13
Lines 15-20 import java.util.Comparator; Link Here
15
import org.eclipse.core.runtime.IConfigurationElement;
16
import org.eclipse.core.runtime.IConfigurationElement;
16
17
17
import org.eclipse.jface.text.contentassist.ICompletionProposal;
18
import org.eclipse.jface.text.contentassist.ICompletionProposal;
19
import org.eclipse.jface.text.contentassist.ICompletionProposalSorter;
18
20
19
/**
21
/**
20
 * Abstract base class for sorters contributed to the
22
 * Abstract base class for sorters contributed to the
Lines 30-36 import org.eclipse.jface.text.contentassist.ICompletionProposal; Link Here
30
 *
32
 *
31
 * @since 3.2
33
 * @since 3.2
32
 */
34
 */
33
public abstract class AbstractProposalSorter implements Comparator<ICompletionProposal> {
35
public abstract class AbstractProposalSorter implements Comparator<ICompletionProposal>, ICompletionProposalSorter {
34
36
35
	/**
37
	/**
36
	 * Creates a new sorter. Note that subclasses must provide a zero-argument constructor to be
38
	 * Creates a new sorter. Note that subclasses must provide a zero-argument constructor to be
37
- 

Return to bug 350991