Search in sources :

Example 76 with Grammar

use of org.eclipse.xtext.Grammar in project xtext-core by eclipse.

the class NodeModelUtilsTest method testFindActualSemanticObjectFor_05.

@Test
public void testFindActualSemanticObjectFor_05() throws Exception {
    String grammarString = "grammar foo.Bar with org.eclipse.xtext.common.Terminals generate foo 'bar' Model:name=ID;";
    Grammar grammar = (Grammar) getModel(grammarString);
    ILeafNode leafNode = NodeModelUtils.findLeafNodeAtOffset(NodeModelUtils.getNode(grammar), grammarString.indexOf("ID"));
    EObject object = NodeModelUtils.findActualSemanticObjectFor(leafNode);
    assertTrue(object instanceof RuleCall);
}
Also used : ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) EObject(org.eclipse.emf.ecore.EObject) Grammar(org.eclipse.xtext.Grammar) RuleCall(org.eclipse.xtext.RuleCall) Test(org.junit.Test)

Example 77 with Grammar

use of org.eclipse.xtext.Grammar in project xtext-core by eclipse.

the class NodeModelUtilsTest method testFindNodesForFeature_Cardinality_1.

@Test
public void testFindNodesForFeature_Cardinality_1() throws Exception {
    Grammar grammar = (Grammar) getModel("grammar foo.Bar with org.eclipse.xtext.common.Terminals generate foo 'bar' Model: name+='foo'* name+='bar'*;");
    Group group = (Group) grammar.getRules().get(0).getAlternatives();
    List<INode> nodes = NodeModelUtils.findNodesForFeature(group, XtextPackage.eINSTANCE.getAbstractElement_Cardinality());
    assertEquals(0, nodes.size());
}
Also used : Group(org.eclipse.xtext.Group) INode(org.eclipse.xtext.nodemodel.INode) Grammar(org.eclipse.xtext.Grammar) Test(org.junit.Test)

Example 78 with Grammar

use of org.eclipse.xtext.Grammar in project xtext-core by eclipse.

the class NodeModelUtilsTest method testFindNodesForFeature_Cardinality_0.

@Test
public void testFindNodesForFeature_Cardinality_0() throws Exception {
    Grammar grammar = (Grammar) getModel("grammar foo.Bar with org.eclipse.xtext.common.Terminals generate foo 'bar' Model: name+='foo'*;");
    Assignment assignment = (Assignment) grammar.getRules().get(0).getAlternatives();
    List<INode> nodes = NodeModelUtils.findNodesForFeature(assignment, XtextPackage.eINSTANCE.getAbstractElement_Cardinality());
    assertEquals(1, nodes.size());
    assertEquals("*", nodes.get(0).getText().trim());
}
Also used : Assignment(org.eclipse.xtext.Assignment) INode(org.eclipse.xtext.nodemodel.INode) Grammar(org.eclipse.xtext.Grammar) Test(org.junit.Test)

Example 79 with Grammar

use of org.eclipse.xtext.Grammar in project xtext-core by eclipse.

the class NodeModelUtilsTest method testFindActualSemanticObjectFor_04.

@Test
public void testFindActualSemanticObjectFor_04() throws Exception {
    String grammarString = "grammar foo.Bar with org.eclipse.xtext.common.Terminals generate foo 'bar' Model:name=ID;";
    Grammar grammar = (Grammar) getModel(grammarString);
    ILeafNode leafNode = NodeModelUtils.findLeafNodeAtOffset(NodeModelUtils.getNode(grammar), grammarString.indexOf("name"));
    EObject object = NodeModelUtils.findActualSemanticObjectFor(leafNode);
    assertTrue(object instanceof Assignment);
}
Also used : Assignment(org.eclipse.xtext.Assignment) ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) EObject(org.eclipse.emf.ecore.EObject) Grammar(org.eclipse.xtext.Grammar) Test(org.junit.Test)

Example 80 with Grammar

use of org.eclipse.xtext.Grammar in project xtext-core by eclipse.

the class NodeModelUtilsTest method testFindActualSemanticObjectFor_07.

@Test
public void testFindActualSemanticObjectFor_07() throws Exception {
    String grammarString = "grammar foo.Bar with org.eclipse.xtext.common.Terminals generate foo 'bar' Model:(name=ID|name=STRING?)*;";
    Grammar grammar = (Grammar) getModel(grammarString);
    ILeafNode star = NodeModelUtils.findLeafNodeAtOffset(NodeModelUtils.getNode(grammar), grammarString.indexOf('*'));
    EObject object = NodeModelUtils.findActualSemanticObjectFor(star);
    assertTrue(object instanceof Alternatives);
    ILeafNode questionMark = NodeModelUtils.findLeafNodeAtOffset(NodeModelUtils.getNode(grammar), grammarString.indexOf('?'));
    object = NodeModelUtils.findActualSemanticObjectFor(questionMark);
    assertTrue(object instanceof Assignment);
}
Also used : Assignment(org.eclipse.xtext.Assignment) ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) EObject(org.eclipse.emf.ecore.EObject) Grammar(org.eclipse.xtext.Grammar) Alternatives(org.eclipse.xtext.Alternatives) Test(org.junit.Test)

Aggregations

Grammar (org.eclipse.xtext.Grammar)356 Test (org.junit.Test)273 ParserRule (org.eclipse.xtext.ParserRule)151 AbstractRule (org.eclipse.xtext.AbstractRule)106 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)101 EObject (org.eclipse.emf.ecore.EObject)70 AbstractXtextRuleInspectorTest (org.eclipse.xtext.xtext.AbstractXtextRuleInspectorTest)49 XtextResource (org.eclipse.xtext.resource.XtextResource)33 RuleCall (org.eclipse.xtext.RuleCall)28 StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)23 TypeReference (org.eclipse.xtext.xtext.generator.model.TypeReference)23 AbstractMetamodelDeclaration (org.eclipse.xtext.AbstractMetamodelDeclaration)21 Assignment (org.eclipse.xtext.Assignment)21 EPackage (org.eclipse.emf.ecore.EPackage)20 AbstractElement (org.eclipse.xtext.AbstractElement)17 TerminalRule (org.eclipse.xtext.TerminalRule)17 Resource (org.eclipse.emf.ecore.resource.Resource)16 EClassifier (org.eclipse.emf.ecore.EClassifier)13 InternalEObject (org.eclipse.emf.ecore.InternalEObject)13 ILeafNode (org.eclipse.xtext.nodemodel.ILeafNode)12