Search in sources :

Example 6 with GeneratedJavaFileAccess

use of org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess in project xtext-core by eclipse.

the class XtextGeneratorTemplates method createWebGenModule.

public JavaFileAccess createWebGenModule(final IXtextGeneratorLanguage langConfig) {
    final Grammar it = langConfig.getGrammar();
    TypeReference _elvis = null;
    TypeReference _superClass = langConfig.getWebGenModule().getSuperClass();
    if (_superClass != null) {
        _elvis = _superClass;
    } else {
        TypeReference _webDefaultModule = this.naming.getWebDefaultModule(it);
        _elvis = _webDefaultModule;
    }
    final TypeReference superClass = _elvis;
    final GeneratedJavaFileAccess file = this.fileAccessFactory.createGeneratedJavaFile(this.naming.getWebGenModule(it));
    file.setImportNestedTypeThreshold(JavaFileAccess.DONT_IMPORT_NESTED_TYPES);
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("/**");
            _builder.newLine();
            _builder.append(" ");
            _builder.append("* Manual modifications go to {@link ");
            String _simpleName = XtextGeneratorTemplates.this.naming.getWebModule(it).getSimpleName();
            _builder.append(_simpleName, " ");
            _builder.append("}.");
            _builder.newLineIfNotEmpty();
            _builder.append(" ");
            _builder.append("*/");
            _builder.newLine();
        }
    };
    file.setTypeComment(_client);
    List<IClassAnnotation> _annotations = file.getAnnotations();
    SuppressWarningsAnnotation _suppressWarningsAnnotation = new SuppressWarningsAnnotation();
    _annotations.add(_suppressWarningsAnnotation);
    StringConcatenationClient _client_1 = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("public abstract class ");
            String _simpleName = XtextGeneratorTemplates.this.naming.getWebGenModule(it).getSimpleName();
            _builder.append(_simpleName);
            _builder.append(" extends ");
            _builder.append(superClass);
            _builder.append(" {");
            _builder.newLineIfNotEmpty();
            _builder.newLine();
            {
                Set<GuiceModuleAccess.Binding> _bindings = langConfig.getWebGenModule().getBindings();
                for (final GuiceModuleAccess.Binding binding : _bindings) {
                    _builder.append("\t");
                    StringConcatenationClient _createBindingMethod = XtextGeneratorTemplates.this.createBindingMethod(binding);
                    _builder.append(_createBindingMethod, "\t");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.newLine();
                }
            }
            _builder.append("}");
            _builder.newLine();
        }
    };
    file.setContent(_client_1);
    file.setMarkedAsGenerated(true);
    return file;
}
Also used : SingletonBinding(org.eclipse.xtext.service.SingletonBinding) GuiceModuleAccess(org.eclipse.xtext.xtext.generator.model.GuiceModuleAccess) Set(java.util.Set) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) IClassAnnotation(org.eclipse.xtext.xtext.generator.model.annotations.IClassAnnotation) GeneratedJavaFileAccess(org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess) Grammar(org.eclipse.xtext.Grammar) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference) SuppressWarningsAnnotation(org.eclipse.xtext.xtext.generator.model.annotations.SuppressWarningsAnnotation)

Example 7 with GeneratedJavaFileAccess

use of org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess in project xtext-core by eclipse.

the class XtextGeneratorTemplates method createRuntimeGenModule.

