Search in sources :

Example 1 with SuppressWarningsAnnotation

use of org.eclipse.xtext.xtext.generator.model.annotations.SuppressWarningsAnnotation 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 2 with SuppressWarningsAnnotation

use of org.eclipse.xtext.xtext.generator.model.annotations.SuppressWarningsAnnotation 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 3 with SuppressWarningsAnnotation

use of org.eclipse.xtext.xtext.generator.model.annotations.SuppressWarningsAnnotation 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 4 with SuppressWarningsAnnotation

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

the class SerializerFragment2 method generateAbstractSyntacticSequencer.

protected void generateAbstractSyntacticSequencer() {
    TypeReference _xifexpression = null;
    boolean _isGenerateStub = this.isGenerateStub();
    if (_isGenerateStub) {
        _xifexpression = this.getAbstractSyntacticSequencerClass(this.getGrammar());
    } else {
        _xifexpression = this.getSyntacticSequencerClass(this.getGrammar());
    }
    final TypeReference clazz = _xifexpression;
    final GeneratedJavaFileAccess javaFile = this.fileAccessFactory.createGeneratedJavaFile(clazz);
    javaFile.setResourceSet(this.getLanguage().getResourceSet());
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("public ");
            {
                boolean _isGenerateStub = SerializerFragment2.this.isGenerateStub();
                if (_isGenerateStub) {
                    _builder.append("abstract ");
                }
            }
            _builder.append("class ");
            String _simpleName = clazz.getSimpleName();
            _builder.append(_simpleName);
            _builder.append(" extends ");
            _builder.append(AbstractSyntacticSequencer.class);
            _builder.append(" {");
            _builder.newLineIfNotEmpty();
            _builder.newLine();
            _builder.append("\t");
            _builder.append("protected ");
            TypeReference _grammarAccess = SerializerFragment2.this._grammarAccessExtensions.getGrammarAccess(SerializerFragment2.this.getGrammar());
            _builder.append(_grammarAccess, "\t");
            _builder.append(" grammarAccess;");
            _builder.newLineIfNotEmpty();
            {
                List<EqualAmbiguousTransitions> _allAmbiguousTransitionsBySyntax = SerializerFragment2.this._syntacticSequencerExtensions.getAllAmbiguousTransitionsBySyntax();
                for (final EqualAmbiguousTransitions group : _allAmbiguousTransitionsBySyntax) {
                    _builder.append("\t");
                    _builder.append("protected ");
                    TypeReference _typeReference = new TypeReference("org.eclipse.xtext.serializer.analysis", "GrammarAlias.AbstractElementAlias");
                    _builder.append(_typeReference, "\t");
                    _builder.append(" match_");
                    String _identifier = group.getIdentifier();
                    _builder.append(_identifier, "\t");
                    _builder.append(";");
                    _builder.newLineIfNotEmpty();
                }
            }
            _builder.append("\t");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("@");
            _builder.append(Inject.class, "\t");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("protected void init(");
            _builder.append(IGrammarAccess.class, "\t");
            _builder.append(" access) {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("grammarAccess = (");
            TypeReference _grammarAccess_1 = SerializerFragment2.this._grammarAccessExtensions.getGrammarAccess(SerializerFragment2.this.getGrammar());
            _builder.append(_grammarAccess_1, "\t\t");
            _builder.append(") access;");
            _builder.newLineIfNotEmpty();
            {
                List<EqualAmbiguousTransitions> _allAmbiguousTransitionsBySyntax_1 = SerializerFragment2.this._syntacticSequencerExtensions.getAllAmbiguousTransitionsBySyntax();
                for (final EqualAmbiguousTransitions group_1 : _allAmbiguousTransitionsBySyntax_1) {
                    _builder.append("\t\t");
                    _builder.append("match_");
                    String _identifier_1 = group_1.getIdentifier();
                    _builder.append(_identifier_1, "\t\t");
                    _builder.append(" = ");
                    StringConcatenationClient _elementAliasToConstructor = SerializerFragment2.this._syntacticSequencerExtensions.elementAliasToConstructor(group_1.getElementAlias());
                    _builder.append(_elementAliasToConstructor, "\t\t");
                    _builder.append(";");
                    _builder.newLineIfNotEmpty();
                }
            }
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("\t");
            _builder.newLine();
            _builder.append("\t");
            StringConcatenationClient _genGetUnassignedRuleCallTokens = SerializerFragment2.this.genGetUnassignedRuleCallTokens();
            _builder.append(_genGetUnassignedRuleCallTokens, "\t");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.newLine();
            {
                List<AbstractRule> _unassignedCalledTokenRules = SerializerFragment2.this.unassignedCalledTokenRules();
                boolean _hasElements = false;
                for (final AbstractRule rule : _unassignedCalledTokenRules) {
                    if (!_hasElements) {
                        _hasElements = true;
                    } else {
                        _builder.appendImmediate("\n", "\t");
                    }
                    _builder.append("\t");
                    StringConcatenationClient _genGetUnassignedRuleCallToken = SerializerFragment2.this.genGetUnassignedRuleCallToken(rule);
                    _builder.append(_genGetUnassignedRuleCallToken, "\t");
                    _builder.newLineIfNotEmpty();
                }
            }
            _builder.append("\t");
            _builder.newLine();
            _builder.append("\t");
            StringConcatenationClient _genEmitUnassignedTokens = SerializerFragment2.this.genEmitUnassignedTokens();
            _builder.append(_genEmitUnassignedTokens, "\t");
            _builder.newLineIfNotEmpty();
            _builder.newLine();
            {
                List<EqualAmbiguousTransitions> _allAmbiguousTransitionsBySyntax_2 = SerializerFragment2.this._syntacticSequencerExtensions.getAllAmbiguousTransitionsBySyntax();
                for (final EqualAmbiguousTransitions group_2 : _allAmbiguousTransitionsBySyntax_2) {
                    _builder.append("\t");
                    _builder.append("/**");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append(" ");
                    _builder.append("* Ambiguous syntax:");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append(" ");
                    _builder.append("*     ");
                    String _replace = group_2.getElementAlias().toString().replace("\n", "\n *     ");
                    _builder.append(_replace, "\t ");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.append(" ");
                    _builder.append("*");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append(" ");
                    _builder.append("* This ambiguous syntax occurs at:");
                    _builder.newLine();
                    {
                        final Function1<ISyntacticSequencerPDAProvider.ISynTransition, String> _function = (ISyntacticSequencerPDAProvider.ISynTransition it) -> {
                            return group_2.ambiguityInsideTransition(it).trim();
                        };
                        List<String> _sort = IterableExtensions.<String>sort(IterableExtensions.<String>toSet(ListExtensions.<ISyntacticSequencerPDAProvider.ISynTransition, String>map(group_2.getTransitions(), _function)));
                        for (final String trans : _sort) {
                            _builder.append("\t");
                            _builder.append(" ");
                            _builder.append("*     ");
                            String _replace_1 = trans.toString().replace("\n", "\n*     ");
                            _builder.append(_replace_1, "\t ");
                            _builder.newLineIfNotEmpty();
                        }
                    }
                    _builder.append("\t");
                    _builder.append(" ");
                    _builder.append("*/");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("protected void emit_");
                    String _identifier_2 = group_2.getIdentifier();
                    _builder.append(_identifier_2, "\t");
                    _builder.append("(");
                    _builder.append(EObject.class, "\t");
                    _builder.append(" semanticObject, ");
                    _builder.append(ISyntacticSequencerPDAProvider.ISynNavigable.class, "\t");
                    _builder.append(" transition, ");
                    _builder.append(List.class, "\t");
                    _builder.append("<");
                    _builder.append(INode.class, "\t");
                    _builder.append("> nodes) {");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("acceptNodes(transition, nodes);");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("}");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.newLine();
                }
            }
            _builder.append("}");
            _builder.newLine();
        }
    };
    javaFile.setContent(_client);
    List<IClassAnnotation> _annotations = javaFile.getAnnotations();
    SuppressWarningsAnnotation _suppressWarningsAnnotation = new SuppressWarningsAnnotation();
    _annotations.add(_suppressWarningsAnnotation);
    javaFile.writeTo(this.getProjectConfig().getRuntime().getSrcGen());
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) SuppressWarningsAnnotation(org.eclipse.xtext.xtext.generator.model.annotations.SuppressWarningsAnnotation) EqualAmbiguousTransitions(org.eclipse.xtext.xtext.generator.serializer.EqualAmbiguousTransitions) ISyntacticSequencerPDAProvider(org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider) EObject(org.eclipse.emf.ecore.EObject) IClassAnnotation(org.eclipse.xtext.xtext.generator.model.annotations.IClassAnnotation) GeneratedJavaFileAccess(org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess) List(java.util.List) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference) AbstractRule(org.eclipse.xtext.AbstractRule)

