summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Fullbright2012-01-09 07:19:11 (EST)
committer Dani Megert2012-01-09 07:19:11 (EST)
commit9538bb8c56138fb59335cd939a339e0cc7354a87 (patch)
tree469d0dd65791861d7515f7fbe34fb082638e2c9b
parente840eccd2cc9454521d8928c4b7835ab671c2ee8 (diff)
downloadeclipse.jdt.ui-9538bb8c56138fb59335cd939a339e0cc7354a87.zip
eclipse.jdt.ui-9538bb8c56138fb59335cd939a339e0cc7354a87.tar.gz
eclipse.jdt.ui-9538bb8c56138fb59335cd939a339e0cc7354a87.tar.bz2
Fixed bug 345213: [content assist][preferences] Add enablement to Java
completion proposal category extension point
-rw-r--r--org.eclipse.jdt.ui/schema/javaCompletionProposalComputer.exsd14
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/SpecificContentAssistAction.java15
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/SpecificContentAssistExecutor.java10
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/CompletionProposalCategory.java55
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/ContentAssistProcessor.java29
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/JavaCompletionProcessor.java26
6 files changed, 136 insertions, 13 deletions
diff --git a/org.eclipse.jdt.ui/schema/javaCompletionProposalComputer.exsd b/org.eclipse.jdt.ui/schema/javaCompletionProposalComputer.exsd
index 80f595e..c25fcf9 100644
--- a/org.eclipse.jdt.ui/schema/javaCompletionProposalComputer.exsd
+++ b/org.eclipse.jdt.ui/schema/javaCompletionProposalComputer.exsd
@@ -7,13 +7,20 @@
</appInfo>
<documentation>
This extension point allows to contribute Java completion proposal computers to participate in the content assist process of the Java editor.
+&lt;p&gt;
+This extension point supports the &lt;code&gt;enablement&lt;/code&gt; tag. Properties to test on are:
+&lt;dl&gt;
+&lt;li&gt;project: type IJavaProject; the current project&lt;/li&gt;
+&lt;/dl&gt;
</documentation>
</annotation>
+ <include schemaLocation="schema://org.eclipse.core.expressions/schema/expressionLanguage.exsd"/>
+
<element name="extension">
<annotation>
<appInfo>
- <meta.element labelAttribute="name"/>
+ <meta.element labelAttribute="name" />
</appInfo>
</annotation>
<complexType>
@@ -131,6 +138,9 @@ and must have a public 0-argument constructor.
</documentation>
</annotation>
<complexType>
+ <sequence>
+ <element ref="enablement" minOccurs="0" maxOccurs="1"/>
+ </sequence>
<attribute name="icon" type="string">
<annotation>
<documentation>
@@ -204,7 +214,7 @@ and must have a public 0-argument constructor.
<meta.section type="copyright"/>
</appInfo>
<documentation>
- Copyright (c) 2006, 2008 IBM Corporation and others.&lt;br&gt;
+ Copyright (c) 2006, 2012 IBM Corporation and others.&lt;br&gt;
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 &lt;a href=&quot;http://www.eclipse.org/legal/epl-v10.html&quot;&gt;http://www.eclipse.org/legal/epl-v10.html&lt;/a&gt;
</documentation>
</annotation>
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/SpecificContentAssistAction.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/SpecificContentAssistAction.java
index 884cc80..170e517 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/SpecificContentAssistAction.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/SpecificContentAssistAction.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2011 IBM Corporation and others.
+ * Copyright (c) 2005, 2012 IBM Corporation and others.
* 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
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Paul Fullbright <paul.fullbright@oracle.com> - content assist category enablement - http://bugs.eclipse.org/345213
*******************************************************************************/
package org.eclipse.jdt.internal.ui.javaeditor;
@@ -29,6 +30,8 @@ import org.eclipse.ui.texteditor.IDocumentProvider;
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 +104,15 @@ final class SpecificContentAssistAction extends Action implements IUpdate {
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);
}
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/SpecificContentAssistExecutor.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/SpecificContentAssistExecutor.java
index 536d645..0b567af 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/SpecificContentAssistExecutor.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/SpecificContentAssistExecutor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2011 IBM Corporation and others.
+ * Copyright (c) 2005, 2012 IBM Corporation and others.
* 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
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Paul Fullbright <paul.fullbright@oracle.com> - content assist category enablement - http://bugs.eclipse.org/345213
*******************************************************************************/
package org.eclipse.jdt.internal.ui.javaeditor;
@@ -20,6 +21,8 @@ import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.ui.texteditor.ITextEditor;
+import org.eclipse.jdt.core.IJavaProject;
+
import org.eclipse.jdt.internal.ui.text.java.CompletionProposalCategory;
import org.eclipse.jdt.internal.ui.text.java.CompletionProposalComputerRegistry;
@@ -53,6 +56,8 @@ public final class SpecificContentAssistExecutor {
Collection<CompletionProposalCategory> categories= fRegistry.getProposalCategories();
boolean[] inclusionState= new boolean[categories.size()];
boolean[] separateState= new boolean[categories.size()];
+ boolean[] enabledState= new boolean[categories.size()];
+ IJavaProject javaProject = EditorUtility.getJavaProject(editor.getEditorInput());
int i= 0;
for (Iterator<CompletionProposalCategory> it= categories.iterator(); it.hasNext(); i++) {
CompletionProposalCategory cat= it.next();
@@ -60,6 +65,8 @@ public final class SpecificContentAssistExecutor {
cat.setIncluded(cat.getId().equals(categoryId));
separateState[i]= cat.isSeparateCommand();
cat.setSeparateCommand(false);
+ enabledState[i]= cat.isEnabled();
+ cat.setEnabled(cat.isEnabled() && cat.matches(javaProject));
}
try {
@@ -72,6 +79,7 @@ public final class SpecificContentAssistExecutor {
CompletionProposalCategory cat= it.next();
cat.setIncluded(inclusionState[i]);
cat.setSeparateCommand(separateState[i]);
+ cat.setEnabled((enabledState[i]));
}
}
}
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/CompletionProposalCategory.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/CompletionProposalCategory.java
index bdcbdc7..bf37496 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/CompletionProposalCategory.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/CompletionProposalCategory.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2011 IBM Corporation and others.
+ * Copyright (c) 2005, 2012 IBM Corporation and others.
* 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
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Paul Fullbright <paul.fullbright@oracle.com> - content assist category enablement - http://bugs.eclipse.org/345213
*******************************************************************************/
package org.eclipse.jdt.internal.ui.text.java;
@@ -17,6 +18,12 @@ import java.util.List;
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 +40,8 @@ import org.eclipse.jface.resource.ImageDescriptor;
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 +63,9 @@ public final class CompletionProposalCategory {
private final IConfigurationElement fElement;
/** The image descriptor for this category, or <code>null</code> if none specified. */
private final ImageDescriptor fImage;
+
+ /** The enablement expression for this category, or <code>null</code> if none specified. */
+ private final Expression fEnablementExpression;
private boolean fIsSeparateCommand= true;
private boolean fIsEnabled= true;
@@ -74,7 +86,16 @@ public final class CompletionProposalCategory {
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 +115,7 @@ public final class CompletionProposalCategory {
fId= id;
fName= name;
fElement= null;
+ fEnablementExpression = null;
fImage= null;
}
@@ -245,6 +267,35 @@ public final class CompletionProposalCategory {
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
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/ContentAssistProcessor.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/ContentAssistProcessor.java
index 4df2e1b..bb717d4 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/ContentAssistProcessor.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/ContentAssistProcessor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2011 IBM Corporation and others.
+ * Copyright (c) 2005, 2012 IBM Corporation and others.
* 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
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Paul Fullbright <paul.fullbright@oracle.com> - content assist category enablement - http://bugs.eclipse.org/345213
*******************************************************************************/
package org.eclipse.jdt.internal.ui.text.java;
@@ -471,13 +472,24 @@ public class ContentAssistProcessor implements IContentAssistProcessor {
List<CompletionProposalCategory> included= new ArrayList<CompletionProposalCategory>();
for (Iterator<CompletionProposalCategory> 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 +577,23 @@ public class ContentAssistProcessor implements IContentAssistProcessor {
ArrayList<CompletionProposalCategory> sorted= new ArrayList<CompletionProposalCategory>();
for (Iterator<CompletionProposalCategory> 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)});
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/JavaCompletionProcessor.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/JavaCompletionProcessor.java
index c94a720..3b5771d 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/JavaCompletionProcessor.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/JavaCompletionProcessor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2012 IBM Corporation and others.
* 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
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Paul Fullbright <paul.fullbright@oracle.com> - content assist category enablement - http://bugs.eclipse.org/345213
*******************************************************************************/
package org.eclipse.jdt.internal.ui.text.java;
@@ -22,11 +23,14 @@ import org.eclipse.jface.text.contentassist.IContextInformationValidator;
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 +87,26 @@ public class JavaCompletionProcessor extends ContentAssistProcessor {
}
/*
+ * @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