Search in sources :

Example 51 with StringConcatenationClient

use of org.eclipse.xtend2.lib.StringConcatenationClient 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 52 with StringConcatenationClient

use of org.eclipse.xtend2.lib.StringConcatenationClient 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 53 with StringConcatenationClient

use of org.eclipse.xtend2.lib.StringConcatenationClient in project xtext-core by eclipse.

the class XtextGeneratorTemplates method createWebSetup.

public JavaFileAccess createWebSetup(final IXtextGeneratorLanguage langConfig) {
    final Grammar it = langConfig.getGrammar();
    boolean _isPreferXtendStubs = this.codeConfig.isPreferXtendStubs();
    if (_isPreferXtendStubs) {
        TypeReference _webSetup = this.naming.getWebSetup(it);
        StringConcatenationClient _client = new StringConcatenationClient() {

            @Override
            protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                _builder.append("/**");
                _builder.newLine();
                _builder.append(" ");
                _builder.append("* Initialization support for running Xtext languages in web applications.");
                _builder.newLine();
                _builder.append(" ");
                _builder.append("*/");
                _builder.newLine();
                _builder.append("class ");
                String _simpleName = XtextGeneratorTemplates.this.naming.getWebSetup(it).getSimpleName();
                _builder.append(_simpleName);
                _builder.append(" extends ");
                TypeReference _runtimeSetup = XtextGeneratorTemplates.this.naming.getRuntimeSetup(it);
                _builder.append(_runtimeSetup);
                _builder.append(" {");
                _builder.newLineIfNotEmpty();
                _builder.append("\t");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("override ");
                _builder.append(Injector.class, "\t");
                _builder.append(" createInjector() {");
                _builder.newLineIfNotEmpty();
                _builder.append("\t\t");
                _builder.append("return ");
                _builder.append(Guice.class, "\t\t");
                _builder.append(".createInjector(");
                _builder.append(Modules2.class, "\t\t");
                _builder.append(".mixin(new ");
                TypeReference _runtimeModule = XtextGeneratorTemplates.this.naming.getRuntimeModule(it);
                _builder.append(_runtimeModule, "\t\t");
                _builder.append(", new ");
                TypeReference _genericIdeModule = XtextGeneratorTemplates.this.naming.getGenericIdeModule(it);
                _builder.append(_genericIdeModule, "\t\t");
                _builder.append(", new ");
                TypeReference _webModule = XtextGeneratorTemplates.this.naming.getWebModule(it);
                _builder.append(_webModule, "\t\t");
                _builder.append("))");
                _builder.newLineIfNotEmpty();
                _builder.append("\t");
                _builder.append("}");
                _builder.newLine();
                _builder.append("\t");
                _builder.newLine();
                _builder.append("}");
                _builder.newLine();
            }
        };
        return this.fileAccessFactory.createXtendFile(_webSetup, _client);
    } else {
        TypeReference _webSetup_1 = this.naming.getWebSetup(it);
        StringConcatenationClient _client_1 = new StringConcatenationClient() {

            @Override
            protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                _builder.append("/**");
                _builder.newLine();
                _builder.append(" ");
                _builder.append("* Initialization support for running Xtext languages in web applications.");
                _builder.newLine();
                _builder.append(" ");
                _builder.append("*/");
                _builder.newLine();
                _builder.append("public class ");
                String _simpleName = XtextGeneratorTemplates.this.naming.getWebSetup(it).getSimpleName();
                _builder.append(_simpleName);
                _builder.append(" extends ");
                TypeReference _runtimeSetup = XtextGeneratorTemplates.this.naming.getRuntimeSetup(it);
                _builder.append(_runtimeSetup);
                _builder.append(" {");
                _builder.newLineIfNotEmpty();
                _builder.append("\t");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("@Override");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("public ");
                _builder.append(Injector.class, "\t");
                _builder.append(" createInjector() {");
                _builder.newLineIfNotEmpty();
                _builder.append("\t\t");
                _builder.append("return ");
                _builder.append(Guice.class, "\t\t");
                _builder.append(".createInjector(");
                _builder.append(Modules2.class, "\t\t");
                _builder.append(".mixin(new ");
                TypeReference _runtimeModule = XtextGeneratorTemplates.this.naming.getRuntimeModule(it);
                _builder.append(_runtimeModule, "\t\t");
                _builder.append("(), new ");
                TypeReference _genericIdeModule = XtextGeneratorTemplates.this.naming.getGenericIdeModule(it);
                _builder.append(_genericIdeModule, "\t\t");
                _builder.append("(), new ");
                TypeReference _webModule = XtextGeneratorTemplates.this.naming.getWebModule(it);
                _builder.append(_webModule, "\t\t");
                _builder.append("()));");
                _builder.newLineIfNotEmpty();
                _builder.append("\t");
                _builder.append("}");
                _builder.newLine();
                _builder.append("\t");
                _builder.newLine();
                _builder.append("}");
                _builder.newLine();
            }
        };
        return this.fileAccessFactory.createJavaFile(_webSetup_1, _client_1);
    }
}
Also used : StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) Grammar(org.eclipse.xtext.Grammar) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference)

Example 54 with StringConcatenationClient

use of org.eclipse.xtend2.lib.StringConcatenationClient in project xtext-core by eclipse.

the class XtextGeneratorTemplates method createIdeModule.

