summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormclay2008-10-30 17:34:48 (EDT)
committer sefftinge2008-10-30 17:34:48 (EDT)
commitba3d730c10ca8be2a06d969a42796d436eefece4 (patch)
tree110eea1d3efb1531fb59e04da1af963f36345165
parent5c029e21999fb3d47045984c03a1ac0ebef4d4f8 (diff)
downloadorg.eclipse.xtext-ba3d730c10ca8be2a06d969a42796d436eefece4.zip
org.eclipse.xtext-ba3d730c10ca8be2a06d969a42796d436eefece4.tar.gz
org.eclipse.xtext-ba3d730c10ca8be2a06d969a42796d436eefece4.tar.bz2
add: to callback completion proposal methods with custom return types (java model) we must add an eclipse buddy policy to be able to load classes of registered bundles
-rw-r--r--devtools/org.eclipse.xtext.reference.ui/META-INF/MANIFEST.MF1
-rw-r--r--plugins/org.eclipse.xtext.ui.common/META-INF/MANIFEST.MF1
-rw-r--r--plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/codecompletion/DefaultContentAssistProcessor.java73
3 files changed, 51 insertions, 24 deletions
diff --git a/devtools/org.eclipse.xtext.reference.ui/META-INF/MANIFEST.MF b/devtools/org.eclipse.xtext.reference.ui/META-INF/MANIFEST.MF
index f7d9565..248abd8 100644
--- a/devtools/org.eclipse.xtext.reference.ui/META-INF/MANIFEST.MF
+++ b/devtools/org.eclipse.xtext.reference.ui/META-INF/MANIFEST.MF
@@ -12,3 +12,4 @@ Require-Bundle: org.eclipse.xtext.reference,
Bundle-Vendor: eclipse.org
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-ActivationPolicy: lazy
+Eclipse-RegisterBuddy: org.eclipse.xtext.ui.common
diff --git a/plugins/org.eclipse.xtext.ui.common/META-INF/MANIFEST.MF b/plugins/org.eclipse.xtext.ui.common/META-INF/MANIFEST.MF
index 8e6c303..daff91d 100644
--- a/plugins/org.eclipse.xtext.ui.common/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.xtext.ui.common/META-INF/MANIFEST.MF
@@ -18,3 +18,4 @@ Export-Package: org.eclipse.xtext.ui.common.editor.codecompletion,
org.eclipse.xtext.ui.common.editor.tasks.dialogfields
Import-Package: org.eclipse.ui.texteditor.templates
Eclipse-RegisterBuddy: org.eclipse.xtext.log4j
+Eclipse-BuddyPolicy: registered
diff --git a/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/codecompletion/DefaultContentAssistProcessor.java b/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/codecompletion/DefaultContentAssistProcessor.java
index 9ab1f03..74d4185 100644
--- a/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/codecompletion/DefaultContentAssistProcessor.java
+++ b/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/codecompletion/DefaultContentAssistProcessor.java
@@ -12,6 +12,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
+import org.apache.log4j.Logger;
import org.eclipse.core.runtime.Assert;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
@@ -48,6 +49,9 @@ import org.eclipse.xtext.ui.core.editor.model.XtextDocument;
*/
public class DefaultContentAssistProcessor implements IContentAssistProcessor {
+ // logger available to subclasses
+ protected final Logger logger = Logger.getLogger(getClass());
+
@Inject
private IProposalProvider proposalProvider;
@@ -84,9 +88,9 @@ public class DefaultContentAssistProcessor implements IContentAssistProcessor {
List<ICompletionProposal> completionProposalList = new ArrayList<ICompletionProposal>();
- Set<AbstractElement> calculatePossibleElementSet = calculatePossibleElementSet(lastCompleteNode, grammarElement);
- for (Iterator<AbstractElement> iterator = calculatePossibleElementSet
- .iterator(); iterator.hasNext();) {
+ Set<AbstractElement> calculatePossibleElementSet = calculatePossibleElementSet(lastCompleteNode,
+ grammarElement);
+ for (Iterator<AbstractElement> iterator = calculatePossibleElementSet.iterator(); iterator.hasNext();) {
AbstractElement nextElement = iterator.next();
List<EObject> resolvedElementOrRuleList = resolveElement(nextElement);
@@ -96,7 +100,8 @@ public class DefaultContentAssistProcessor implements IContentAssistProcessor {
}
if (completionProposalList != null) {
- List<? extends ICompletionProposal> sortAndFilter = proposalProvider.sortAndFilter(completionProposalList);
+ List<? extends ICompletionProposal> sortAndFilter = proposalProvider
+ .sortAndFilter(completionProposalList);
return (ICompletionProposal[]) sortAndFilter.toArray(new ICompletionProposal[] {});
}
@@ -120,15 +125,36 @@ public class DefaultContentAssistProcessor implements IContentAssistProcessor {
Assignment assignment = (Assignment) abstractElement;
- ParserRule lexerRule = GrammarUtil.containingParserRule(assignment);
+ ParserRule parserRule = GrammarUtil.containingParserRule(assignment);
- Method method = findMethod(proposalProvider.getClass(),
- "complete" + firstLetterCapitalized(lexerRule.getName())
- + firstLetterCapitalized(assignment.getFeature()), Assignment.class, EObject.class,
+ Method method = findMethod(proposalProvider.getClass(), "complete"
+ + firstLetterCapitalized(parserRule.getName())
+ + firstLetterCapitalized(assignment.getFeature()), Assignment.class, EObject.class,
String.class, IDocument.class, int.class);
+ Object model = currentLeafNode;
+
+ // prefer assignment completion proposal method with custom return types (class) over EObject ones
+ if (parserRule.getType() != null) {
+
+ try {
+ Class<?> type = Class.forName(parserRule.getType().getAlias() + "."
+ + parserRule.getType().getName());
+ method = findMethod(proposalProvider.getClass(), "complete"
+ + firstLetterCapitalized(parserRule.getName())
+ + firstLetterCapitalized(assignment.getFeature()), Assignment.class, type,
+ String.class, IDocument.class, int.class);
+ model = ((CompositeNode) currentLeafNode.eContainer()).getElement();
+ }
+ catch (ClassNotFoundException e) {
+ if (logger.isTraceEnabled()) {
+ logger.trace("Custom type '" + parserRule.getType().getAlias() + "."
+ + parserRule.getType().getName() + "' could not be determined.");
+ }
+ }
+ }
- Collection<? extends ICompletionProposal> assignmentProposalList = invokeMethod(method, proposalProvider,
- assignment, currentLeafNode, prefix, xtextDocument, offset);
+ Collection<? extends ICompletionProposal> assignmentProposalList = invokeMethod(method,
+ proposalProvider, assignment, model, prefix, xtextDocument, offset);
if (null != assignmentProposalList) {
completionProposalList.addAll(assignmentProposalList);
@@ -138,32 +164,31 @@ public class DefaultContentAssistProcessor implements IContentAssistProcessor {
else if (abstractElement instanceof RuleCall) {
List<? extends ICompletionProposal> ruleCallProposalList = this.proposalProvider.completeRuleCall(
- (RuleCall) abstractElement, currentLeafNode, prefix, xtextDocument,offset);
+ (RuleCall) abstractElement, currentLeafNode, prefix, xtextDocument, offset);
if (null != ruleCallProposalList) {
completionProposalList.addAll(ruleCallProposalList);
}
-
+
AbstractRule calledRule = GrammarUtil.calledRule((RuleCall) abstractElement);
-
- if (calledRule.getType()!=null) {
-
+
+ if (calledRule.getType() != null) {
+
TypeRef typeRef = calledRule.getType();
- Method method = findMethod(proposalProvider.getClass(),
- "complete" + firstLetterCapitalized(typeRef.getAlias())
- + firstLetterCapitalized(typeRef.getName()), RuleCall.class, EObject.class,
- String.class, IDocument.class, int.class);
-
+ Method method = findMethod(proposalProvider.getClass(), "complete"
+ + firstLetterCapitalized(typeRef.getAlias()) + firstLetterCapitalized(typeRef.getName()),
+ RuleCall.class, EObject.class, String.class, IDocument.class, int.class);
+
Collection<? extends ICompletionProposal> proposalList = invokeMethod(method, proposalProvider,
abstractElement, currentLeafNode, prefix, xtextDocument, offset);
-
+
if (null != proposalList) {
completionProposalList.addAll(proposalList);
}
- }
-
+ }
+
}
}
}
@@ -401,7 +426,7 @@ public class DefaultContentAssistProcessor implements IContentAssistProcessor {
@SuppressWarnings("unchecked")
private final Collection<ICompletionProposal> invokeMethod(Method method, Object target, Object... args) {
-
+
try {
return (Collection<ICompletionProposal>) method.invoke(target, args);
}