### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.ui Index: schema/javaCompletionProposalComputer.exsd =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/schema/javaCompletionProposalComputer.exsd,v retrieving revision 1.8 diff -u -r1.8 javaCompletionProposalComputer.exsd --- schema/javaCompletionProposalComputer.exsd 18 Apr 2008 06:23:21 -0000 1.8 +++ schema/javaCompletionProposalComputer.exsd 28 Dec 2011 15:27:58 -0000 @@ -7,13 +7,20 @@ This extension point allows to contribute Java completion proposal computers to participate in the content assist process of the Java editor. +<p> +This extension point supports the <code>enablement</code> tag. Properties to test on are: +<dl> +<li>project: type IJavaProject; the current project</li> +</dl> + + - + @@ -131,6 +138,9 @@ + + + @@ -204,7 +214,7 @@ - Copyright (c) 2006, 2008 IBM Corporation and others.<br> + Copyright (c) 2006, 2011 IBM Corporation and others.<br> All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a> Index: ui/org/eclipse/jdt/internal/ui/javaeditor/SpecificContentAssistAction.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/SpecificContentAssistAction.java,v retrieving revision 1.13 diff -u -r1.13 SpecificContentAssistAction.java --- ui/org/eclipse/jdt/internal/ui/javaeditor/SpecificContentAssistAction.java 27 Apr 2011 07:48:35 -0000 1.13 +++ ui/org/eclipse/jdt/internal/ui/javaeditor/SpecificContentAssistAction.java 28 Dec 2011 15:27:58 -0000 @@ -7,6 +7,8 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Paul Fullbright + * - content assist category enablement (https://bugs.eclipse.org/bugs/show_bug.cgi?id=345213) *******************************************************************************/ package org.eclipse.jdt.internal.ui.javaeditor; @@ -29,6 +31,8 @@ import org.eclipse.ui.texteditor.ITextEditor; import org.eclipse.ui.texteditor.IUpdate; +import org.eclipse.jdt.core.IJavaProject; + import org.eclipse.jdt.ui.text.IJavaPartitions; import org.eclipse.jdt.internal.ui.text.java.CompletionProposalCategory; @@ -101,11 +105,15 @@ private boolean computeEnablement(ITextEditor editor) { if (editor == null) return false; + ITextOperationTarget target= (ITextOperationTarget) editor.getAdapter(ITextOperationTarget.class); - boolean hasContentAssist= target != null && target.canDoOperation(ISourceViewer.CONTENTASSIST_PROPOSALS); - if (!hasContentAssist) + if (target == null || ! target.canDoOperation(ISourceViewer.CONTENTASSIST_PROPOSALS)) return false; - + + IJavaProject javaProject = EditorUtility.getJavaProject(editor.getEditorInput()); + if (! fCategory.matches(javaProject)) + return false; + ISelection selection= editor.getSelectionProvider().getSelection(); return isValidSelection(selection); } Index: ui/org/eclipse/jdt/internal/ui/text/java/CompletionProposalCategory.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/CompletionProposalCategory.java,v retrieving revision 1.19 diff -u -r1.19 CompletionProposalCategory.java --- ui/org/eclipse/jdt/internal/ui/text/java/CompletionProposalCategory.java 1 Mar 2011 11:50:36 -0000 1.19 +++ ui/org/eclipse/jdt/internal/ui/text/java/CompletionProposalCategory.java 28 Dec 2011 15:27:58 -0000 @@ -7,6 +7,8 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Paul Fullbright + * - content assist category enablement (https://bugs.eclipse.org/bugs/show_bug.cgi?id=345213) *******************************************************************************/ package org.eclipse.jdt.internal.ui.text.java; @@ -17,6 +19,12 @@ import org.osgi.framework.Bundle; +import org.eclipse.core.expressions.EvaluationContext; +import org.eclipse.core.expressions.EvaluationResult; +import org.eclipse.core.expressions.Expression; +import org.eclipse.core.expressions.ExpressionConverter; +import org.eclipse.core.expressions.ExpressionTagNames; + import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.IConfigurationElement; @@ -33,6 +41,8 @@ import org.eclipse.jface.text.contentassist.ICompletionProposal; import org.eclipse.jface.text.contentassist.IContextInformation; +import org.eclipse.jdt.core.IJavaProject; + import org.eclipse.jdt.internal.corext.util.Messages; import org.eclipse.jdt.ui.text.java.ContentAssistInvocationContext; @@ -54,6 +64,9 @@ private final IConfigurationElement fElement; /** The image descriptor for this category, or null if none specified. */ private final ImageDescriptor fImage; + + /** The enablement expression for this category, or null if none specified. */ + private final Expression fEnablementExpression; private boolean fIsSeparateCommand= true; private boolean fIsEnabled= true; @@ -74,7 +87,16 @@ fName= fId; else fName= name; - + + IConfigurationElement[] children= fElement.getChildren(ExpressionTagNames.ENABLEMENT); + if (children.length == 1) { + ExpressionConverter parser= ExpressionConverter.getDefault(); + fEnablementExpression = parser.perform(children[0]); + } + else { + fEnablementExpression = null; + } + String icon= element.getAttribute(ICON); ImageDescriptor img= null; if (icon != null) { @@ -94,6 +116,7 @@ fId= id; fName= name; fElement= null; + fEnablementExpression = null; fImage= null; } @@ -245,6 +268,35 @@ public void setSortOrder(int sortOrder) { fSortOrder= sortOrder; } + + /** + * Determines if the project matches any enablement expression defined on the extension. + * If there is no enablement expression, return true for any project. + * Otherwise, if the project is null, return false. + * + * @param javaProject - the project against which to test the enablement expression + * @return true if this category is to be included in content proposals + * @since 3.8 + */ + public boolean matches(IJavaProject javaProject) { + if (fEnablementExpression == null) { + return true; + } + + if (javaProject == null) { + return false; + } + + try { + EvaluationContext evalContext= new EvaluationContext(null, javaProject); + evalContext.addVariable("project", javaProject); //$NON-NLS-1$ + return fEnablementExpression.evaluate(evalContext) == EvaluationResult.TRUE; + } catch (CoreException e) { + JavaPlugin.log(e); + } + + return false; + } /** * Safely computes completion proposals of all computers of this category through their Index: ui/org/eclipse/jdt/internal/ui/text/java/ContentAssistProcessor.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/ContentAssistProcessor.java,v retrieving revision 1.26 diff -u -r1.26 ContentAssistProcessor.java --- ui/org/eclipse/jdt/internal/ui/text/java/ContentAssistProcessor.java 1 Mar 2011 11:50:36 -0000 1.26 +++ ui/org/eclipse/jdt/internal/ui/text/java/ContentAssistProcessor.java 28 Dec 2011 15:27:58 -0000 @@ -7,6 +7,8 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Paul Fullbright + * - content assist category enablement (https://bugs.eclipse.org/bugs/show_bug.cgi?id=345213) *******************************************************************************/ package org.eclipse.jdt.internal.ui.text.java; @@ -471,13 +473,24 @@ List included= new ArrayList(); for (Iterator it= fCategories.iterator(); it.hasNext();) { CompletionProposalCategory category= it.next(); - if (category.isIncluded() && category.hasComputers(fPartition)) + if (checkDefaultEnablement(category)) included.add(category); } return included; } /** + * Determine whether the category is enabled by default + * + * @param category - the category to check + * @return true if this category is enabled by default + * @since 3.8 + */ + protected boolean checkDefaultEnablement(CompletionProposalCategory category) { + return category.isIncluded() && category.hasComputers(fPartition); + } + + /** * Informs the user about the fact that there are no enabled categories in the default content * assist set and shows a link to the preferences. * @@ -565,12 +578,23 @@ ArrayList sorted= new ArrayList(); for (Iterator it= fCategories.iterator(); it.hasNext();) { CompletionProposalCategory category= it.next(); - if (category.isSeparateCommand() && category.hasComputers(fPartition)) + if (checkSeparateEnablement(category)) sorted.add(category); } Collections.sort(sorted, ORDER_COMPARATOR); return sorted; } + + /** + * Determine whether the category is enabled for separate use + * + * @param category - the category to check + * @return true if this category is enabled for separate use + * @since 3.8 + */ + protected boolean checkSeparateEnablement(CompletionProposalCategory category) { + return category.isSeparateCommand() && category.hasComputers(fPartition); + } private String createEmptyMessage() { return Messages.format(JavaTextMessages.ContentAssistProcessor_empty_message, new String[]{getCategoryLabel(fRepetition)}); Index: ui/org/eclipse/jdt/internal/ui/text/java/JavaCompletionProcessor.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/JavaCompletionProcessor.java,v retrieving revision 1.82 diff -u -r1.82 JavaCompletionProcessor.java --- ui/org/eclipse/jdt/internal/ui/text/java/JavaCompletionProcessor.java 1 Mar 2011 11:50:36 -0000 1.82 +++ ui/org/eclipse/jdt/internal/ui/text/java/JavaCompletionProcessor.java 28 Dec 2011 15:27:58 -0000 @@ -7,6 +7,8 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Paul Fullbright + * - content assist category enablement (https://bugs.eclipse.org/bugs/show_bug.cgi?id=345213) *******************************************************************************/ package org.eclipse.jdt.internal.ui.text.java; @@ -22,11 +24,14 @@ import org.eclipse.ui.IEditorPart; +import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.ui.text.java.ContentAssistInvocationContext; import org.eclipse.jdt.ui.text.java.JavaContentAssistInvocationContext; +import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility; + /** * Java completion processor. */ @@ -83,6 +88,26 @@ } /* + * @see ContentAssistProcessor#checkDefaultEnablement(CompletionProposalCategory) + */ + @Override + protected boolean checkDefaultEnablement(CompletionProposalCategory category) { + return super.checkDefaultEnablement(category) && category.matches(getJavaProject()); + } + + /* + * @see ContentAssistProcessor#checkSeparateEnablement(CompletionProposalCategory) + */ + @Override + protected boolean checkSeparateEnablement(CompletionProposalCategory category) { + return super.checkSeparateEnablement(category) && category.matches(getJavaProject()); + } + + private IJavaProject getJavaProject() { + return EditorUtility.getJavaProject(fEditor.getEditorInput()); + } + + /* * @see org.eclipse.jdt.internal.ui.text.java.ContentAssistProcessor#filterAndSort(java.util.List, org.eclipse.core.runtime.IProgressMonitor) */ @Override