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 (-30 / +50 lines)
Lines 52-58 import org.eclipse.jdt.internal.ui.JavaPlugin; Link Here
52
52
53
/**
53
/**
54
 * Describes a category extension to the "javaCompletionProposalComputer" extension point.
54
 * Describes a category extension to the "javaCompletionProposalComputer" extension point.
55
 *
55
 * 
56
 * @since 3.2
56
 * @since 3.2
57
 */
57
 */
58
public final class CompletionProposalCategory {
58
public final class CompletionProposalCategory {
Lines 60-81 public final class CompletionProposalCategory { Link Here
60
	private static final String ICON= "icon"; //$NON-NLS-1$
60
	private static final String ICON= "icon"; //$NON-NLS-1$
61
61
62
	private final String fId;
62
	private final String fId;
63
63
	private final String fName;
64
	private final String fName;
65
64
	private final IConfigurationElement fElement;
66
	private final IConfigurationElement fElement;
67
65
	/** The image descriptor for this category, or <code>null</code> if none specified. */
68
	/** The image descriptor for this category, or <code>null</code> if none specified. */
66
	private final ImageDescriptor fImage;
69
	private final ImageDescriptor fImage;
67
	
70
68
	/** The enablement expression for this category, or <code>null</code> if none specified. */
71
	/** The enablement expression for this category, or <code>null</code> if none specified. */
69
	private final Expression fEnablementExpression;
72
	private final Expression fEnablementExpression;
70
73
71
	private boolean fIsSeparateCommand= true;
74
	private boolean fIsSeparateCommand= true;
75
72
	private boolean fIsEnabled= true;
76
	private boolean fIsEnabled= true;
77
73
	private boolean fIsIncluded= true;
78
	private boolean fIsIncluded= true;
79
74
	private final CompletionProposalComputerRegistry fRegistry;
80
	private final CompletionProposalComputerRegistry fRegistry;
75
81
76
	private int fSortOrder= 0xffff - 1;
82
	private int fSortOrder= 0xffff - 1;
83
77
	private String fLastError= null;
84
	private String fLastError= null;
78
85
86
	private boolean fRequiresReordering;
87
79
	CompletionProposalCategory(IConfigurationElement element, CompletionProposalComputerRegistry registry) throws CoreException {
88
	CompletionProposalCategory(IConfigurationElement element, CompletionProposalComputerRegistry registry) throws CoreException {
80
		fElement= element;
89
		fElement= element;
81
		fRegistry= registry;
90
		fRegistry= registry;
Lines 87-102 public final class CompletionProposalCategory { Link Here
87
			fName= fId;
96
			fName= fId;
88
		else
97
		else
89
			fName= name;
98
			fName= name;
90
		
99
91
		IConfigurationElement[] children= fElement.getChildren(ExpressionTagNames.ENABLEMENT);
100
		IConfigurationElement[] children= fElement.getChildren(ExpressionTagNames.ENABLEMENT);
92
		if (children.length == 1) {
101
		if (children.length == 1) {
93
			ExpressionConverter parser= ExpressionConverter.getDefault();
102
			ExpressionConverter parser= ExpressionConverter.getDefault();
94
			fEnablementExpression = parser.perform(children[0]);
103
			fEnablementExpression= parser.perform(children[0]);
95
		}
104
		}
96
		else {
105
		else {
97
			fEnablementExpression = null;
106
			fEnablementExpression= null;
98
		}
107
		}
99
		
108
100
		String icon= element.getAttribute(ICON);
109
		String icon= element.getAttribute(ICON);
101
		ImageDescriptor img= null;
110
		ImageDescriptor img= null;
102
		if (icon != null) {
111
		if (icon != null) {
Lines 108-114 public final class CompletionProposalCategory { Link Here
108
			}
117
			}
109
		}
118
		}
110
		fImage= img;
119
		fImage= img;
111
112
	}
120
	}
113
121
114
	CompletionProposalCategory(String id, String name, CompletionProposalComputerRegistry registry) {
122
	CompletionProposalCategory(String id, String name, CompletionProposalComputerRegistry registry) {
Lines 116-122 public final class CompletionProposalCategory { Link Here
116
		fId= id;
124
		fId= id;
117
		fName= name;
125
		fName= name;
118
		fElement= null;
126
		fElement= null;
119
		fEnablementExpression = null;
127
		fEnablementExpression= null;
120
		fImage= null;
128
		fImage= null;
121
	}
129
	}
122
130
Lines 128-134 public final class CompletionProposalCategory { Link Here
128
136
129
	/**
137
	/**
130
	 * Checks that the given attribute value is not <code>null</code>.
138
	 * Checks that the given attribute value is not <code>null</code>.
131
	 *
139
	 * 
132
	 * @param value the element to be checked
140
	 * @param value the element to be checked
133
	 * @param attribute the attribute
141
	 * @param attribute the attribute
134
	 * @throws CoreException if <code>value</code> is <code>null</code>
142
	 * @throws CoreException if <code>value</code> is <code>null</code>
Lines 142-150 public final class CompletionProposalCategory { Link Here
142
		}
150
		}
143
	}
151
	}
144
152
153
145
	/**
154
	/**
146
	 * Returns the identifier of the described extension.
155
	 * Returns the identifier of the described extension.
147
	 *
156
	 * 
148
	 * @return Returns the id
157
	 * @return Returns the id
149
	 */
158
	 */
150
	public String getId() {
159
	public String getId() {
Lines 153-159 public final class CompletionProposalCategory { Link Here
153
162
154
	/**
163
	/**
155
	 * Returns the name of the described extension.
164
	 * Returns the name of the described extension.
156
	 *
165
	 * 
157
	 * @return Returns the name
166
	 * @return Returns the name
158
	 */
167
	 */
159
	public String getName() {
168
	public String getName() {
Lines 161-170 public final class CompletionProposalCategory { Link Here
161
	}
170
	}
162
171
163
	/**
172
	/**
164
	 * Returns the name of the described extension
173
	 * Returns the name of the described extension without mnemonic hint in order to be displayed in
165
	 * without mnemonic hint in order to be displayed
174
	 * a message.
166
	 * in a message.
175
	 * 
167
	 *
168
	 * @return Returns the name
176
	 * @return Returns the name
169
	 */
177
	 */
170
	public String getDisplayName() {
178
	public String getDisplayName() {
Lines 173-179 public final class CompletionProposalCategory { Link Here
173
181
174
	/**
182
	/**
175
	 * Returns the image descriptor of the described category.
183
	 * Returns the image descriptor of the described category.
176
	 *
184
	 * 
177
	 * @return the image descriptor of the described category
185
	 * @return the image descriptor of the described category
178
	 */
186
	 */
179
	public ImageDescriptor getImageDescriptor() {
187
	public ImageDescriptor getImageDescriptor() {
Lines 182-188 public final class CompletionProposalCategory { Link Here
182
190
183
	/**
191
	/**
184
	 * Sets the separate command state of the category.
192
	 * Sets the separate command state of the category.
185
	 *
193
	 * 
186
	 * @param enabled the new enabled state.
194
	 * @param enabled the new enabled state.
187
	 */
195
	 */
188
	public void setSeparateCommand(boolean enabled) {
196
	public void setSeparateCommand(boolean enabled) {
Lines 191-197 public final class CompletionProposalCategory { Link Here
191
199
192
	/**
200
	/**
193
	 * Returns the enablement state of the category.
201
	 * Returns the enablement state of the category.
194
	 *
202
	 * 
195
	 * @return the enablement state of the category
203
	 * @return the enablement state of the category
196
	 */
204
	 */
197
	public boolean isSeparateCommand() {
205
	public boolean isSeparateCommand() {
Lines 223-229 public final class CompletionProposalCategory { Link Here
223
	/**
231
	/**
224
	 * Returns <code>true</code> if the category contains any computers, <code>false</code>
232
	 * Returns <code>true</code> if the category contains any computers, <code>false</code>
225
	 * otherwise.
233
	 * otherwise.
226
	 *
234
	 * 
227
	 * @return <code>true</code> if the category contains any computers, <code>false</code>
235
	 * @return <code>true</code> if the category contains any computers, <code>false</code>
228
	 *         otherwise
236
	 *         otherwise
229
	 */
237
	 */
Lines 238-246 public final class CompletionProposalCategory { Link Here
238
	}
246
	}
239
247
240
	/**
248
	/**
241
	 * Returns <code>true</code> if the category contains any computers in the given partition, <code>false</code>
249
	 * Returns <code>true</code> if the category contains any computers in the given partition,
242
	 * otherwise.
250
	 * <code>false</code> otherwise.
243
	 *
251
	 * 
244
	 * @param partition the partition
252
	 * @param partition the partition
245
	 * @return <code>true</code> if the category contains any computers, <code>false</code>
253
	 * @return <code>true</code> if the category contains any computers, <code>false</code>
246
	 *         otherwise
254
	 *         otherwise
Lines 268-274 public final class CompletionProposalCategory { Link Here
268
	public void setSortOrder(int sortOrder) {
276
	public void setSortOrder(int sortOrder) {
269
		fSortOrder= sortOrder;
277
		fSortOrder= sortOrder;
270
	}
278
	}
271
	
279
272
	/**
280
	/**
273
	 * Determines if the project matches any enablement expression defined on the extension.
281
	 * Determines if the project matches any enablement expression defined on the extension.
274
	 * 
282
	 * 
Lines 283-293 public final class CompletionProposalCategory { Link Here
283
		if (fEnablementExpression == null) {
291
		if (fEnablementExpression == null) {
284
			return true;
292
			return true;
285
		}
293
		}
286
		
294
287
		if (javaProject == null) {
295
		if (javaProject == null) {
288
			return false;
296
			return false;
289
		}
297
		}
290
		
298
291
		try {
299
		try {
292
			EvaluationContext evalContext= new EvaluationContext(null, javaProject);
300
			EvaluationContext evalContext= new EvaluationContext(null, javaProject);
293
			evalContext.addVariable("project", javaProject); //$NON-NLS-1$
301
			evalContext.addVariable("project", javaProject); //$NON-NLS-1$
Lines 295-301 public final class CompletionProposalCategory { Link Here
295
		} catch (CoreException e) {
303
		} catch (CoreException e) {
296
			JavaPlugin.log(e);
304
			JavaPlugin.log(e);
297
		}
305
		}
298
		
306
299
		return false;
307
		return false;
300
	}
308
	}
301
309
Lines 303-309 public final class CompletionProposalCategory { Link Here
303
	 * Safely computes completion proposals of all computers of this category through their
311
	 * Safely computes completion proposals of all computers of this category through their
304
	 * extension. If an extension is disabled, throws an exception or otherwise does not adhere to
312
	 * extension. If an extension is disabled, throws an exception or otherwise does not adhere to
305
	 * the contract described in {@link IJavaCompletionProposalComputer}, it is disabled.
313
	 * the contract described in {@link IJavaCompletionProposalComputer}, it is disabled.
306
	 *
314
	 * 
307
	 * @param context the invocation context passed on to the extension
315
	 * @param context the invocation context passed on to the extension
308
	 * @param partition the partition type where to invocation occurred
316
	 * @param partition the partition type where to invocation occurred
309
	 * @param monitor the progress monitor passed on to the extension
317
	 * @param monitor the progress monitor passed on to the extension
Lines 328-334 public final class CompletionProposalCategory { Link Here
328
	 * Safely computes context information objects of all computers of this category through their
336
	 * Safely computes context information objects of all computers of this category through their
329
	 * extension. If an extension is disabled, throws an exception or otherwise does not adhere to
337
	 * extension. If an extension is disabled, throws an exception or otherwise does not adhere to
330
	 * the contract described in {@link IJavaCompletionProposalComputer}, it is disabled.
338
	 * the contract described in {@link IJavaCompletionProposalComputer}, it is disabled.
331
	 *
339
	 * 
332
	 * @param context the invocation context passed on to the extension
340
	 * @param context the invocation context passed on to the extension
333
	 * @param partition the partition type where to invocation occurred
341
	 * @param partition the partition type where to invocation occurred
334
	 * @param monitor the progress monitor passed on to the extension
342
	 * @param monitor the progress monitor passed on to the extension
Lines 351-357 public final class CompletionProposalCategory { Link Here
351
359
352
	/**
360
	/**
353
	 * Returns the error message from the computers in this category.
361
	 * Returns the error message from the computers in this category.
354
	 *
362
	 * 
355
	 * @return the error message from the computers in this category
363
	 * @return the error message from the computers in this category
356
	 */
364
	 */
357
	public String getErrorMessage() {
365
	public String getErrorMessage() {
Lines 365-372 public final class CompletionProposalCategory { Link Here
365
		List<CompletionProposalComputerDescriptor> descriptors= new ArrayList<CompletionProposalComputerDescriptor>(fRegistry.getProposalComputerDescriptors());
373
		List<CompletionProposalComputerDescriptor> descriptors= new ArrayList<CompletionProposalComputerDescriptor>(fRegistry.getProposalComputerDescriptors());
366
		for (Iterator<CompletionProposalComputerDescriptor> it= descriptors.iterator(); it.hasNext();) {
374
		for (Iterator<CompletionProposalComputerDescriptor> it= descriptors.iterator(); it.hasNext();) {
367
			CompletionProposalComputerDescriptor desc= it.next();
375
			CompletionProposalComputerDescriptor desc= it.next();
368
			if (desc.getCategory() == this)
376
			if (desc.getCategory() == this){
369
				desc.sessionStarted();
377
				desc.sessionStarted();
378
				fRequiresReordering|= desc.requiresReordering();
379
			}
370
			if (fLastError == null)
380
			if (fLastError == null)
371
				fLastError= desc.getErrorMessage();
381
				fLastError= desc.getErrorMessage();
372
		}
382
		}
Lines 386-389 public final class CompletionProposalCategory { Link Here
386
		}
396
		}
387
	}
397
	}
388
398
399
	/**
400
	 * Returns whether any completion proposal computer associated with this category requires
401
	 * proposals to be reordered.
402
	 * 
403
	 * @return <code>true</code> if any completion proposal computer in this category requires
404
	 *         proposals to be reordered.
405
	 */
406
	public boolean requiresReordering() {
407
		return fRequiresReordering;
408
	}
389
}
409
}
(-)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