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 / +10 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 Link Here
95
               </appInfo>
95
               </appInfo>
96
            </annotation>
96
            </annotation>
97
         </attribute>
97
         </attribute>
98
         <attribute name="needsSortingAfterFiltering" 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 processor to resort the list of proposals every time a new token is entered or removed to the completion prefix.
102
103
@since 3.8
104
               </documentation>
105
            </annotation>
106
         </attribute>
98
      </complexType>
107
      </complexType>
99
   </element>
108
   </element>
100
109
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/CompletionProposalCategory.java (-1 / +24 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 75-80 Link Here
75
76
76
	private int fSortOrder= 0xffff - 1;
77
	private int fSortOrder= 0xffff - 1;
77
	private String fLastError= null;
78
	private String fLastError= null;
79
80
	/**
81
	 * Flag indicating whether any completion engine associated with this category requests
82
	 * resorting of its proposals after filtering is triggered. Filtering is, e.g., triggered when a
83
	 * user continues typing with an open completion window.
84
	 * 
85
	 * @since 3.8
86
	 */
87
	private boolean fNeedsSortingAfterFiltering;
78
88
79
	CompletionProposalCategory(IConfigurationElement element, CompletionProposalComputerRegistry registry) throws CoreException {
89
	CompletionProposalCategory(IConfigurationElement element, CompletionProposalComputerRegistry registry) throws CoreException {
80
		fElement= element;
90
		fElement= element;
Lines 365-372 Link Here
365
		List<CompletionProposalComputerDescriptor> descriptors= new ArrayList<CompletionProposalComputerDescriptor>(fRegistry.getProposalComputerDescriptors());
375
		List<CompletionProposalComputerDescriptor> descriptors= new ArrayList<CompletionProposalComputerDescriptor>(fRegistry.getProposalComputerDescriptors());
366
		for (Iterator<CompletionProposalComputerDescriptor> it= descriptors.iterator(); it.hasNext();) {
376
		for (Iterator<CompletionProposalComputerDescriptor> it= descriptors.iterator(); it.hasNext();) {
367
			CompletionProposalComputerDescriptor desc= it.next();
377
			CompletionProposalComputerDescriptor desc= it.next();
368
			if (desc.getCategory() == this)
378
			if (desc.getCategory() == this){
369
				desc.sessionStarted();
379
				desc.sessionStarted();
380
				fNeedsSortingAfterFiltering= fNeedsSortingAfterFiltering || desc.isSortingAfterFilteringNeeded();
381
		    }
370
			if (fLastError == null)
382
			if (fLastError == null)
371
				fLastError= desc.getErrorMessage();
383
				fLastError= desc.getErrorMessage();
372
		}
384
		}
Lines 376-381 Link Here
376
	 * Notifies the computers in this category of a proposal computation session end.
388
	 * Notifies the computers in this category of a proposal computation session end.
377
	 */
389
	 */
378
	public void sessionEnded() {
390
	public void sessionEnded() {
391
		fNeedsSortingAfterFiltering= false;
379
		List<CompletionProposalComputerDescriptor> descriptors= new ArrayList<CompletionProposalComputerDescriptor>(fRegistry.getProposalComputerDescriptors());
392
		List<CompletionProposalComputerDescriptor> descriptors= new ArrayList<CompletionProposalComputerDescriptor>(fRegistry.getProposalComputerDescriptors());
380
		for (Iterator<CompletionProposalComputerDescriptor> it= descriptors.iterator(); it.hasNext();) {
393
		for (Iterator<CompletionProposalComputerDescriptor> it= descriptors.iterator(); it.hasNext();) {
381
			CompletionProposalComputerDescriptor desc= it.next();
394
			CompletionProposalComputerDescriptor desc= it.next();
Lines 386-389 Link Here
386
		}
399
		}
387
	}
400
	}
388
401
402
	/**
403
	 * Returns whether any completion proposal computer associated with this category requires
404
	 * proposals to be sorted again after filtering.
405
	 * 
406
	 * @return <code>true</code> if any completion proposal computer in this category requires
407
	 *         proposals to be sorted.
408
	 */
409
	public boolean isSortingAfterFilteringNeeded() {
410
		return fNeedsSortingAfterFiltering;
411
	}
389
}
412
}
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/CompletionProposalComputerDescriptor.java (-1 / +25 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2011 IBM Corporation and others.
2
 * Copyright (c) 2005, 2012 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
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 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 needsSortingAfterFiltering attribute. */
66
	private static final String NEEDS_SORTING_AFTER_FILTERING= "needsSortingAfterFiltering"; //$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 Link Here
131
	 * @since 3.4
134
	 * @since 3.4
132
	 */
135
	 */
133
	boolean fTriedLoadingComputer= false;
136
	boolean fTriedLoadingComputer= false;
137
	
138
	/**
139
	 * Tells whether this proposal engine provides dynamic content that needs to be sorted after its
140
	 * proposal have been filtered. Filtering happens, e.g., when a user continues typing with an
141
	 * open completion window.
142
	 * 
143
	 * @since 3.8
144
	 */
145
	private boolean fNeedsSortingAfterFiltering;
134
146
135
147
136
	/**
148
	/**
Lines 173-178 Link Here
173
185
174
		String activateAttribute= element.getAttribute(ACTIVATE);
186
		String activateAttribute= element.getAttribute(ACTIVATE);
175
		fActivate= Boolean.valueOf(activateAttribute).booleanValue();
187
		fActivate= Boolean.valueOf(activateAttribute).booleanValue();
188
189
		String needsSortingAfterFilteringAttribute= element.getAttribute(NEEDS_SORTING_AFTER_FILTERING);
190
		fNeedsSortingAfterFiltering= Boolean.valueOf(needsSortingAfterFilteringAttribute).booleanValue();
176
191
177
		fClass= element.getAttribute(CLASS);
192
		fClass= element.getAttribute(CLASS);
178
		checkNotNull(fClass, CLASS);
193
		checkNotNull(fClass, CLASS);
Lines 564-567 Link Here
564
        }
579
        }
565
    }
580
    }
566
581
582
	/**
583
	 * Returns the <code>needsSortingAfterFiltering</code> flag of the described extension.
584
	 * 
585
	 * @return the needsSortingAfterFiltering flag of the described extension
586
	 * @since 3.8
587
	 */
588
	public boolean isSortingAfterFilteringNeeded() {
589
		return fNeedsSortingAfterFiltering;
590
	}
567
}
591
}
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/ContentAssistProcessor.java (-1 / +38 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 29-35 Link Here
29
import org.eclipse.swt.widgets.Shell;
30
import org.eclipse.swt.widgets.Shell;
30
31
31
import org.eclipse.core.runtime.Assert;
32
import org.eclipse.core.runtime.Assert;
33
import org.eclipse.core.runtime.CoreException;
32
import org.eclipse.core.runtime.IProgressMonitor;
34
import org.eclipse.core.runtime.IProgressMonitor;
35
import org.eclipse.core.runtime.InvalidRegistryObjectException;
33
import org.eclipse.core.runtime.NullProgressMonitor;
36
import org.eclipse.core.runtime.NullProgressMonitor;
34
import org.eclipse.core.runtime.Platform;
37
import org.eclipse.core.runtime.Platform;
35
import org.eclipse.core.runtime.SubProgressMonitor;
38
import org.eclipse.core.runtime.SubProgressMonitor;
Lines 63-68 Link Here
63
import org.eclipse.jdt.internal.corext.util.Messages;
66
import org.eclipse.jdt.internal.corext.util.Messages;
64
67
65
import org.eclipse.jdt.ui.PreferenceConstants;
68
import org.eclipse.jdt.ui.PreferenceConstants;
69
import org.eclipse.jdt.ui.text.java.AbstractProposalSorter;
66
import org.eclipse.jdt.ui.text.java.ContentAssistInvocationContext;
70
import org.eclipse.jdt.ui.text.java.ContentAssistInvocationContext;
67
71
68
import org.eclipse.jdt.internal.ui.JavaPlugin;
72
import org.eclipse.jdt.internal.ui.JavaPlugin;
Lines 277-292 Link Here
277
	 * @return the list of proposals
281
	 * @return the list of proposals
278
	 */
282
	 */
279
	private List<ICompletionProposal> collectProposals(ITextViewer viewer, int offset, IProgressMonitor monitor, ContentAssistInvocationContext context) {
283
	private List<ICompletionProposal> collectProposals(ITextViewer viewer, int offset, IProgressMonitor monitor, ContentAssistInvocationContext context) {
284
		boolean needsSortingAfterFiltering= false;
280
		List<ICompletionProposal> proposals= new ArrayList<ICompletionProposal>();
285
		List<ICompletionProposal> proposals= new ArrayList<ICompletionProposal>();
281
		List<CompletionProposalCategory> providers= getCategories();
286
		List<CompletionProposalCategory> providers= getCategories();
282
		for (Iterator<CompletionProposalCategory> it= providers.iterator(); it.hasNext();) {
287
		for (Iterator<CompletionProposalCategory> it= providers.iterator(); it.hasNext();) {
283
			CompletionProposalCategory cat= it.next();
288
			CompletionProposalCategory cat= it.next();
284
			List<ICompletionProposal> computed= cat.computeCompletionProposals(context, fPartition, new SubProgressMonitor(monitor, 1));
289
			List<ICompletionProposal> computed= cat.computeCompletionProposals(context, fPartition, new SubProgressMonitor(monitor, 1));
285
			proposals.addAll(computed);
290
			proposals.addAll(computed);
291
			needsSortingAfterFiltering= needsSortingAfterFiltering || (cat.isSortingAfterFilteringNeeded() && !computed.isEmpty());
286
			if (fErrorMessage == null)
292
			if (fErrorMessage == null)
287
				fErrorMessage= cat.getErrorMessage();
293
				fErrorMessage= cat.getErrorMessage();
288
		}
294
		}
289
295
		installProposalSorter(needsSortingAfterFiltering);
290
		return proposals;
296
		return proposals;
291
	}
297
	}
292
298
Lines 630-633 Link Here
630
			return (KeySequence) binding;
636
			return (KeySequence) binding;
631
		return null;
637
		return null;
632
    }
