use of org.eclipse.xtext.RuleCall in project xtext-core by eclipse.
the class GrammarPDAProviderTest method toPda.
private String toPda(final CharSequence rulesText) {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("grammar org.eclipse.xtext.serializer.GrammarPDAProviderTestLanguage with org.eclipse.xtext.common.Terminals");
_builder.newLine();
_builder.newLine();
_builder.append("generate GrammarPDAProviderTest \"http://www.eclipse.org/2010/tmf/xtext/GrammarPDAProviderTestLanguage\"");
_builder.newLine();
_builder.newLine();
_builder.append(rulesText);
_builder.newLineIfNotEmpty();
final Grammar grammar = this.parser.parse(_builder);
this.validator.assertNoErrors(grammar);
final SerializationContextMap<Pda<ISerState, RuleCall>> pdas = this.pdaProvider.getGrammarPDAs(grammar);
final Consumer<SerializationContextMap.Entry<Pda<ISerState, RuleCall>>> _function = (SerializationContextMap.Entry<Pda<ISerState, RuleCall>> it) -> {
this.assertNoLeakedGrammarElements(grammar, it.getValue());
};
pdas.values().forEach(_function);
final Function1<SerializationContextMap.Entry<Pda<ISerState, RuleCall>>, List<ISerializationContext>> _function_1 = (SerializationContextMap.Entry<Pda<ISerState, RuleCall>> it) -> {
return it.getContexts();
};
final Function1<ISerializationContext, String> _function_2 = (ISerializationContext it) -> {
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append(it);
_builder_1.append(":");
_builder_1.newLineIfNotEmpty();
_builder_1.append("\t");
String _listString = this.toListString(pdas.get(it));
_builder_1.append(_listString, "\t");
_builder_1.newLineIfNotEmpty();
return _builder_1.toString();
};
return IterableExtensions.join(ListExtensions.<ISerializationContext, String>map(IterableExtensions.<ISerializationContext>sort(Iterables.<ISerializationContext>concat(ListExtensions.<SerializationContextMap.Entry<Pda<ISerState, RuleCall>>, List<ISerializationContext>>map(pdas.values(), _function_1))), _function_2));
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.RuleCall in project xtext-core by eclipse.
the class XtextValidationTest method testCheckRuleCallInUnorderedGroup_02.
@Test
public void testCheckRuleCallInUnorderedGroup_02() 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.EBIG_DECIMAL);
ParserRule parserRule = XtextFactory.eINSTANCE.createParserRule();
parserRule.setType(typeRef);
ruleCall.setRule(parserRule);
unorderedGroup.getElements().add(ruleCall);
ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null, false, false);
validator.setMessageAcceptor(messageAcceptor);
validator.checkRuleCallInUnorderedGroup(ruleCall);
messageAcceptor.validate();
}
use of org.eclipse.xtext.RuleCall in project xtext-core by eclipse.
the class XtextValidationTest method testRuleCallAllowed_08_335692.
@Test
public void testRuleCallAllowed_08_335692() throws Exception {
String grammarAsText = "grammar test with org.eclipse.xtext.common.Terminals\n" + "generate test 'http://test'\n" + "Model : value=ID FRAGMENT;\n" + "SubModel : FRAGMENT;\n" + "terminal fragment FRAGMENT: ';';";
Grammar grammar = (Grammar) getModel(grammarAsText);
ParserRule datatypeRule = (ParserRule) grammar.getRules().get(1);
RuleCall ruleCall = (RuleCall) datatypeRule.getAlternatives();
XtextValidator validator = get(XtextValidator.class);
ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(ruleCall, true, false);
validator.setMessageAcceptor(messageAcceptor);
validator.checkUnassignedRuleCallAllowed(ruleCall);
validator.checkTerminalFragmentCalledFromTerminalRule(ruleCall);
messageAcceptor.validate();
}
use of org.eclipse.xtext.RuleCall in project xtext-core by eclipse.
the class XtextValidationTest method testRuleCallAllowed_09_335692.
@Test
public void testRuleCallAllowed_09_335692() throws Exception {
String grammarAsText = "grammar test with org.eclipse.xtext.common.Terminals\n" + "generate test 'http://test'\n" + "Model : value=ID FRAGMENT;\n" + "SubModel : FRAGMENT;\n" + "terminal fragment FRAGMENT: ';';";
Grammar grammar = (Grammar) getModel(grammarAsText);
ParserRule rule = (ParserRule) grammar.getRules().get(0);
RuleCall ruleCall = (RuleCall) ((Group) rule.getAlternatives()).getElements().get(1);
XtextValidator validator = get(XtextValidator.class);
ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(ruleCall, true, false);
validator.setMessageAcceptor(messageAcceptor);
validator.checkUnassignedRuleCallAllowed(ruleCall);
validator.checkTerminalFragmentCalledFromTerminalRule(ruleCall);
messageAcceptor.validate();
}
use of org.eclipse.xtext.RuleCall in project xtext-core by eclipse.
the class ContentAssistFragment2 method generateGenJavaProposalProvider.
protected GeneratedJavaFileAccess generateGenJavaProposalProvider() {
GeneratedJavaFileAccess _xblockexpression = null;
{
final Set<String> excludedFqnFeatureNames = this.getFQFeatureNamesToExclude(this.getGrammar());
final HashSet<String> processedNames = CollectionLiterals.<String>newHashSet();
final Function2<ArrayList<Assignment>, Assignment, ArrayList<Assignment>> _function = (ArrayList<Assignment> candidates, Assignment assignment) -> {
ArrayList<Assignment> _xblockexpression_1 = null;
{
final String fqFeatureName = this.getFQFeatureName(assignment);
if (((!processedNames.contains(fqFeatureName)) && (!excludedFqnFeatureNames.contains(fqFeatureName)))) {
processedNames.add(fqFeatureName);
candidates.add(assignment);
}
_xblockexpression_1 = candidates;
}
return _xblockexpression_1;
};
final ArrayList<Assignment> assignments = IterableExtensions.<Assignment, ArrayList<Assignment>>fold(GrammarUtil.containedAssignments(this.getGrammar()), CollectionLiterals.<Assignment>newArrayList(), _function);
final Function2<ArrayList<AbstractRule>, AbstractRule, ArrayList<AbstractRule>> _function_1 = (ArrayList<AbstractRule> candidates, AbstractRule rule) -> {
ArrayList<AbstractRule> _xblockexpression_1 = null;
{
final String fqnFeatureName = this.getFQFeatureName(rule);
if (((!processedNames.contains(fqnFeatureName)) && (!excludedFqnFeatureNames.contains(fqnFeatureName)))) {
processedNames.add(fqnFeatureName);
candidates.add(rule);
}
_xblockexpression_1 = candidates;
}
return _xblockexpression_1;
};
final ArrayList<AbstractRule> remainingRules = IterableExtensions.<AbstractRule, ArrayList<AbstractRule>>fold(this.getGrammar().getRules(), CollectionLiterals.<AbstractRule>newArrayList(), _function_1);
TypeReference _xifexpression = null;
boolean _isGenerateStub = this.isGenerateStub();
if (_isGenerateStub) {
_xifexpression = this.getGenProposalProviderClass(this.getGrammar());
} else {
_xifexpression = this.getProposalProviderClass(this.getGrammar());
}
final TypeReference genClass = _xifexpression;
GeneratedJavaFileAccess _createGeneratedJavaFile = this.fileAccessFactory.createGeneratedJavaFile(genClass);
final Procedure1<GeneratedJavaFileAccess> _function_2 = (GeneratedJavaFileAccess it) -> {
final TypeReference superClass = this.getGenProposalProviderSuperClass(this.getGrammar());
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("/**");
_builder.newLine();
_builder.append(" ");
_builder.append("* Represents a generated, default implementation of superclass {@link ");
_builder.append(superClass, " ");
_builder.append("}.");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("* Methods are dynamically dispatched on the first parameter, i.e., you can override them ");
_builder.newLine();
_builder.append(" ");
_builder.append("* with a more concrete subtype. ");
_builder.newLine();
_builder.append(" ");
_builder.append("*/");
_builder.newLine();
}
};
it.setTypeComment(_client);
StringConcatenationClient _client_1 = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("public ");
{
boolean _isGenerateStub = ContentAssistFragment2.this.isGenerateStub();
if (_isGenerateStub) {
_builder.append("abstract ");
}
}
_builder.append("class ");
String _simpleName = genClass.getSimpleName();
_builder.append(_simpleName);
_builder.append(" extends ");
_builder.append(superClass);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.newLine();
{
boolean _isEmpty = assignments.isEmpty();
boolean _not = (!_isEmpty);
if (_not) {
{
for (final Assignment assignment : assignments) {
_builder.append("\t");
StringConcatenationClient _handleAssignment = ContentAssistFragment2.this.handleAssignment(assignment);
_builder.append(_handleAssignment, "\t");
_builder.newLineIfNotEmpty();
}
}
_builder.newLine();
}
}
{
for (final AbstractRule rule : remainingRules) {
_builder.append("\t");
_builder.append("public void complete");
String _fQFeatureName = ContentAssistFragment2.this.getFQFeatureName(rule);
_builder.append(_fQFeatureName, "\t");
_builder.append("(");
_builder.append(EObject.class, "\t");
_builder.append(" model, ");
_builder.append(RuleCall.class, "\t");
_builder.append(" ruleCall, ");
TypeReference _contentAssistContextClass = ContentAssistFragment2.this.getContentAssistContextClass();
_builder.append(_contentAssistContextClass, "\t");
_builder.append(" context, ");
TypeReference _iCompletionProposalAcceptorClass = ContentAssistFragment2.this.getICompletionProposalAcceptorClass();
_builder.append(_iCompletionProposalAcceptorClass, "\t");
_builder.append(" acceptor) {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\t");
_builder.append("// subclasses may override");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
}
}
_builder.append("}");
_builder.newLine();
}
};
it.setContent(_client_1);
it.writeTo(this.getProjectConfig().getEclipsePlugin().getSrcGen());
};
_xblockexpression = ObjectExtensions.<GeneratedJavaFileAccess>operator_doubleArrow(_createGeneratedJavaFile, _function_2);
}
return _xblockexpression;
}
Aggregations