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 / +26 lines)
Lines 76-81 public final class CompletionProposalCategory { Link Here
76
	private int fSortOrder= 0xffff - 1;
76
	private int fSortOrder= 0xffff - 1;
77
	private String fLastError= null;
77
	private String fLastError= null;
78
78
79
	private boolean fRequiresReordering;
80
79
	CompletionProposalCategory(IConfigurationElement element, CompletionProposalComputerRegistry registry) throws CoreException {
81
	CompletionProposalCategory(IConfigurationElement element, CompletionProposalComputerRegistry registry) throws CoreException {
80
		fElement= element;
82
		fElement= element;
81
		fRegistry= registry;
83
		fRegistry= registry;
Lines 108-114 public final class CompletionProposalCategory { Link Here
108
			}
110
			}
109
		}
111
		}
110
		fImage= img;
112
		fImage= img;
111
113
		initalizeRequiresReordering();
112
	}
114
	}
113
115
114
	CompletionProposalCategory(String id, String name, CompletionProposalComputerRegistry registry) {
116
	CompletionProposalCategory(String id, String name, CompletionProposalComputerRegistry registry) {
Lines 118-123 public final class CompletionProposalCategory { Link Here
118
		fElement= null;
120
		fElement= null;
119
		fEnablementExpression = null;
121
		fEnablementExpression = null;
120
		fImage= null;
122
		fImage= null;
123
		initalizeRequiresReordering();
121
	}
124
	}
122
125
123
	private Bundle getBundle() {
126
	private Bundle getBundle() {
Lines 143-148 public final class CompletionProposalCategory { Link Here
143
	}
146
	}
144
147
145
	/**
148
	/**
149
	 * Iterates through all proposal computer descriptors iterated with this category and tests
150
	 * whether any of them requests proposal reordering.
151
	 */
152
	private void initalizeRequiresReordering() {
153
		for (CompletionProposalComputerDescriptor desc : fRegistry.getProposalComputerDescriptors()) {
154
			if (desc.getCategory() == this) {
155
				fRequiresReordering|= desc.requiresReordering();
156
			}
157
		}
158
	}
159
160
	/**
146
	 * Returns the identifier of the described extension.
161
	 * Returns the identifier of the described extension.
147
	 *
162
	 *
148
	 * @return Returns the id
163
	 * @return Returns the id
Lines 386-389 public final class CompletionProposalCategory { Link Here
386
		}
401
		}
387
	}
402
	}
388
403
404
	/**
405
	 * Returns whether any completion proposal computer associated with this category requires
406
	 * proposals to be reordered.
407
	 * 
408
	 * @return <code>true</code> if any completion proposal computer in this category requires
409
	 *         proposals to be reordered.
410
	 */
411
	public boolean requiresReordering() {
412
		return fRequiresReordering;
413
	}
389
}
414
}
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/CompletionProposalComputerDescriptor.java (+20 lines)
Lines 61-66 final class CompletionProposalComputerDescriptor { Link Here
61
	private static final String CLASS= "class"; //$NON-NLS-1$
61
	private static final String CLASS= "class"; //$NON-NLS-1$
62
	/** The extension schema name of the activate attribute. */
62
	/** The extension schema name of the activate attribute. */
63
	private static final String ACTIVATE= "activate"; //$NON-NLS-1$
63
	private static final String ACTIVATE= "activate"; //$NON-NLS-1$
64
	/** The extension schema name of the requiresReordering attribute. */
65
	private static final String REQUIRES_REORDERING= "requiresReordering"; //$NON-NLS-1$
64
	/** The extension schema name of the partition child elements. */
66
	/** The extension schema name of the partition child elements. */
65
	private static final String PARTITION= "partition"; //$NON-NLS-1$
67
	private static final String PARTITION= "partition"; //$NON-NLS-1$
66
	/** Set of Java partition types. */
68
	/** Set of Java partition types. */
Lines 131-136 final class CompletionProposalComputerDescriptor { Link Here
131
	 * @since 3.4
133
	 * @since 3.4
132
	 */
134
	 */
133
	boolean fTriedLoadingComputer= false;
135
	boolean fTriedLoadingComputer= false;
136
	/**
137
	 * Tells whether this proposal engine provides dynamic content that needs reordering of its
138
	 * proposals.
139
	 * 
140
	 * @since 3.8
141
	 */
142
	private boolean fRequiresReordering;
134
143
135
144
136
	/**
145
	/**
Lines 174-179 final class CompletionProposalComputerDescriptor { Link Here
174
		String activateAttribute= element.getAttribute(ACTIVATE);
183
		String activateAttribute= element.getAttribute(ACTIVATE);
175
		fActivate= Boolean.valueOf(activateAttribute).booleanValue();
184
		fActivate= Boolean.valueOf(activateAttribute).booleanValue();
176
185
186
		String reorderingAttribute= element.getAttribute(REQUIRES_REORDERING);
187
		fRequiresReordering= Boolean.valueOf(reorderingAttribute).booleanValue();
188
177
		fClass= element.getAttribute(CLASS);
189
		fClass= element.getAttribute(CLASS);
178
		checkNotNull(fClass, CLASS);
190
		checkNotNull(fClass, CLASS);
179
191
Lines 564-567 final class CompletionProposalComputerDescriptor { Link Here
564
        }
576
        }
565
    }
577
    }
566
578
579
	/**
580
	 * Returns the requiresReordering flag of the described extension.
581
	 * 
582
	 * @return the requiresReordering flag of the described extension
583
	 */
584
	public boolean requiresReordering() {
585
		return fRequiresReordering;
586
	}
567
}
587
}
(-)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 / +1 lines)
Lines 133-139 public final class ProposalSorterHandle { Link Here
133
	 * @throws InvalidRegistryObjectException if the extension is not valid any longer (e.g. due to
133
	 * @throws InvalidRegistryObjectException if the extension is not valid any longer (e.g. due to
134
	 *         plug-in unloading)
134
	 *         plug-in unloading)
135
	 */
135
	 */
136
	private synchronized AbstractProposalSorter getSorter() throws CoreException, InvalidRegistryObjectException {
136
	synchronized AbstractProposalSorter getSorter() throws CoreException, InvalidRegistryObjectException {
137
		if (fSorter == null)
137
		if (fSorter == null)
138
			fSorter= createSorter();
138
			fSorter= createSorter();
139
		return fSorter;
139
		return fSorter;
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/text/java/AbstractProposalSorter.java (-2 / +3 lines)
Lines 15-20 import java.util.Comparator; Link Here
15
import org.eclipse.core.runtime.IConfigurationElement;
15
import org.eclipse.core.runtime.IConfigurationElement;
16
16
17
import org.eclipse.jface.text.contentassist.ICompletionProposal;
17
import org.eclipse.jface.text.contentassist.ICompletionProposal;
18
import org.eclipse.jface.text.contentassist.ICompletionProposalSorter;
19
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