Example 5 with SuppressWarningsAnnotation

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

the class XtextGeneratorTemplates method createRuntimeGenSetup.

public JavaFileAccess createRuntimeGenSetup(final IXtextGeneratorLanguage langConfig) {
    final Grammar it = langConfig.getGrammar();
    final GeneratedJavaFileAccess file = this.fileAccessFactory.createGeneratedJavaFile(this.naming.getRuntimeGenSetup(it));
    XtextGeneratorTemplates.addBackwardsCompabibleImportsTo(langConfig, file);
    List<IClassAnnotation> _annotations = file.getAnnotations();
    SuppressWarningsAnnotation _suppressWarningsAnnotation = new SuppressWarningsAnnotation();
    _annotations.add(_suppressWarningsAnnotation);
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("public class ");
            String _simpleName = XtextGeneratorTemplates.this.naming.getRuntimeGenSetup(it).getSimpleName();
            _builder.append(_simpleName);
            _builder.append(" implements ");
            _builder.append(ISetup.class);
            _builder.append(" {");
            _builder.newLineIfNotEmpty();
            _builder.newLine();
            _builder.append("\t");
            _builder.append("@Override");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("public ");
            _builder.append(Injector.class, "\t");
            _builder.append(" createInjectorAndDoEMFRegistration() {");
            _builder.newLineIfNotEmpty();
            {
                EList<Grammar> _usedGrammars = langConfig.getGrammar().getUsedGrammars();
                for (final Grammar usedGrammar : _usedGrammars) {
                    _builder.append("\t\t");
                    TypeReference _runtimeSetup = XtextGeneratorTemplates.this.naming.getRuntimeSetup(usedGrammar);
                    _builder.append(_runtimeSetup, "\t\t");
                    _builder.append(".doSetup();");
                    _builder.newLineIfNotEmpty();
                }
            }
            {
                boolean _isEmpty = langConfig.getGrammar().getUsedGrammars().isEmpty();
                if (_isEmpty) {
                    _builder.append("\t\t");
                    _builder.append("// register default ePackages");
                    _builder.newLine();
                    _builder.append("\t\t");
                    _builder.append("if (!");
                    TypeReference _typeRef = TypeReference.typeRef("org.eclipse.emf.ecore.resource.Resource");
                    _builder.append(_typeRef, "\t\t");
                    _builder.append(".Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey(\"ecore\"))");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t");
                    _builder.append("\t");
                    TypeReference _typeRef_1 = TypeReference.typeRef("org.eclipse.emf.ecore.resource.Resource");
                    _builder.append(_typeRef_1, "\t\t\t");
                    _builder.append(".Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t");
                    _builder.append("\t\t");
                    _builder.append("\"ecore\", new ");
                    TypeReference _typeRef_2 = TypeReference.typeRef("org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl");
                    _builder.append(_typeRef_2, "\t\t\t\t");
                    _builder.append("());");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t");
                    _builder.append("if (!");
                    TypeReference _typeRef_3 = TypeReference.typeRef("org.eclipse.emf.ecore.resource.Resource");
                    _builder.append(_typeRef_3, "\t\t");
                    _builder.append(".Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey(\"xmi\"))");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t");
                    _builder.append("\t");
                    TypeReference _typeRef_4 = TypeReference.typeRef("org.eclipse.emf.ecore.resource.Resource");
                    _builder.append(_typeRef_4, "\t\t\t");
                    _builder.append(".Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t");
                    _builder.append("\t\t");
                    _builder.append("\"xmi\", new ");
                    TypeReference _typeRef_5 = TypeReference.typeRef("org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl");
                    _builder.append(_typeRef_5, "\t\t\t\t");
                    _builder.append("());");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t");
                    _builder.append("if (!");
                    TypeReference _typeRef_6 = TypeReference.typeRef("org.eclipse.emf.ecore.resource.Resource");
                    _builder.append(_typeRef_6, "\t\t");
                    _builder.append(".Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey(\"xtextbin\"))");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t");
                    _builder.append("\t");
                    TypeReference _typeRef_7 = TypeReference.typeRef("org.eclipse.emf.ecore.resource.Resource");
                    _builder.append(_typeRef_7, "\t\t\t");
                    _builder.append(".Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t");
                    _builder.append("\t\t");
                    _builder.append("\"xtextbin\", new ");
                    _builder.append(BinaryGrammarResourceFactoryImpl.class, "\t\t\t\t");
                    _builder.append("());");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t");
                    _builder.append("if (!");
                    TypeReference _typeRef_8 = TypeReference.typeRef("org.eclipse.emf.ecore.EPackage");
                    _builder.append(_typeRef_8, "\t\t");
                    _builder.append(".Registry.INSTANCE.containsKey(");
                    _builder.append(XtextPackage.class, "\t\t");
                    _builder.append(".eNS_URI))");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t");
                    _builder.append("\t");
                    TypeReference _typeRef_9 = TypeReference.typeRef("org.eclipse.emf.ecore.EPackage");
                    _builder.append(_typeRef_9, "\t\t\t");
                    _builder.append(".Registry.INSTANCE.put(");
                    _builder.append(XtextPackage.class, "\t\t\t");
                    _builder.append(".eNS_URI, ");
                    _builder.append(XtextPackage.class, "\t\t\t");
                    _builder.append(".eINSTANCE);");
                    _builder.newLineIfNotEmpty();
                }
            }
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append(Injector.class, "\t\t");
            _builder.append(" injector = createInjector();");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("register(injector);");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("return injector;");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("\t");
            _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(new ");
            TypeReference _runtimeModule = XtextGeneratorTemplates.this.naming.getRuntimeModule(it);
            _builder.append(_runtimeModule, "\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 register(");
            _builder.append(Injector.class, "\t");
            _builder.append(" injector) {");
            _builder.newLineIfNotEmpty();
            {
                List<StringConcatenationClient> _registrations = langConfig.getRuntimeGenSetup().getRegistrations();
                for (final StringConcatenationClient reg : _registrations) {
                    _builder.append("\t\t");
                    _builder.append(reg, "\t\t");
                    _builder.newLineIfNotEmpty();
                }
            }
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("}");
            _builder.newLine();
        }
    };
    file.setContent(_client);
    return file;
}
Also used : XtextPackage(org.eclipse.xtext.XtextPackage) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) Grammar(org.eclipse.xtext.Grammar) BinaryGrammarResourceFactoryImpl(org.eclipse.xtext.resource.impl.BinaryGrammarResourceFactoryImpl) SuppressWarningsAnnotation(org.eclipse.xtext.xtext.generator.model.annotations.SuppressWarningsAnnotation) EList(org.eclipse.emf.common.util.EList) IClassAnnotation(org.eclipse.xtext.xtext.generator.model.annotations.IClassAnnotation) GeneratedJavaFileAccess(org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess) EList(org.eclipse.emf.common.util.EList) List(java.util.List) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference)

