use of org.eclipse.xtext.AbstractRule in project xtext-core by eclipse.
the class GrammarUtilTest method testFindCurrentType_06.
@Test
public void testFindCurrentType_06() throws Exception {
this.with(XtextStandaloneSetup.class);
StringConcatenation _builder = new StringConcatenation();
_builder.append("grammar myLang with org.eclipse.xtext.common.Terminals");
_builder.newLine();
_builder.append("generate g \'http://1\'");
_builder.newLine();
_builder.append("Rule:");
_builder.newLine();
_builder.append("\t");
_builder.append("Fragment;");
_builder.newLine();
_builder.append("fragment Fragment returns Rule:");
_builder.newLine();
_builder.append(" ");
_builder.append("name=ID Fragment?");
_builder.newLine();
_builder.append(";");
_builder.newLine();
String model = _builder.toString();
final XtextResource r = this.getResourceFromString(model);
EObject _get = r.getContents().get(0);
final Grammar grammar = ((Grammar) _get);
final AbstractRule rule = IterableExtensions.<AbstractRule>last(grammar.getRules());
AbstractElement _alternatives = rule.getAlternatives();
final AbstractElement fragmentCall = IterableExtensions.<AbstractElement>last(((Group) _alternatives).getElements());
final EClassifier currentType = GrammarUtil.findCurrentType(fragmentCall);
Assert.assertEquals("Rule", currentType.getName());
}
use of org.eclipse.xtext.AbstractRule in project xtext-core by eclipse.
the class GrammarUtilTest method testAllMetamodelDeclarations_02.
@Test
public void testAllMetamodelDeclarations_02() throws Exception {
this.with(XtextStandaloneSetup.class);
StringConcatenation _builder = new StringConcatenation();
_builder.append("grammar foo with org.eclipse.xtext.common.Terminals");
_builder.newLine();
_builder.append("import \'http://www.eclipse.org/emf/2002/Ecore\' as bar");
_builder.newLine();
_builder.append("generate g \'http://3\' as bar");
_builder.newLine();
_builder.append("startrule returns bar::startrule: name=ID;");
_builder.newLine();
String model = _builder.toString();
Resource r = this.getResourceFromString(model);
EObject _get = r.getContents().get(0);
Grammar g = ((Grammar) _get);
List<AbstractMetamodelDeclaration> decls = GrammarUtil.allMetamodelDeclarations(g);
Assert.assertEquals(3, decls.size());
AbstractMetamodelDeclaration decl = decls.get(0);
Assert.assertTrue((decl instanceof ReferencedMetamodel));
Assert.assertNotNull(decl.getEPackage());
Assert.assertEquals("http://www.eclipse.org/emf/2002/Ecore", decl.getEPackage().getNsURI());
Assert.assertEquals("bar", decl.getAlias());
decl = decls.get(1);
Assert.assertEquals("bar", decl.getAlias());
Assert.assertNotNull(decl.getEPackage());
Assert.assertEquals("http://3", decl.getEPackage().getNsURI());
decl = decls.get(2);
Assert.assertTrue((decl instanceof ReferencedMetamodel));
Assert.assertNotNull(decl.getEPackage());
Assert.assertEquals("http://www.eclipse.org/emf/2002/Ecore", decl.getEPackage().getNsURI());
Assert.assertEquals("ecore", decl.getAlias());
AbstractRule abstractRule = g.getRules().get(0);
Assert.assertSame(decls.get(1), abstractRule.getType().getMetamodel());
}
use of org.eclipse.xtext.AbstractRule in project xtext-core by eclipse.
the class GrammarUtilTest method testFindCurrentType_03.
@Test
public void testFindCurrentType_03() throws Exception {
this.with(XtextStandaloneSetup.class);
StringConcatenation _builder = new StringConcatenation();
_builder.append("grammar myLang with org.eclipse.xtext.common.Terminals");
_builder.newLine();
_builder.append("generate g \'http://1\'");
_builder.newLine();
_builder.append("Rule:");
_builder.newLine();
_builder.append("\t");
_builder.append("Fragment;");
_builder.newLine();
_builder.append("fragment Fragment: name=ID SecondFragment;");
_builder.newLine();
_builder.append("fragment SecondFragment: {SubRule.named=current} value=ID;");
_builder.newLine();
String model = _builder.toString();
final XtextResource r = this.getResourceFromString(model);
EObject _get = r.getContents().get(0);
final Grammar grammar = ((Grammar) _get);
final AbstractRule rule = IterableExtensions.<AbstractRule>head(grammar.getRules());
final AbstractElement fragmentCall = rule.getAlternatives();
final EClassifier currentType = GrammarUtil.findCurrentType(fragmentCall);
Assert.assertEquals("SubRule", currentType.getName());
}
use of org.eclipse.xtext.AbstractRule 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;
}
use of org.eclipse.xtext.AbstractRule in project xtext-core by eclipse.
the class ValidatorFragment2 method generateValidationToDeprecateRules.
protected StringConcatenationClient generateValidationToDeprecateRules() {
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
{
if (ValidatorFragment2.this.generateDeprecationValidation) {
{
List<AbstractRule> _deprecatedRulesFromGrammar = ValidatorFragment2.this.getDeprecatedRulesFromGrammar();
for (final AbstractRule deprecatedRule : _deprecatedRulesFromGrammar) {
EClassifier _classifier = deprecatedRule.getType().getClassifier();
ResourceSet _resourceSet = ValidatorFragment2.this.getGrammar().eResource().getResourceSet();
final TypeReference elementType = new TypeReference(((EClass) _classifier), _resourceSet);
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("@");
_builder.append(Check.class);
_builder.newLineIfNotEmpty();
_builder.append("public void checkDeprecated");
String _simpleName = elementType.getSimpleName();
_builder.append(_simpleName);
_builder.append("(");
_builder.append(elementType);
_builder.append(" element) {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("warning(\"This part of the language is marked as deprecated and might get removed in the future!\", element, null);");
_builder.newLine();
_builder.append("}");
_builder.newLine();
}
}
}
}
}
};
return _client;
}
Aggregations