use of org.eclipse.xtext.NamedArgument in project xtext-core by eclipse.
the class XtextLinkerTest method testNamedParameterAdjustment.
@Test
public void testNamedParameterAdjustment() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("grammar test.Lang with org.eclipse.xtext.common.Terminals");
_builder.newLine();
_builder.append("generate test \'http://test\'");
_builder.newLine();
_builder.append("Root<MyParam>: rule=Rule<true>;");
_builder.newLine();
_builder.append("Rule<MyParam>: name=ID child=Root<false>?;");
_builder.newLine();
final String grammarAsString = _builder.toString();
EObject _model = this.getModel(grammarAsString);
final Grammar grammar = ((Grammar) _model);
final ResourceSet resourceSet = grammar.eResource().getResourceSet();
final Resource otherResource = resourceSet.createResource(URI.createURI("other.xtext"));
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("grammar test.SubLang with test.Lang");
_builder_1.newLine();
_builder_1.append("import \'http://test\'");
_builder_1.newLine();
_builder_1.append("Root<MyParam>: rule=super::Rule<true>;");
_builder_1.newLine();
LazyStringInputStream _lazyStringInputStream = new LazyStringInputStream(_builder_1.toString());
otherResource.load(_lazyStringInputStream, null);
EObject _head = IterableExtensions.<EObject>head(otherResource.getContents());
final Grammar subGrammar = ((Grammar) _head);
AbstractRule _head_1 = IterableExtensions.<AbstractRule>head(subGrammar.getRules());
final ParserRule rootRule = ((ParserRule) _head_1);
AbstractRule _last = IterableExtensions.<AbstractRule>last(grammar.getRules());
final ParserRule parentRule = ((ParserRule) _last);
AbstractElement _alternatives = parentRule.getAlternatives();
AbstractElement _last_1 = IterableExtensions.<AbstractElement>last(((Group) _alternatives).getElements());
final Assignment lastAssignment = ((Assignment) _last_1);
AbstractElement _terminal = lastAssignment.getTerminal();
final RuleCall ruleCall = ((RuleCall) _terminal);
final NamedArgument argument = IterableExtensions.<NamedArgument>head(ruleCall.getArguments());
Assert.assertEquals(IterableExtensions.<Parameter>head(rootRule.getParameters()), argument.getParameter());
Condition _value = argument.getValue();
Assert.assertFalse(((LiteralCondition) _value).isTrue());
}
use of org.eclipse.xtext.NamedArgument in project xtext-core by eclipse.
the class XtextLinkerTest method testImplicitNamedParameterLinking_01.
@Test
public void testImplicitNamedParameterLinking_01() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("grammar test.Lang with org.eclipse.xtext.common.Terminals");
_builder.newLine();
_builder.append("generate test \'http://test\'");
_builder.newLine();
_builder.append("Root<MyParam>: rule=Rule<MyParam>;");
_builder.newLine();
_builder.append("Rule<MyParam>: name=ID child=Root<MyParam>?;");
_builder.newLine();
final String grammarAsString = _builder.toString();
EObject _model = this.getModel(grammarAsString);
final Grammar grammar = ((Grammar) _model);
AbstractRule _head = IterableExtensions.<AbstractRule>head(grammar.getRules());
final ParserRule rootRule = ((ParserRule) _head);
AbstractRule _last = IterableExtensions.<AbstractRule>last(grammar.getRules());
final ParserRule lastRule = ((ParserRule) _last);
AbstractElement _alternatives = lastRule.getAlternatives();
AbstractElement _last_1 = IterableExtensions.<AbstractElement>last(((Group) _alternatives).getElements());
final Assignment lastAssignment = ((Assignment) _last_1);
AbstractElement _terminal = lastAssignment.getTerminal();
final RuleCall ruleCall = ((RuleCall) _terminal);
final NamedArgument argument = IterableExtensions.<NamedArgument>head(ruleCall.getArguments());
Assert.assertEquals(IterableExtensions.<Parameter>head(rootRule.getParameters()), argument.getParameter());
Condition _value = argument.getValue();
Assert.assertEquals(IterableExtensions.<Parameter>head(lastRule.getParameters()), ((ParameterReference) _value).getParameter());
}
use of org.eclipse.xtext.NamedArgument in project xtext-core by eclipse.
the class AntlrGrammarGenUtil method getPredicatedElement.
/**
* @since 2.9
*/
public static AbstractElement getPredicatedElement(AbstractElement element) {
if (element.isPredicated()) {
return doGetPredicatedElement(element);
}
if (element instanceof Assignment) {
return getPredicatedElement(((Assignment) element).getTerminal());
}
if (element instanceof RuleCall) {
final RuleCall ruleCall = (RuleCall) element;
final AbstractRule calledRule = ruleCall.getRule();
Group group = (Group) calledRule.getAlternatives();
AbstractElement first = group.getElements().get(0);
AbstractElement result = getPredicatedElement(first);
if (ruleCall.getArguments().isEmpty()) {
return result;
}
EcoreUtil.Copier copier = new EcoreUtil.Copier() {
private static final long serialVersionUID = 1L;
@Override
public EObject copy(EObject eObject) {
if (eObject instanceof ParameterReference) {
ParameterReference paramRef = (ParameterReference) eObject;
Parameter parameter = paramRef.getParameter();
if (calledRule == GrammarUtil.containingRule(parameter)) {
for (NamedArgument givenArgument : ruleCall.getArguments()) {
if (givenArgument.getParameter() == parameter) {
EObject result = copy(givenArgument.getValue());
return result;
}
}
throw new IllegalStateException();
}
}
return super.copy(eObject);
}
};
AbstractElement clone = (AbstractElement) copier.copy(result);
copier.copyReferences();
return clone;
}
return doGetPredicatedElement(element);
}
Aggregations