public JavaFileAccess createIdeModule(final IXtextGeneratorLanguage langConfig) {
    final Grammar it = langConfig.getGrammar();
    boolean _isPreferXtendStubs = this.codeConfig.isPreferXtendStubs();
    if (_isPreferXtendStubs) {
        TypeReference _genericIdeModule = this.naming.getGenericIdeModule(it);
        StringConcatenationClient _client = new StringConcatenationClient() {

            @Override
            protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                _builder.append("/**");
                _builder.newLine();
                _builder.append(" ");
                _builder.append("* Use this class to register ide components.");
                _builder.newLine();
                _builder.append(" ");
                _builder.append("*/");
                _builder.newLine();
                _builder.append("class ");
                String _simpleName = XtextGeneratorTemplates.this.naming.getGenericIdeModule(it).getSimpleName();
                _builder.append(_simpleName);
                _builder.append(" extends ");
                TypeReference _genericIdeGenModule = XtextGeneratorTemplates.this.naming.getGenericIdeGenModule(it);
                _builder.append(_genericIdeGenModule);
                _builder.append(" {");
                _builder.newLineIfNotEmpty();
                _builder.append("}");
                _builder.newLine();
            }
        };
        return this.fileAccessFactory.createXtendFile(_genericIdeModule, _client);
    } else {
        TypeReference _genericIdeModule_1 = this.naming.getGenericIdeModule(it);
        StringConcatenationClient _client_1 = new StringConcatenationClient() {

            @Override
            protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                _builder.append("/**");
                _builder.newLine();
                _builder.append(" ");
                _builder.append("* Use this class to register ide components.");
                _builder.newLine();
                _builder.append(" ");
                _builder.append("*/");
                _builder.newLine();
                _builder.append("public class ");
                String _simpleName = XtextGeneratorTemplates.this.naming.getGenericIdeModule(it).getSimpleName();
                _builder.append(_simpleName);
                _builder.append(" extends ");
                TypeReference _genericIdeGenModule = XtextGeneratorTemplates.this.naming.getGenericIdeGenModule(it);
                _builder.append(_genericIdeGenModule);
                _builder.append(" {");
                _builder.newLineIfNotEmpty();
                _builder.append("}");
                _builder.newLine();
            }
        };
        return this.fileAccessFactory.createJavaFile(_genericIdeModule_1, _client_1);
    }
}
Also used : StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) Grammar(org.eclipse.xtext.Grammar) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference)

Example 55 with StringConcatenationClient

use of org.eclipse.xtend2.lib.StringConcatenationClient in project xtext-core by eclipse.

the class XtextGeneratorTemplates method createWebModule.

public JavaFileAccess createWebModule(final IXtextGeneratorLanguage langConfig) {
    final Grammar it = langConfig.getGrammar();
    boolean _isPreferXtendStubs = this.codeConfig.isPreferXtendStubs();
    if (_isPreferXtendStubs) {
        TypeReference _webModule = this.naming.getWebModule(it);
        StringConcatenationClient _client = new StringConcatenationClient() {

            @Override
            protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                _builder.append("/**");
                _builder.newLine();
                _builder.append(" ");
                _builder.append("* Use this class to register additional components to be used within the web application.");
                _builder.newLine();
                _builder.append(" ");
                _builder.append("*/");
                _builder.newLine();
                _builder.append("class ");
                String _simpleName = XtextGeneratorTemplates.this.naming.getWebModule(it).getSimpleName();
                _builder.append(_simpleName);
                _builder.append(" extends ");
                TypeReference _webGenModule = XtextGeneratorTemplates.this.naming.getWebGenModule(it);
                _builder.append(_webGenModule);
                _builder.append(" {");
                _builder.newLineIfNotEmpty();
                _builder.append("}");
                _builder.newLine();
            }
        };
        return this.fileAccessFactory.createXtendFile(_webModule, _client);
    } else {
        TypeReference _webModule_1 = this.naming.getWebModule(it);
        StringConcatenationClient _client_1 = new StringConcatenationClient() {

            @Override
            protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                _builder.append("/**");
                _builder.newLine();
                _builder.append(" ");
                _builder.append("* Use this class to register additional components to be used within the web application.");
                _builder.newLine();
                _builder.append(" ");
                _builder.append("*/");
                _builder.newLine();
                _builder.append("public class ");
                String _simpleName = XtextGeneratorTemplates.this.naming.getWebModule(it).getSimpleName();
                _builder.append(_simpleName);
                _builder.append(" extends ");
                TypeReference _webGenModule = XtextGeneratorTemplates.this.naming.getWebGenModule(it);
                _builder.append(_webGenModule);
                _builder.append(" {");
                _builder.newLineIfNotEmpty();
                _builder.append("}");
                _builder.newLine();
            }
        };
        return this.fileAccessFactory.createJavaFile(_webModule_1, _client_1);
    }
}
Also used : StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) Grammar(org.eclipse.xtext.Grammar) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference)

Aggregations

StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)194 TypeReference (org.eclipse.xtext.xtext.generator.model.TypeReference)119 GeneratedJavaFileAccess (org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess)24 GuiceModuleAccess (org.eclipse.xtext.xtext.generator.model.GuiceModuleAccess)24 Grammar (org.eclipse.xtext.Grammar)23 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)19 List (java.util.List)18 Test (org.junit.Test)18 Set (java.util.Set)14 JavaFileAccess (org.eclipse.xtext.xtext.generator.model.JavaFileAccess)12 ManifestAccess (org.eclipse.xtext.xtext.generator.model.ManifestAccess)12 EClass (org.eclipse.emf.ecore.EClass)11 EList (org.eclipse.emf.common.util.EList)10 AbstractRule (org.eclipse.xtext.AbstractRule)10 IGeneratorNode (org.eclipse.xtext.generator.trace.node.IGeneratorNode)10 EObject (org.eclipse.emf.ecore.EObject)9 IClassAnnotation (org.eclipse.xtext.xtext.generator.model.annotations.IClassAnnotation)9 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)8 SuppressWarningsAnnotation (org.eclipse.xtext.xtext.generator.model.annotations.SuppressWarningsAnnotation)8 ArrayList (java.util.ArrayList)7