use of org.eclipse.xtext.Assignment in project xtext-core by eclipse.
the class GrammarParserTest method testAssignment.
@Test
public void testAssignment() throws Exception {
Assignment assignment = (Assignment) getModel("name=ID");
assertNotNull(assignment);
assertEquals("ID", ((RuleCall) assignment.getTerminal()).getRule().getName());
}
use of org.eclipse.xtext.Assignment in project xtext-core by eclipse.
the class XtextValidationTest method testCheckRuleCallInUnorderedGroup_05.
@Test
public void testCheckRuleCallInUnorderedGroup_05() throws Exception {
XtextValidator validator = get(XtextValidator.class);
UnorderedGroup unorderedGroup = XtextFactory.eINSTANCE.createUnorderedGroup();
RuleCall ruleCall = XtextFactory.eINSTANCE.createRuleCall();
TypeRef typeRef = XtextFactory.eINSTANCE.createTypeRef();
typeRef.setClassifier(EcorePackage.Literals.EOBJECT);
ParserRule parserRule = XtextFactory.eINSTANCE.createParserRule();
parserRule.setType(typeRef);
ruleCall.setRule(parserRule);
Assignment assignment = XtextFactory.eINSTANCE.createAssignment();
assignment.setTerminal(ruleCall);
unorderedGroup.getElements().add(assignment);
ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null, false, false);
validator.setMessageAcceptor(messageAcceptor);
validator.checkRuleCallInUnorderedGroup(ruleCall);
messageAcceptor.validate();
}
use of org.eclipse.xtext.Assignment in project xtext-core by eclipse.
the class XtextValidationTest method testKeywordWithSpaces.
@Test
public void testKeywordWithSpaces() throws Exception {
String grammarAsText = "grammar test with org.eclipse.xtext.common.Terminals\n" + "generate test 'http://test'\n" + "A: foo='a b c'; B: bar='x\ty'; terminal C: ' ';";
Grammar grammar = (Grammar) getModel(grammarAsText);
XtextValidator validator = get(XtextValidator.class);
ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null, false, true);
Assignment valueAssignment = (Assignment) grammar.getRules().get(0).getAlternatives();
Assignment valueAssignment2 = (Assignment) grammar.getRules().get(1).getAlternatives();
messageAcceptor.expectedContext(valueAssignment.getTerminal());
configureValidator(validator, messageAcceptor, valueAssignment);
validator.checkKeywordNoSpaces((Keyword) valueAssignment.getTerminal());
messageAcceptor.validate();
messageAcceptor = new ValidatingMessageAcceptor(null, false, true);
messageAcceptor.expectedContext(valueAssignment2.getTerminal());
configureValidator(validator, messageAcceptor, valueAssignment2);
validator.checkKeywordNoSpaces((Keyword) valueAssignment2.getTerminal());
messageAcceptor.validate();
messageAcceptor = new ValidatingMessageAcceptor(null, false, false);
configureValidator(validator, messageAcceptor, valueAssignment2);
validator.checkKeywordNoSpaces((Keyword) grammar.getRules().get(2).getAlternatives());
messageAcceptor.validate();
}
use of org.eclipse.xtext.Assignment in project xtext-core by eclipse.
the class NodeModelUtils method findActualSemanticObjectFor.
/**
* Returns the semantic object that is really associated with the actual container node of the given node. It
* handles the structural semantics that results from {@link Action Actions} and {@link RuleCall unassigned rule
* calls}.
*
* @return the semantic object that is really associated with the actual container node of the given node.
*/
/* @Nullable */
public static EObject findActualSemanticObjectFor(/* @Nullable */
INode node) {
if (node == null)
return null;
if (node.hasDirectSemanticElement())
return node.getSemanticElement();
EObject grammarElement = node.getGrammarElement();
ICompositeNode parent = node.getParent();
if (grammarElement == null)
return findActualSemanticObjectFor(parent);
Assignment assignment = GrammarUtil.containingAssignment(grammarElement);
if (assignment != null) {
if (GrammarUtil.isEObjectFragmentRule(GrammarUtil.containingRule(assignment))) {
EObject result = findActualSemanticObjectInChildren(node, grammarElement);
if (result != null)
return result;
}
if (parent.hasDirectSemanticElement())
return findActualSemanticObjectFor(parent);
INode sibling = parent.getFirstChild();
while (!sibling.equals(node)) {
EObject siblingGrammarElement = sibling.getGrammarElement();
if (siblingGrammarElement != null && GrammarUtil.containingAssignment(siblingGrammarElement) == null) {
if (GrammarUtil.isEObjectRuleCall(siblingGrammarElement)) {
return findActualSemanticObjectFor(sibling);
}
if (siblingGrammarElement.eClass() == XtextPackage.Literals.ACTION) {
return findActualSemanticObjectFor(sibling);
}
}
sibling = sibling.getNextSibling();
}
} else if (!GrammarUtil.isEObjectFragmentRuleCall(grammarElement)) {
EObject result = findActualSemanticObjectInChildren(node, grammarElement);
if (result != null)
return result;
}
return findActualSemanticObjectFor(parent);
}
use of org.eclipse.xtext.Assignment in project xtext-core by eclipse.
the class TreeConstructionReportImpl method getDiagnosticMessage.
protected String getDiagnosticMessage(AssignmentToken token) {
Assignment ass = (Assignment) token.getGrammarElement();
Object value = token.getEObjectConsumer().getConsumable(ass.getFeature(), false);
if (value == null) {
EStructuralFeature f = token.getEObjectConsumer().getEObject().eClass().getEStructuralFeature(ass.getFeature());
if (f == null)
return "The current object of type '" + token.getEObjectConsumer().getEObject().eClass().getName() + "' does not have a feature named '" + ass.getFeature() + "'";
String cls = f.getEContainingClass() == token.getEObjectConsumer().getEObject().eClass() ? f.getEContainingClass().getName() : f.getEContainingClass().getName() + "(" + token.getEObjectConsumer().getEObject().eClass().getName() + ")";
String feat = cls + "." + f.getName();
if (f.isMany()) {
int size = ((List<?>) token.getEObjectConsumer().getEObject().eGet(f)).size();
return "All " + size + " values of " + feat + " have been consumed. " + "More are needed to continue here.";
} else
return feat + " is not set.";
} else {
ErrorAcceptor err = new ErrorAcceptor();
for (RuleCall ruleCall : GrammarUtil.containedRuleCalls(token.getGrammarElement())) {
if (ruleCall.getRule() instanceof EnumRule) {
if (enumSerializer.isValid(token.getEObject(), ruleCall, value, err))
return null;
} else if (ruleCall.getRule().getType().getClassifier() instanceof EDataType) {
if (valueSerializer.isValid(token.getEObject(), ruleCall, value, err))
return null;
}
}
return err.getMessage();
}
}
Aggregations