summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormclay2008-12-04 16:17:28 (EST)
committer sefftinge2008-12-04 16:17:28 (EST)
commit35b9ff3ccc79b255c6676576507b0846526e7eef (patch)
tree62fa71f15f184912a8dc84d7519049a093fc68f0
parent42c53d34c3d54a355bdfb30adad1d70b6efe6d8b (diff)
downloadorg.eclipse.xtext-35b9ff3ccc79b255c6676576507b0846526e7eef.zip
org.eclipse.xtext-35b9ff3ccc79b255c6676576507b0846526e7eef.tar.gz
org.eclipse.xtext-35b9ff3ccc79b255c6676576507b0846526e7eef.tar.bz2
fix: invoke GrammarUtil.getReference with correct eClass (isnt always the same as the current context object e.g. contained [Abstract]Rule which start with a CrossRef)
-rw-r--r--plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/codecompletion/AbstractProposalProvider.java9
-rw-r--r--tests/org.eclipse.xtext.ui.common.tests/src/org/eclipse/xtext/ui/common/editor/codecompletion/DefaultContentAssistProcessorTest.java10
2 files changed, 12 insertions, 7 deletions
diff --git a/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/codecompletion/AbstractProposalProvider.java b/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/codecompletion/AbstractProposalProvider.java
index 330aa75..f360507 100644
--- a/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/codecompletion/AbstractProposalProvider.java
+++ b/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/codecompletion/AbstractProposalProvider.java
@@ -8,6 +8,7 @@ import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
+import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.jface.text.IDocument;
@@ -29,6 +30,7 @@ import org.eclipse.xtext.parsetree.CompositeNode;
import org.eclipse.xtext.parsetree.LeafNode;
import org.eclipse.xtext.parsetree.NodeUtil;
import org.eclipse.xtext.parsetree.ParseTreeUtil;
+import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.service.Inject;
import org.eclipse.xtext.util.Strings;
@@ -187,8 +189,11 @@ public abstract class AbstractProposalProvider implements IProposalProvider {
List<ICompletionProposal> completionProposalList = new ArrayList<ICompletionProposal>();
if (linkingCandidatesService != null) {
- //TODO the passed model is not always an instance of type, the cross reference is declared for.
- final EReference ref = GrammarUtil.getReference(crossReference, model.eClass());
+
+ final XtextResource xtextResource = (XtextResource) model.eResource();
+ final ParserRule containingParserRule = GrammarUtil.containingParserRule(crossReference);
+ final EClass eClass = xtextResource.getElementFactory().getEClass(GrammarUtil.getReturnTypeName(containingParserRule));
+ final EReference ref = GrammarUtil.getReference(crossReference, eClass);
final Iterable<IScopedElement> candidates = linkingCandidatesService.getLinkingCandidates(model, ref);
final String trimmedPrefix = prefix.trim();
for (IScopedElement candidate : candidates) {
diff --git a/tests/org.eclipse.xtext.ui.common.tests/src/org/eclipse/xtext/ui/common/editor/codecompletion/DefaultContentAssistProcessorTest.java b/tests/org.eclipse.xtext.ui.common.tests/src/org/eclipse/xtext/ui/common/editor/codecompletion/DefaultContentAssistProcessorTest.java
index dab3af5..377ed2a 100644
--- a/tests/org.eclipse.xtext.ui.common.tests/src/org/eclipse/xtext/ui/common/editor/codecompletion/DefaultContentAssistProcessorTest.java
+++ b/tests/org.eclipse.xtext.ui.common.tests/src/org/eclipse/xtext/ui/common/editor/codecompletion/DefaultContentAssistProcessorTest.java
@@ -110,9 +110,9 @@ public class DefaultContentAssistProcessorTest extends AbstractUiTest
.appendNl("R1 : (attr+=R2)*;")
.appendNl("R2 : (attr=INT)? prop=R3;")
.append("R3: attr+=").assertText(
-// "R1",
-// "R2",
-// "R3",
+ "R1",
+ "R2",
+ "R3",
"\"KeywordValueSTRING\"",
"\"KeywordValue\"",
"(",
@@ -126,8 +126,8 @@ public class DefaultContentAssistProcessorTest extends AbstractUiTest
.appendNl("abstract rules")
.appendNl("R1 ();")
.append("R2 rule :").assertText(
-// "R1",
-// "R2",
+ "R1",
+ "R2",
":" // TODO: Why does this proposal come up?
);
}