aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhbehrens2008-11-06 10:19:34 (EST)
committersefftinge2008-11-06 10:19:34 (EST)
commit239434c46cf5b5b1201d6112efacd7918eb37908 (patch)
tree6145df8904f01bda88632c115fa0f348cef1a5db
parentd8147b87cd15b781f80edd70a084221b82567c7f (diff)
downloadorg.eclipse.xtext-239434c46cf5b5b1201d6112efacd7918eb37908.zip
org.eclipse.xtext-239434c46cf5b5b1201d6112efacd7918eb37908.tar.gz
org.eclipse.xtext-239434c46cf5b5b1201d6112efacd7918eb37908.tar.bz2
* Applied Sebastians Patch from #254428 (partially)
* Fixed Tests for CrossLinking
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/crossrefs/CrossRefTest.java38
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parser/PartialParserTest.java37
-rwxr-xr-xtests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/tests/AbstractGeneratorTest.java5
3 files changed, 73 insertions, 7 deletions
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/crossrefs/CrossRefTest.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/crossrefs/CrossRefTest.java
index 53e0369..2d85ef1 100644
--- a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/crossrefs/CrossRefTest.java
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/crossrefs/CrossRefTest.java
@@ -6,7 +6,17 @@ import org.apache.log4j.Logger;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.xtext.AbstractElement;
+import org.eclipse.xtext.Assignment;
+import org.eclipse.xtext.CrossReference;
+import org.eclipse.xtext.Group;
+import org.eclipse.xtext.ParserRule;
import org.eclipse.xtext.crossref.ILinkingService;
+import org.eclipse.xtext.crossrefs.services.LangAGrammarAccess;
+import org.eclipse.xtext.parsetree.AbstractNode;
+import org.eclipse.xtext.parsetree.CompositeNode;
+import org.eclipse.xtext.parsetree.ParseTreeUtil;
+import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.service.ServiceRegistry;
import org.eclipse.xtext.tests.AbstractGeneratorTest;
import org.eclipse.xtext.util.Pair;
@@ -42,16 +52,30 @@ public class CrossRefTest extends AbstractGeneratorTest {
}
public void testGetLinkCandidates01() throws Exception {
- EObject model = getModel("type TypeA extends TypeB type TypeB extends TypeA AnotherType extends TypeA");
- assertEquals(3, linkingService.getLinkCandidates(model, null, "").size());
- assertEquals(2, linkingService.getLinkCandidates(model, null, "Type").size());
- assertEquals(1, linkingService.getLinkCandidates(model, null, "TypeA").size());
- assertEquals(0, linkingService.getLinkCandidates(model, null, "TypeC").size());
+ EObject model = getModel("type TypeA extends TypeB type TypeB extends TypeA type AnotherType extends TypeA");
+
+ assertWithXtend("3", "types.size", model);
+
+ EObject context = (EObject) invokeWithXtend("types.first()", model);
+ ParserRule prType = new LangAGrammarAccess().pr_Type();
+ Assignment asExtends = (Assignment)((Group)prType.getAlternatives()).getAbstractTokens().get(1);
+ CrossReference xref = (CrossReference) asExtends.getTerminal();
+
+ assertEquals(3, linkingService.getLinkCandidates(context, xref, "").size());
+ assertEquals(2, linkingService.getLinkCandidates(context, xref, "Type").size());
+ assertEquals(1, linkingService.getLinkCandidates(context, xref, "TypeA").size());
+ assertEquals(0, linkingService.getLinkCandidates(context, xref, "TypeC").size());
}
public void testGetLinkCandidates02() throws Exception {
- EObject model = getModel("type TypeA extends TypeB type TypeB extends TypeA AnotherType extends TypeA");
- List<Pair<String, URI>> candidates = linkingService.getLinkCandidates(model, null, "TypeA");
+ EObject model = getModel("type TypeA extends TypeB type TypeB extends TypeA type AnotherType extends TypeA");
+
+ EObject context = (EObject) invokeWithXtend("types.first()", model);
+ ParserRule prType = new LangAGrammarAccess().pr_Type();
+ Assignment asExtends = (Assignment)((Group)prType.getAlternatives()).getAbstractTokens().get(1);
+ CrossReference xref = (CrossReference) asExtends.getTerminal();
+
+ List<Pair<String, URI>> candidates = linkingService.getLinkCandidates(context, xref, "TypeA");
assertEquals(1, candidates.size());
Pair<String, URI> candidate = candidates.get(0);
assertEquals("TypeA", candidate.getFirstElement());
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parser/PartialParserTest.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parser/PartialParserTest.java
index 991837b..72d5956 100644
--- a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parser/PartialParserTest.java
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parser/PartialParserTest.java
@@ -8,13 +8,21 @@
*******************************************************************************/
package org.eclipse.xtext.parser;
+import java.util.Collections;
import java.util.Iterator;
+import org.eclipse.emf.common.util.AbstractTreeIterator;
+import org.eclipse.emf.common.util.TreeIterator;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.xtext.ParserRule;
import org.eclipse.xtext.parser.impl.PartialParsingPointers;
import org.eclipse.xtext.parser.impl.PartialParsingUtil;
+import org.eclipse.xtext.parsetree.AbstractNode;
import org.eclipse.xtext.parsetree.CompositeNode;
import org.eclipse.xtext.parsetree.LeafNode;
+import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.testlanguages.LookaheadLanguageStandaloneSetup;
+import org.eclipse.xtext.testlanguages.ReferenceGrammarStandaloneSetup;
import org.eclipse.xtext.testlanguages.SimpleExpressionsStandaloneSetup;
import org.eclipse.xtext.util.StringInputStream;
@@ -45,6 +53,35 @@ public class PartialParserTest extends AbstractPartialParserTest {
}
}
+ public void testGrammarElementAssigned() throws Exception {
+ with(ReferenceGrammarStandaloneSetup.class);
+ String model = "spielplatz 1 {kind (k 1)\n}";
+ XtextResource resource = getResourceFromString(model);
+ CompositeNode rootNode = resource.getParseResult().getRootNode();
+ checkGrammarAssigned(rootNode);
+ IParseResult reparse = PartialParsingUtil.reparse(getParser(), rootNode, model.length() - 2, 0, "\n");
+ rootNode = reparse.getRootNode();
+ checkGrammarAssigned(rootNode);
+ }
+
+ @SuppressWarnings("serial")
+ private void checkGrammarAssigned(CompositeNode rootNode) {
+ TreeIterator<AbstractNode> iter = new AbstractTreeIterator<AbstractNode>(rootNode) {
+ @Override
+ protected Iterator<? extends AbstractNode> getChildren(Object object) {
+ if (object instanceof CompositeNode)
+ return ((CompositeNode) object).getChildren().iterator();
+ return Collections.<AbstractNode>emptyList().iterator();
+ }
+ };
+ while(iter.hasNext()) {
+ AbstractNode node = iter.next();
+ assertNotNull(node.getGrammarElement());
+ EObject grammarElement = node.getGrammarElement();
+ assertEquals(node.getParent()==null, grammarElement instanceof ParserRule);
+ }
+ }
+
@SuppressWarnings("unchecked")
public void testNodeState() throws Exception {
with(SimpleExpressionsStandaloneSetup.class);
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/tests/AbstractGeneratorTest.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/tests/AbstractGeneratorTest.java
index 132dcd6..a22e004 100755
--- a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/tests/AbstractGeneratorTest.java
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/tests/AbstractGeneratorTest.java
@@ -39,6 +39,7 @@ import org.eclipse.xtext.util.StringInputStream;
/**
* @author Sven Efftinge - Initial contribution and API
+ * @author Heiko Behrens
*
*/
public abstract class AbstractGeneratorTest extends TestCase {
@@ -138,6 +139,10 @@ public abstract class AbstractGeneratorTest extends TestCase {
protected CompositeNode getRootNode(InputStream model) throws Exception {
XtextResource resource = getResource(model);
+ return getRootNode(resource);
+ }
+
+ protected CompositeNode getRootNode(XtextResource resource) {
return resource.getParseResult().getRootNode();
}