638
    }
639
640
	/**
641
	 * Installs the proposal sorter to be used by the content assistant for resorting proposals
642
	 * after filtering. Sets the sorter to the system's default sorter if
643
	 * <code>needsSortingAfterFiltering</code> is <code>true</code>, <code>null</code> otherwise.
644
	 * 
645
	 * @param needsSortingAfterFiltering the flag indicating whether a sorter should be passed to
646
	 *            the content assistant
647
	 * @since 3.8
648
	 * @see ProposalSorterRegistry#getCurrentSorter() the sorter used if <code>true</code>
649
	 */
650
	private void installProposalSorter(boolean needsSortingAfterFiltering) {
651
		if (!needsSortingAfterFiltering) {
652
			fAssistant.setSorter(null);
653
			return;
654
		}
655
656
		AbstractProposalSorter sorter= null;
657
		ProposalSorterHandle currentSorter= ProposalSorterRegistry.getDefault().getCurrentSorter();
658
		try {
659
			sorter= currentSorter.getSorter();
660
		} catch (InvalidRegistryObjectException x) {
661
			JavaPlugin.log(currentSorter.createExceptionStatus(x));
662
		} catch (CoreException x) {
663
			JavaPlugin.log(currentSorter.createExceptionStatus(x));
664
		} catch (RuntimeException x) {
665
			JavaPlugin.log(currentSorter.createExceptionStatus(x));
666
		}
667
		fAssistant.setSorter(sorter);
668
	}