public JavaFileAccess createRuntimeGenModule(final IXtextGeneratorLanguage langConfig) {
    final Grammar it = langConfig.getGrammar();
    TypeReference _elvis = null;
    TypeReference _superClass = langConfig.getRuntimeGenModule().getSuperClass();
    if (_superClass != null) {
        _elvis = _superClass;
    } else {
        TypeReference _runtimeDefaultModule = this.naming.getRuntimeDefaultModule(it);
        _elvis = _runtimeDefaultModule;
    }
    final TypeReference superClass = _elvis;
    final GeneratedJavaFileAccess file = this.fileAccessFactory.createGeneratedJavaFile(this.naming.getRuntimeGenModule(it));
    file.setImportNestedTypeThreshold(JavaFileAccess.DONT_IMPORT_NESTED_TYPES);
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("/**");
            _builder.newLine();
            _builder.append(" ");
            _builder.append("* Manual modifications go to {@link ");
            String _simpleName = XtextGeneratorTemplates.this.naming.getRuntimeModule(it).getSimpleName();
            _builder.append(_simpleName, " ");
            _builder.append("}.");
            _builder.newLineIfNotEmpty();
            _builder.append(" ");
            _builder.append("*/");
            _builder.newLine();
        }
    };
    file.setTypeComment(_client);
    List<IClassAnnotation> _annotations = file.getAnnotations();
    SuppressWarningsAnnotation _suppressWarningsAnnotation = new SuppressWarningsAnnotation();
    _annotations.add(_suppressWarningsAnnotation);
    StringConcatenationClient _client_1 = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("public abstract class ");
            String _simpleName = XtextGeneratorTemplates.this.naming.getRuntimeGenModule(it).getSimpleName();
            _builder.append(_simpleName);
            _builder.append(" extends ");
            _builder.append(superClass);
            _builder.append(" {");
            _builder.newLineIfNotEmpty();
            _builder.newLine();
            _builder.append("\t");
            _builder.append("protected ");
            _builder.append(Properties.class, "\t");
            _builder.append(" properties = null;");
            _builder.newLineIfNotEmpty();
            _builder.newLine();
            _builder.append("\t");
            _builder.append("@Override");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("public void configure(");
            _builder.append(Binder.class, "\t");
            _builder.append(" binder) {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("properties = tryBindProperties(binder, \"");
            String _replaceAll = langConfig.getGrammar().getName().replaceAll("\\.", "/");
            _builder.append(_replaceAll, "\t\t");
            _builder.append(".properties\");");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("super.configure(binder);");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("\t");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("public void configureLanguageName(");
            _builder.append(Binder.class, "\t");
            _builder.append(" binder) {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("binder.bind(String.class).annotatedWith(");
            _builder.append(Names.class, "\t\t");
            _builder.append(".named(");
            _builder.append(Constants.class, "\t\t");
            _builder.append(".LANGUAGE_NAME)).toInstance(\"");
            String _name = langConfig.getGrammar().getName();
            _builder.append(_name, "\t\t");
            _builder.append("\");");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("\t");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("public void configureFileExtensions(");
            _builder.append(Binder.class, "\t");
            _builder.append(" binder) {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("if (properties == null || properties.getProperty(Constants.FILE_EXTENSIONS) == null)");
            _builder.newLine();
            _builder.append("\t\t\t");
            _builder.append("binder.bind(String.class).annotatedWith(");
            _builder.append(Names.class, "\t\t\t");
            _builder.append(".named(");
            _builder.append(Constants.class, "\t\t\t");
            _builder.append(".FILE_EXTENSIONS)).toInstance(\"");
            String _join = IterableExtensions.join(langConfig.getFileExtensions(), ",");
            _builder.append(_join, "\t\t\t");
            _builder.append("\");");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("\t");
            _builder.newLine();
            {
                Set<GuiceModuleAccess.Binding> _bindings = langConfig.getRuntimeGenModule().getBindings();
                for (final GuiceModuleAccess.Binding binding : _bindings) {
                    _builder.append("\t");
                    StringConcatenationClient _createBindingMethod = XtextGeneratorTemplates.this.createBindingMethod(binding);
                    _builder.append(_createBindingMethod, "\t");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.newLine();
                }
            }
            _builder.append("}");
            _builder.newLine();
        }
    };
    file.setContent(_client_1);
    file.setMarkedAsGenerated(true);
    return file;
}
Also used : SingletonBinding(org.eclipse.xtext.service.SingletonBinding) GuiceModuleAccess(org.eclipse.xtext.xtext.generator.model.GuiceModuleAccess) Set(java.util.Set) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) IClassAnnotation(org.eclipse.xtext.xtext.generator.model.annotations.IClassAnnotation) GeneratedJavaFileAccess(org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess) Grammar(org.eclipse.xtext.Grammar) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference) SuppressWarningsAnnotation(org.eclipse.xtext.xtext.generator.model.annotations.SuppressWarningsAnnotation)

Example 8 with GeneratedJavaFileAccess

use of org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess in project xtext-core by eclipse.

the class XtextGeneratorTemplates method createEclipsePluginGenModule.

