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);
}
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);
}
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();
}
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();
}
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());
}
Aggregations