669
633
}
670
}
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/ProposalSorterHandle.java (-5 / +6 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2011 IBM Corporation and others.
2
 * Copyright (c) 2005, 2012 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
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 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;
Lines 213-233 Link Here
213
		return stats;
214
		return stats;
214
	}
215
	}
215
216
216
	private Status createExceptionStatus(InvalidRegistryObjectException x) {
217
	Status createExceptionStatus(InvalidRegistryObjectException x) {
217
		// extension has become invalid - log & disable
218
		// extension has become invalid - log & disable
218
		String disable= createBlameMessage();
219
		String disable= createBlameMessage();
219
		String reason= JavaTextMessages.CompletionProposalComputerDescriptor_reason_invalid;
220
		String reason= JavaTextMessages.CompletionProposalComputerDescriptor_reason_invalid;
220
		return new Status(IStatus.INFO, JavaPlugin.getPluginId(), IStatus.OK, disable + " " + reason, x); //$NON-NLS-1$
221
		return new Status(IStatus.INFO, JavaPlugin.getPluginId(), IStatus.OK, disable + " " + reason, x); //$NON-NLS-1$
221
	}
222
	}
222
223
223
	private Status createExceptionStatus(CoreException x) {
224
	Status createExceptionStatus(CoreException x) {
224
		// unable to instantiate the extension - log & disable
225
		// unable to instantiate the extension - log & disable
225
		String disable= createBlameMessage();
226
		String disable= createBlameMessage();
226
		String reason= JavaTextMessages.CompletionProposalComputerDescriptor_reason_instantiation;
227
		String reason= JavaTextMessages.CompletionProposalComputerDescriptor_reason_instantiation;
227
		return new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IStatus.OK, disable + " " + reason, x); //$NON-NLS-1$
228
		return new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IStatus.OK, disable + " " + reason, x); //$NON-NLS-1$