public JavaFileAccess createEclipsePluginGenModule(final IXtextGeneratorLanguage langConfig) {
    final Grammar it = langConfig.getGrammar();
    TypeReference _elvis = null;
    TypeReference _superClass = langConfig.getEclipsePluginGenModule().getSuperClass();
    if (_superClass != null) {
        _elvis = _superClass;
    } else {
        TypeReference _eclipsePluginDefaultModule = this.naming.getEclipsePluginDefaultModule(it);
        _elvis = _eclipsePluginDefaultModule;
    }
    final TypeReference superClass = _elvis;
    final GeneratedJavaFileAccess file = this.fileAccessFactory.createGeneratedJavaFile(this.naming.getEclipsePluginGenModule(it));
    file.setImportNestedTypeThreshold(JavaFileAccess.DONT_IMPORT_NESTED_TYPES);
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("/**");
            _builder.newLine();
            _builder.append(" ");
            _builder.append("* Manual modifications go to {@link ");
            String _simpleName = XtextGeneratorTemplates.this.naming.getEclipsePluginModule(it).getSimpleName();
            _builder.append(_simpleName, " ");
            _builder.append("}.");
            _builder.newLineIfNotEmpty();
            _builder.append(" ");
            _builder.append("*/");
            _builder.newLine();
        }
    };
    file.setTypeComment(_client);
    List<IClassAnnotation> _annotations = file.getAnnotations();
    SuppressWarningsAnnotation _suppressWarningsAnnotation = new SuppressWarningsAnnotation();
    _annotations.add(_suppressWarningsAnnotation);
    StringConcatenationClient _client_1 = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("public abstract class ");
            String _simpleName = XtextGeneratorTemplates.this.naming.getEclipsePluginGenModule(it).getSimpleName();
            _builder.append(_simpleName);
            _builder.append(" extends ");
            _builder.append(superClass);
            _builder.append(" {");
            _builder.newLineIfNotEmpty();
            _builder.newLine();
            _builder.append("\t");
            _builder.append("public ");
            String _simpleName_1 = XtextGeneratorTemplates.this.naming.getEclipsePluginGenModule(it).getSimpleName();
            _builder.append(_simpleName_1, "\t");
            _builder.append("(");
            TypeReference _typeRef = TypeReference.typeRef("org.eclipse.ui.plugin.AbstractUIPlugin");
            _builder.append(_typeRef, "\t");
            _builder.append(" plugin) {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("super(plugin);");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("\t");
            _builder.newLine();
            {
                Set<GuiceModuleAccess.Binding> _bindings = langConfig.getEclipsePluginGenModule().getBindings();
                for (final GuiceModuleAccess.Binding binding : _bindings) {
                    _builder.append("\t");
                    StringConcatenationClient _createBindingMethod = XtextGeneratorTemplates.this.createBindingMethod(binding);
                    _builder.append(_createBindingMethod, "\t");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.newLine();
                }
            }
            _builder.append("}");
            _builder.newLine();
        }
    };
    file.setContent(_client_1);
    file.setMarkedAsGenerated(true);
    return file;
}
Also used : SingletonBinding(org.eclipse.xtext.service.SingletonBinding) GuiceModuleAccess(org.eclipse.xtext.xtext.generator.model.GuiceModuleAccess) Set(java.util.Set) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) IClassAnnotation(org.eclipse.xtext.xtext.generator.model.annotations.IClassAnnotation) GeneratedJavaFileAccess(org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess) Grammar(org.eclipse.xtext.Grammar) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference) SuppressWarningsAnnotation(org.eclipse.xtext.xtext.generator.model.annotations.SuppressWarningsAnnotation)

Example 9 with GeneratedJavaFileAccess

use of org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess in project xtext-core by eclipse.

the class GrammarAccessFragment2 method doGenerateGrammarAccess.

