Search in sources :

Example 11 with GeneratedJavaFileAccess

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

the class ImportNamespacesScopingFragment2 method generateGenScopeProvider.

protected void generateGenScopeProvider() {
    TypeReference _xifexpression = null;
    boolean _isGenerateStub = this.isGenerateStub();
    if (_isGenerateStub) {
        _xifexpression = this.getAbstractScopeProviderClass(this.getGrammar());
    } else {
        _xifexpression = this.getScopeProviderClass(this.getGrammar());
    }
    final TypeReference genClass = _xifexpression;
    final GeneratedJavaFileAccess file = this.fileAccessFactory.createGeneratedJavaFile(genClass);
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("public ");
            {
                boolean _isGenerateStub = ImportNamespacesScopingFragment2.this.isGenerateStub();
                if (_isGenerateStub) {
                    _builder.append("abstract ");
                }
            }
            _builder.append("class ");
            String _simpleName = genClass.getSimpleName();
            _builder.append(_simpleName);
            _builder.append(" extends ");
            TypeReference _scopeProviderSuperClass = ImportNamespacesScopingFragment2.this.getScopeProviderSuperClass(ImportNamespacesScopingFragment2.this.getGrammar());
            _builder.append(_scopeProviderSuperClass);
            _builder.append(" {");
            _builder.newLineIfNotEmpty();
            _builder.append("}");
            _builder.newLine();
        }
    };
    file.setContent(_client);
    file.writeTo(this.getProjectConfig().getRuntime().getSrcGen());
}
Also used : StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) GeneratedJavaFileAccess(org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference)

Example 12 with GeneratedJavaFileAccess

use of org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess 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 13 with GeneratedJavaFileAccess

use of org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess 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)

Example 14 with GeneratedJavaFileAccess

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

the class XtextGeneratorTemplates method createEclipsePluginExecutableExtensionFactory.

public JavaFileAccess createEclipsePluginExecutableExtensionFactory(final IXtextGeneratorLanguage langConfig, final IXtextGeneratorLanguage activatorLanguage) {
    final Grammar grammar = langConfig.getGrammar();
    final GeneratedJavaFileAccess file = this.fileAccessFactory.createGeneratedJavaFile(this.naming.getEclipsePluginExecutableExtensionFactory(grammar));
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("/**");
            _builder.newLine();
            _builder.append(" ");
            _builder.append("* This class was generated. Customizations should only happen in a newly");
            _builder.newLine();
            _builder.append(" ");
            _builder.append("* introduced subclass. ");
            _builder.newLine();
            _builder.append(" ");
            _builder.append("*/");
            _builder.newLine();
        }
    };
    file.setTypeComment(_client);
    StringConcatenationClient _client_1 = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("public class ");
            String _simpleName = XtextGeneratorTemplates.this.naming.getEclipsePluginExecutableExtensionFactory(grammar).getSimpleName();
            _builder.append(_simpleName);
            _builder.append(" extends ");
            TypeReference _typeRef = TypeReference.typeRef("org.eclipse.xtext.ui.guice.AbstractGuiceAwareExecutableExtensionFactory");
            _builder.append(_typeRef);
            _builder.append(" {");
            _builder.newLineIfNotEmpty();
            _builder.newLine();
            _builder.append("\t");
            _builder.append("@Override");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("protected ");
            TypeReference _typeRef_1 = TypeReference.typeRef("org.osgi.framework.Bundle");
            _builder.append(_typeRef_1, "\t");
            _builder.append(" getBundle() {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("return ");
            TypeReference _typeRef_2 = TypeReference.typeRef("org.eclipse.core.runtime.Platform");
            _builder.append(_typeRef_2, "\t\t");
            _builder.append(".getBundle(");
            TypeReference _eclipsePluginActivator = XtextGeneratorTemplates.this.naming.getEclipsePluginActivator();
            _builder.append(_eclipsePluginActivator, "\t\t");
            _builder.append(".PLUGIN_ID);");
            _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 ");
            _builder.append(Injector.class, "\t");
            _builder.append(" getInjector() {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            TypeReference _eclipsePluginActivator_1 = XtextGeneratorTemplates.this.naming.getEclipsePluginActivator();
            _builder.append(_eclipsePluginActivator_1, "\t\t");
            _builder.append(" activator = ");
            TypeReference _eclipsePluginActivator_2 = XtextGeneratorTemplates.this.naming.getEclipsePluginActivator();
            _builder.append(_eclipsePluginActivator_2, "\t\t");
            _builder.append(".getInstance();");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("return activator != null ? activator.getInjector(");
            TypeReference _eclipsePluginActivator_3 = XtextGeneratorTemplates.this.naming.getEclipsePluginActivator();
            _builder.append(_eclipsePluginActivator_3, "\t\t");
            _builder.append(".");
            String _replaceAll = langConfig.getGrammar().getName().toUpperCase().replaceAll("\\.", "_");
            _builder.append(_replaceAll, "\t\t");
            _builder.append(") : null;");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.newLine();
            _builder.append("}");
            _builder.newLine();
        }
    };
    file.setContent(_client_1);
    return file;
}
Also used : StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) GeneratedJavaFileAccess(org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess) Grammar(org.eclipse.xtext.Grammar) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference)

Example 15 with GeneratedJavaFileAccess

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

the class XtextGeneratorTemplates method createIdeGenModule.

public JavaFileAccess createIdeGenModule(final IXtextGeneratorLanguage langConfig) {
    final Grammar it = langConfig.getGrammar();
    TypeReference _elvis = null;
    TypeReference _superClass = langConfig.getIdeGenModule().getSuperClass();
    if (_superClass != null) {
        _elvis = _superClass;
    } else {
        TypeReference _genericIdeDefaultModule = this.naming.getGenericIdeDefaultModule(it);
        _elvis = _genericIdeDefaultModule;
    }
    final TypeReference superClass = _elvis;
    final GeneratedJavaFileAccess file = this.fileAccessFactory.createGeneratedJavaFile(this.naming.getGenericIdeGenModule(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.getGenericIdeModule(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.getGenericIdeGenModule(it).getSimpleName();
            _builder.append(_simpleName);
            _builder.append(" extends ");
            _builder.append(superClass);
            _builder.append(" {");
            _builder.newLineIfNotEmpty();
            _builder.newLine();
            {
                Set<GuiceModuleAccess.Binding> _bindings = langConfig.getIdeGenModule().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)

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