228
	}
229
	}
229
230
230
	private Status createExceptionStatus(RuntimeException x) {
231
	Status createExceptionStatus(RuntimeException x) {
231
		// misbehaving extension - log & disable
232
		// misbehaving extension - log & disable
232
		String disable= createBlameMessage();
233
		String disable= createBlameMessage();
233
		String reason= JavaTextMessages.CompletionProposalComputerDescriptor_reason_runtime_ex;
234
		String reason= JavaTextMessages.CompletionProposalComputerDescriptor_reason_runtime_ex;
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/text/java/AbstractProposalSorter.java (-4 / +9 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2011 IBM Corporation and others.
2
 * Copyright (c) 2006, 2012 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
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 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 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
Lines 40-46 Link Here
40
	}
42
	}
41
43
42
	/**
44
	/**
43
	 * Called once before sorting.
45
	 * Called once before initial sorting starts the first time. Note that if a completion engine
46
	 * needs subsequent sorting of its proposals (e.g., after some proposals get filtered due to
47
	 * changes in the completion prefix), this method is <i>not</i> called again.
44
	 * <p>
48
	 * <p>
45
	 * Clients may override, the default implementation does nothing.
49
	 * Clients may override, the default implementation does nothing.
46
	 * </p>
50
	 * </p>
Lines 63-69 Link Here
63
	public abstract int compare(ICompletionProposal p1, ICompletionProposal p2);
67
	public abstract int compare(ICompletionProposal p1, ICompletionProposal p2);
64
68
65
	/**
69
	/**
66
	 * Called once after sorting.
70
	 * Called once after the initial sorting finished. Note that even if a completion engine causes
71
	 * a subsequent sorting of its proposals, this method is <i>not</i> called again.
67
	 * <p>
72
	 * <p>
68
	 * Clients may override, the default implementation does nothing.
73
	 * Clients may override, the default implementation does nothing.
69
	 * </p>
74
	 * </p>

Return to bug 350991