protected void doGenerateGrammarAccess() {
    final GeneratedJavaFileAccess javaFile = this.fileAccessFactory.createGeneratedJavaFile(this._grammarAccessExtensions.getGrammarAccess(this.getGrammar()));
    List<IClassAnnotation> _annotations = javaFile.getAnnotations();
    SingletonClassAnnotation _singletonClassAnnotation = new SingletonClassAnnotation();
    _annotations.add(_singletonClassAnnotation);
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("public class ");
            String _simpleName = GrammarAccessFragment2.this._grammarAccessExtensions.getGrammarAccess(GrammarAccessFragment2.this.getLanguage().getGrammar()).getSimpleName();
            _builder.append(_simpleName);
            _builder.append(" extends ");
            _builder.append(AbstractElementFinder.AbstractGrammarElementFinder.class);
            _builder.append(" {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.newLine();
            {
                Iterable<ParserRule> _filter = Iterables.<ParserRule>filter(GrammarAccessFragment2.this.getLanguage().getGrammar().getRules(), ParserRule.class);
                for (final ParserRule r : _filter) {
                    _builder.append("\t");
                    StringConcatenationClient _parserRuleClasses = GrammarAccessFragment2.this.parserRuleClasses(r);
                    _builder.append(_parserRuleClasses, "\t");
                    _builder.newLineIfNotEmpty();
                }
            }
            _builder.append("\t");
            _builder.newLine();
            {
                Iterable<EnumRule> _filter_1 = Iterables.<EnumRule>filter(GrammarAccessFragment2.this.getLanguage().getGrammar().getRules(), EnumRule.class);
                for (final EnumRule r_1 : _filter_1) {
                    _builder.append("\t");
                    StringConcatenationClient _parserRuleClasses_1 = GrammarAccessFragment2.this.parserRuleClasses(r_1);
                    _builder.append(_parserRuleClasses_1, "\t");
                    _builder.newLineIfNotEmpty();
                }
            }
            _builder.append("\t");
            _builder.newLine();
            {
                EList<AbstractRule> _rules = GrammarAccessFragment2.this.getLanguage().getGrammar().getRules();
                for (final AbstractRule r_2 : _rules) {
                    _builder.append("\t");
                    StringConcatenationClient _cache = GrammarAccessFragment2.this.cache(r_2);
                    _builder.append(_cache, "\t");
                    _builder.newLineIfNotEmpty();
                }
            }
            _builder.append("\t");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("private final ");
            _builder.append(Grammar.class, "\t");
            _builder.append(" grammar;");
            _builder.newLineIfNotEmpty();
            {
                List<Grammar> _effectivelyUsedGrammars = GrammarAccessFragment2.this.getEffectivelyUsedGrammars(GrammarAccessFragment2.this.getLanguage().getGrammar());
                for (final Grammar g : _effectivelyUsedGrammars) {
                    _builder.append("\t");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("private final ");
                    TypeReference _grammarAccess = GrammarAccessFragment2.this._grammarAccessExtensions.getGrammarAccess(g);
                    _builder.append(_grammarAccess, "\t");
                    _builder.append(" ");
                    String _gaGrammarAccessLocalVarName = GrammarAccessFragment2.this.gaGrammarAccessLocalVarName(g);
                    _builder.append(_gaGrammarAccessLocalVarName, "\t");
                    _builder.append(";");
                    _builder.newLineIfNotEmpty();
                }
            }
            _builder.newLine();
            _builder.append("\t");
            _builder.append("@");
            _builder.append(Inject.class, "\t");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("public ");
            String _simpleName_1 = GrammarAccessFragment2.this._grammarAccessExtensions.getGrammarAccess(GrammarAccessFragment2.this.getLanguage().getGrammar()).getSimpleName();
            _builder.append(_simpleName_1, "\t");
            _builder.append("(");
            _builder.append(GrammarProvider.class, "\t");
            _builder.append(" grammarProvider");
            {
                List<Grammar> _effectivelyUsedGrammars_1 = GrammarAccessFragment2.this.getEffectivelyUsedGrammars(GrammarAccessFragment2.this.getLanguage().getGrammar());
                for (final Grammar g_1 : _effectivelyUsedGrammars_1) {
                    _builder.append(",");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.append("\t\t");
                    TypeReference _grammarAccess_1 = GrammarAccessFragment2.this._grammarAccessExtensions.getGrammarAccess(g_1);
                    _builder.append(_grammarAccess_1, "\t\t\t");
                    _builder.append(" ");
                    String _gaGrammarAccessLocalVarName_1 = GrammarAccessFragment2.this.gaGrammarAccessLocalVarName(g_1);
                    _builder.append(_gaGrammarAccessLocalVarName_1, "\t\t\t");
                }
            }
            _builder.append(") {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("this.grammar = internalFindGrammar(grammarProvider);");
            _builder.newLine();
            {
                List<Grammar> _effectivelyUsedGrammars_2 = GrammarAccessFragment2.this.getEffectivelyUsedGrammars(GrammarAccessFragment2.this.getLanguage().getGrammar());
                for (final Grammar g_2 : _effectivelyUsedGrammars_2) {
                    _builder.append("\t\t");
                    _builder.append("this.");
                    String _gaGrammarAccessLocalVarName_2 = GrammarAccessFragment2.this.gaGrammarAccessLocalVarName(g_2);
                    _builder.append(_gaGrammarAccessLocalVarName_2, "\t\t");
                    _builder.append(" = ");
                    String _gaGrammarAccessLocalVarName_3 = GrammarAccessFragment2.this.gaGrammarAccessLocalVarName(g_2);
                    _builder.append(_gaGrammarAccessLocalVarName_3, "\t\t");
                    _builder.append(";");
                    _builder.newLineIfNotEmpty();
                }
            }
            {
                EList<AbstractRule> _rules_1 = GrammarAccessFragment2.this.getLanguage().getGrammar().getRules();
                for (final AbstractRule r_3 : _rules_1) {
                    _builder.append("\t\t");
                    StringConcatenationClient _initializer = GrammarAccessFragment2.this.initializer(r_3);
                    _builder.append(_initializer, "\t\t");
                    _builder.newLineIfNotEmpty();
                }
            }
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("\t");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("protected ");
            _builder.append(Grammar.class, "\t");
            _builder.append(" internalFindGrammar(");
            _builder.append(GrammarProvider.class, "\t");
            _builder.append(" grammarProvider) {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append(Grammar.class, "\t\t");
            _builder.append(" grammar = grammarProvider.getGrammar(this);");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("while (grammar != null) {");
            _builder.newLine();
            _builder.append("\t\t\t");
            _builder.append("if (\"");
            String _name = GrammarAccessFragment2.this.getLanguage().getGrammar().getName();
            _builder.append(_name, "\t\t\t");
            _builder.append("\".equals(grammar.getName())) {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t\t\t");
            _builder.append("return grammar;");
            _builder.newLine();
            _builder.append("\t\t\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("\t\t\t");
            _builder.append(List.class, "\t\t\t");
            _builder.append("<");
            _builder.append(Grammar.class, "\t\t\t");
            _builder.append("> grammars = grammar.getUsedGrammars();");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t\t");
            _builder.append("if (!grammars.isEmpty()) {");
            _builder.newLine();
            _builder.append("\t\t\t\t");
            _builder.append("grammar = grammars.iterator().next();");
            _builder.newLine();
            _builder.append("\t\t\t");
            _builder.append("} else {");
            _builder.newLine();
            _builder.append("\t\t\t\t");
            _builder.append("return null;");
            _builder.newLine();
            _builder.append("\t\t\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("return grammar;");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("\t");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("@Override");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("public ");
            _builder.append(Grammar.class, "\t");
            _builder.append(" getGrammar() {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("return grammar;");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("\t");
            _builder.newLine();
            {
                List<Grammar> _effectivelyUsedGrammars_3 = GrammarAccessFragment2.this.getEffectivelyUsedGrammars(GrammarAccessFragment2.this.getLanguage().getGrammar());
                for (final Grammar g_3 : _effectivelyUsedGrammars_3) {
                    _builder.append("\t");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("public ");
                    TypeReference _grammarAccess_2 = GrammarAccessFragment2.this._grammarAccessExtensions.getGrammarAccess(g_3);
                    _builder.append(_grammarAccess_2, "\t");
                    _builder.append(" get");
                    String _simpleName_2 = GrammarAccessFragment2.this._grammarAccessExtensions.getGrammarAccess(g_3).getSimpleName();
                    _builder.append(_simpleName_2, "\t");
                    _builder.append("() {");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("return ");
                    String _gaGrammarAccessLocalVarName_4 = GrammarAccessFragment2.this.gaGrammarAccessLocalVarName(g_3);
                    _builder.append(_gaGrammarAccessLocalVarName_4, "\t\t");
                    _builder.append(";");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.append("}");
                    _builder.newLine();
                }
            }
            _builder.newLine();
            {
                List<AbstractRule> _allRules = GrammarUtil.allRules(GrammarAccessFragment2.this.getLanguage().getGrammar());
                for (final AbstractRule r_4 : _allRules) {
                    _builder.append("\t");
                    _builder.newLine();
                    _builder.append("\t");
                    StringConcatenationClient _ter = GrammarAccessFragment2.this.getter(r_4, GrammarAccessFragment2.this.getLanguage().getGrammar());
                    _builder.append(_ter, "\t");
                    _builder.newLineIfNotEmpty();
                }
            }
            _builder.append("}");
            _builder.newLine();
        }
    };
    javaFile.setContent(_client);
    javaFile.writeTo(this.getProjectConfig().getRuntime().getSrcGen());
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) SingletonClassAnnotation(org.eclipse.xtext.xtext.generator.model.annotations.SingletonClassAnnotation) Grammar(org.eclipse.xtext.Grammar) EnumRule(org.eclipse.xtext.EnumRule) EList(org.eclipse.emf.common.util.EList) AbstractElementFinder(org.eclipse.xtext.service.AbstractElementFinder) IClassAnnotation(org.eclipse.xtext.xtext.generator.model.annotations.IClassAnnotation) GeneratedJavaFileAccess(org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess) List(java.util.List) EList(org.eclipse.emf.common.util.EList) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference) AbstractRule(org.eclipse.xtext.AbstractRule)

Example 10 with GeneratedJavaFileAccess

use of org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess in project xtext-core by eclipse.

the class XtextAntlrGeneratorFragment2 method generateContentAssistParser.

public JavaFileAccess generateContentAssistParser() {
    @Extension final ContentAssistGrammarNaming naming = this.contentAssistNaming;
    final GeneratedJavaFileAccess file = this.fileFactory.createGeneratedJavaFile(naming.getParserClass(this.getGrammar()));
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("public class ");
            String _simpleName = naming.getParserClass(XtextAntlrGeneratorFragment2.this.getGrammar()).getSimpleName();
            _builder.append(_simpleName);
            _builder.append(" extends ");
            TypeReference _parserSuperClass = naming.getParserSuperClass(XtextAntlrGeneratorFragment2.this.getGrammar(), XtextAntlrGeneratorFragment2.this.partialParsing);
            _builder.append(_parserSuperClass);
            _builder.append(" {");
            _builder.newLineIfNotEmpty();
            _builder.newLine();
            _builder.append("\t");
            StringConcatenationClient _initNameMappings = XtextAntlrGeneratorFragment2.this.initNameMappings(XtextAntlrGeneratorFragment2.this.getGrammar());
            _builder.append(_initNameMappings, "\t");
            _builder.newLineIfNotEmpty();
            _builder.newLine();
            _builder.append("\t");
            _builder.append("@");
            _builder.append(Inject.class, "\t");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("private ");
            TypeReference _grammarAccess = XtextAntlrGeneratorFragment2.this.grammarUtil.getGrammarAccess(XtextAntlrGeneratorFragment2.this.getGrammar());
            _builder.append(_grammarAccess, "\t");
            _builder.append(" grammarAccess;");
            _builder.newLineIfNotEmpty();
            _builder.newLine();
            _builder.append("\t");
            _builder.append("@Override");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("protected ");
            TypeReference _internalParserClass = naming.getInternalParserClass(XtextAntlrGeneratorFragment2.this.getGrammar());
            _builder.append(_internalParserClass, "\t");
            _builder.append(" createParser() {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            TypeReference _internalParserClass_1 = naming.getInternalParserClass(XtextAntlrGeneratorFragment2.this.getGrammar());
            _builder.append(_internalParserClass_1, "\t\t");
            _builder.append(" result = new ");
            TypeReference _internalParserClass_2 = naming.getInternalParserClass(XtextAntlrGeneratorFragment2.this.getGrammar());
            _builder.append(_internalParserClass_2, "\t\t");
            _builder.append("(null);");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("result.setGrammarAccess(grammarAccess);");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("return result;");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.newLine();
            {
                boolean _hasSyntheticTerminalRule = XtextAntlrGeneratorFragment2.this.hasSyntheticTerminalRule();
                if (_hasSyntheticTerminalRule) {
                    _builder.append("\t");
                    _builder.append("@Override");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("protected ");
                    _builder.append(TokenSource.class, "\t");
                    _builder.append(" createLexer(");
                    _builder.append(CharStream.class, "\t");
                    _builder.append(" stream) {");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("return new ");
                    TypeReference _tokenSourceClass = naming.getTokenSourceClass(XtextAntlrGeneratorFragment2.this.getGrammar());
                    _builder.append(_tokenSourceClass, "\t\t");
                    _builder.append("(super.createLexer(stream));");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.append("}");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.newLine();
                }
            }
            _builder.append("\t");
            _builder.append("@Override");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("protected String getRuleName(");
            _builder.append(AbstractElement.class, "\t");
            _builder.append(" element) {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("return nameMappings.getRuleName(element);");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.newLine();
            _builder.append("\t");
            _builder.append("@Override");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("protected String[] getInitialHiddenTokens() {");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("return new String[] { ");
            {
                List<String> _initialHiddenTokens = XtextAntlrGeneratorFragment2.this.grammarUtil.initialHiddenTokens(XtextAntlrGeneratorFragment2.this.getGrammar());
                boolean _hasElements = false;
                for (final String hidden : _initialHiddenTokens) {
                    if (!_hasElements) {
                        _hasElements = true;
                    } else {
                        _builder.appendImmediate(", ", "\t\t");
                    }
                    _builder.append("\"");
                    _builder.append(hidden, "\t\t");
                    _builder.append("\"");
                }
            }
            _builder.append(" };");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.newLine();
            _builder.append("\t");
            _builder.append("public ");
            TypeReference _grammarAccess_1 = XtextAntlrGeneratorFragment2.this.grammarUtil.getGrammarAccess(XtextAntlrGeneratorFragment2.this.getGrammar());
            _builder.append(_grammarAccess_1, "\t");
            _builder.append(" getGrammarAccess() {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("return this.grammarAccess;");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.newLine();
            _builder.append("\t");
            _builder.append("public void setGrammarAccess(");
            TypeReference _grammarAccess_2 = XtextAntlrGeneratorFragment2.this.grammarUtil.getGrammarAccess(XtextAntlrGeneratorFragment2.this.getGrammar());
            _builder.append(_grammarAccess_2, "\t");
            _builder.append(" grammarAccess) {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("this.grammarAccess = grammarAccess;");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("\t");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("public NameMappings getNameMappings() {");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("return nameMappings;");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("\t");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("public void setNameMappings(NameMappings nameMappings) {");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("this.nameMappings = nameMappings;");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("}");
            _builder.newLine();
        }
    };
    file.setContent(_client);
    return file;
}
Also used : Extension(org.eclipse.xtext.xbase.lib.Extension) TokenSource(org.antlr.runtime.TokenSource) AbstractIndentationTokenSource(org.eclipse.xtext.parser.antlr.AbstractIndentationTokenSource) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) ContentAssistGrammarNaming(org.eclipse.xtext.xtext.generator.parser.antlr.ContentAssistGrammarNaming) GeneratedJavaFileAccess(org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess) List(java.util.List) ArrayList(java.util.ArrayList) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference) CharStream(org.antlr.runtime.CharStream)

Aggregations

StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)20 GeneratedJavaFileAccess (org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess)20 TypeReference (org.eclipse.xtext.xtext.generator.model.TypeReference)20 Grammar (org.eclipse.xtext.Grammar)9 IClassAnnotation (org.eclipse.xtext.xtext.generator.model.annotations.IClassAnnotation)9 SuppressWarningsAnnotation (org.eclipse.xtext.xtext.generator.model.annotations.SuppressWarningsAnnotation)8 List (java.util.List)6 Set (java.util.Set)6 GuiceModuleAccess (org.eclipse.xtext.xtext.generator.model.GuiceModuleAccess)6 SingletonBinding (org.eclipse.xtext.service.SingletonBinding)5 ArrayList (java.util.ArrayList)3 AbstractRule (org.eclipse.xtext.AbstractRule)3 EList (org.eclipse.emf.common.util.EList)2 EObject (org.eclipse.emf.ecore.EObject)2 ParserRule (org.eclipse.xtext.ParserRule)2 ContentAssistGrammarNaming (org.eclipse.xtext.xtext.generator.parser.antlr.ContentAssistGrammarNaming)2 Inject (com.google.inject.Inject)1 HashSet (java.util.HashSet)1 CharStream (org.antlr.runtime.CharStream)1 TokenSource (org.antlr.runtime.TokenSource)1