Java Code Examples for org.eclipse.xtext.GrammarUtil#containedActions()

The following examples show how to use org.eclipse.xtext.GrammarUtil#containedActions() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GrammarTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
private AbstractRule checkConcreteImplRule(Grammar grammar, String ruleName) {
	AbstractRule concreteRule = GrammarUtil.findRuleForName(grammar, ruleName);
	assertNotNull(concreteRule);
	EClassifier returnType = ((ParserRule)concreteRule).getType().getClassifier();
	String returnTypeName = getClassifierName(returnType);
	assertEquals(ruleName, returnTypeName + "_Impl");
	List<Assignment> assignments = GrammarUtil.containedAssignments(concreteRule);
	assertEquals(1, assignments.size());
	assertEquals("name", assignments.get(0).getFeature());
	assertEquals("=", assignments.get(0).getOperator());
	List<Action> containedActions = GrammarUtil.containedActions(concreteRule);
	assertEquals(1, containedActions.size());
	assertEquals(returnTypeName, getClassifierName(containedActions.get(0).getType().getClassifier()));
	List<Keyword> containedKeywords = GrammarUtil.containedKeywords(concreteRule);
	assertEquals(1, containedKeywords.size());
	assertEquals(returnTypeName, containedKeywords.get(0).getValue());
	return concreteRule;
}
 
Example 2
Source File: AbstractCodeElementExtractor.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Replies the assignment component with the given nazme in the given grammar component.
 *
 * @param grammarComponent the component to explore.
 * @param assignmentName the name of the assignment to search for.
 * @return the assignment component.
 */
protected static Action findAction(EObject grammarComponent, String assignmentName) {
	for (final Action action : GrammarUtil.containedActions(grammarComponent)) {
		if (GrammarUtil.isAssignedAction(action)) {
			if (Objects.equals(assignmentName, action.getFeature())) {
				return action;
			}
		}
	}
	return null;
}
 
Example 3
Source File: AbstractCodeElementExtractor.java    From sarl with Apache License 2.0 5 votes vote down vote up
@Override
public EClassifier getGeneratedTypeFor(AbstractRule rule) {
	final List<Action> actions = GrammarUtil.containedActions(rule);
	final EClassifier classifier;
	if (actions.isEmpty()) {
		classifier = rule.getType().getClassifier();
	} else {
		classifier = actions.get(0).getType().getClassifier();
	}
	return classifier;
}