Aggregations

StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)8 GeneratedJavaFileAccess (org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess)8 TypeReference (org.eclipse.xtext.xtext.generator.model.TypeReference)8 IClassAnnotation (org.eclipse.xtext.xtext.generator.model.annotations.IClassAnnotation)8 SuppressWarningsAnnotation (org.eclipse.xtext.xtext.generator.model.annotations.SuppressWarningsAnnotation)8 Grammar (org.eclipse.xtext.Grammar)7 Set (java.util.Set)5 SingletonBinding (org.eclipse.xtext.service.SingletonBinding)5 GuiceModuleAccess (org.eclipse.xtext.xtext.generator.model.GuiceModuleAccess)5 List (java.util.List)3 EList (org.eclipse.emf.common.util.EList)1 EClass (org.eclipse.emf.ecore.EClass)1 EObject (org.eclipse.emf.ecore.EObject)1 AbstractRule (org.eclipse.xtext.AbstractRule)1 XtextPackage (org.eclipse.xtext.XtextPackage)1 INode (org.eclipse.xtext.nodemodel.INode)1 BinaryGrammarResourceFactoryImpl (org.eclipse.xtext.resource.impl.BinaryGrammarResourceFactoryImpl)1 IGrammarConstraintProvider (org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider)1 ISyntacticSequencerPDAProvider (org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider)1 AbstractDelegatingSemanticSequencer (org.eclipse.xtext.serializer.sequencer.AbstractDelegatingSemanticSequencer)1