Search in sources :

Example 16 with Assignment

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

the class ValueSerializer method equalsOrReplacesNode.

@Override
public boolean equalsOrReplacesNode(EObject context, RuleCall ruleCall, Object value, INode node) {
    if (ruleCall != node.getGrammarElement())
        return false;
    Assignment ass = GrammarUtil.containingAssignment(ruleCall);
    if (GrammarUtil.isSingleAssignment(ass))
        return true;
    Object converted = converter.toValue(serialize(node), ruleCall.getRule().getName(), node);
    return converted != null && converted.equals(value);
}
Also used : Assignment(org.eclipse.xtext.Assignment) EObject(org.eclipse.emf.ecore.EObject)

Example 17 with Assignment

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

the class GrammarElementTitleSwitch method addAssignemnt.

protected String addAssignemnt(String result, AbstractElement ele) {
    if (!showAssignment)
        return result;
    Assignment ass = GrammarUtil.containingAssignment(ele);
    result = ass != null ? ass.getFeature() + ass.getOperator() + result : result;
    return addQualified(result, ele);
}
Also used : Assignment(org.eclipse.xtext.Assignment)

Example 18 with Assignment

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

the class XtextValidationTest method testCrossReferenceNotInAlternatives.

@Test
public void testCrossReferenceNotInAlternatives() throws Exception {
    String grammarAsText = "grammar test with org.eclipse.xtext.common.Terminals\n" + "generate test 'http://test'\n" + "A: foo=([A|ID]|[A|STRING]);";
    Grammar grammar = (Grammar) getModel(grammarAsText);
    XtextValidator validator = get(XtextValidator.class);
    ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null, true, false);
    Assignment assignment = (Assignment) grammar.getRules().get(0).getAlternatives();
    Alternatives alternatives = (Alternatives) assignment.getTerminal();
    messageAcceptor.expectedContext(alternatives);
    configureValidator(validator, messageAcceptor, alternatives);
    validator.checkCrossReferenceNotInAlternatives(alternatives);
    messageAcceptor.validate();
}
Also used : Assignment(org.eclipse.xtext.Assignment) Grammar(org.eclipse.xtext.Grammar) Alternatives(org.eclipse.xtext.Alternatives) Test(org.junit.Test)

Example 19 with Assignment

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

the class XtextValidationTest method testPredicatedUnorderedGroup_04.

@Test
public void testPredicatedUnorderedGroup_04() throws Exception {
    String grammarAsText = "grammar test with org.eclipse.xtext.common.Terminals\n" + "generate test 'http://test'\n" + "A: =>(name=ID value=B);\n" + "B: name=ID & value=STRING;";
    Grammar grammar = (Grammar) getModel(grammarAsText);
    XtextValidator validator = get(XtextValidator.class);
    ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null, true, false);
    Group predicatedGroup = (Group) grammar.getRules().get(0).getAlternatives();
    Group groupContent = (Group) predicatedGroup.getElements().get(0);
    Assignment valueAssignment = (Assignment) groupContent.getElements().get(1);
    messageAcceptor.expectedContext(grammar.getRules().get(0).getAlternatives(), valueAssignment.getTerminal(), grammar.getRules().get(1).getAlternatives());
    validator.setMessageAcceptor(messageAcceptor);
    validator.checkUnorderedGroupIsNotPredicated(grammar);
    messageAcceptor.validate();
}
Also used : Assignment(org.eclipse.xtext.Assignment) Group(org.eclipse.xtext.Group) UnorderedGroup(org.eclipse.xtext.UnorderedGroup) Grammar(org.eclipse.xtext.Grammar) Test(org.junit.Test)

Example 20 with Assignment

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

the class GrammarUtilTest method testGetReference.

@Test
public void testGetReference() throws Exception {
    this.with(LangATestLanguageStandaloneSetup.class);
    XtextResource resource = this.getResourceFromStringAndExpect("type A extends B", 1);
    Assignment asExtends = this.<LangATestLanguageGrammarAccess>get(LangATestLanguageGrammarAccess.class).getTypeAccess().getExtendsAssignment_2_1();
    AbstractElement _terminal = asExtends.getTerminal();
    CrossReference xref = ((CrossReference) _terminal);
    EObject _model = this.getModel(resource);
    Main model = ((Main) _model);
    EObject typeA = model.getTypes().get(0);
    EReference ref = GrammarUtil.getReference(xref, typeA.eClass());
    Assert.assertNotNull(ref);
    Assert.assertEquals("extends", ref.getName());
    Assert.assertFalse(ref.isMany());
    Assert.assertEquals(typeA.eClass(), ref.getEReferenceType());
}
Also used : Assignment(org.eclipse.xtext.Assignment) AbstractElement(org.eclipse.xtext.AbstractElement) EObject(org.eclipse.emf.ecore.EObject) LangATestLanguageGrammarAccess(org.eclipse.xtext.linking.services.LangATestLanguageGrammarAccess) CrossReference(org.eclipse.xtext.CrossReference) XtextResource(org.eclipse.xtext.resource.XtextResource) Main(org.eclipse.xtext.linking.langATestLanguage.Main) EReference(org.eclipse.emf.ecore.EReference) Test(org.junit.Test)

Aggregations

Assignment (org.eclipse.xtext.Assignment)60 EObject (org.eclipse.emf.ecore.EObject)27 Test (org.junit.Test)25 RuleCall (org.eclipse.xtext.RuleCall)22 Grammar (org.eclipse.xtext.Grammar)21 AbstractElement (org.eclipse.xtext.AbstractElement)15 ParserRule (org.eclipse.xtext.ParserRule)15 ILeafNode (org.eclipse.xtext.nodemodel.ILeafNode)14 Action (org.eclipse.xtext.Action)13 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)12 AbstractRule (org.eclipse.xtext.AbstractRule)12 Group (org.eclipse.xtext.Group)11 UnorderedGroup (org.eclipse.xtext.UnorderedGroup)9 Alternatives (org.eclipse.xtext.Alternatives)8 CrossReference (org.eclipse.xtext.CrossReference)7 ArrayList (java.util.ArrayList)6 EClass (org.eclipse.emf.ecore.EClass)6 InternalEObject (org.eclipse.emf.ecore.InternalEObject)6 NamedArgument (org.eclipse.xtext.NamedArgument)6 LiteralCondition (org.eclipse.xtext.LiteralCondition)5