Search in sources :

Example 56 with StringConcatenationClient

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

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

the class BuilderIntegrationFragment2 method addRuntimeGuiceBindings.

protected void addRuntimeGuiceBindings() {
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("binder.bind(");
            _builder.append(IResourceDescriptions.class);
            _builder.append(".class).to(");
            _builder.append(ResourceSetBasedResourceDescriptions.class);
            _builder.append(".class);");
        }
    };
    final StringConcatenationClient statement1 = _client;
    StringConcatenationClient _client_1 = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("binder.bind(");
            _builder.append(IResourceDescriptions.class);
            _builder.append(".class).annotatedWith(");
            _builder.append(Names.class);
            _builder.append(".named(");
            _builder.append(ResourceDescriptionsProvider.class);
            _builder.append(".PERSISTED_DESCRIPTIONS)).to(");
            _builder.append(ResourceSetBasedResourceDescriptions.class);
            _builder.append(".class);");
        }
    };
    final StringConcatenationClient statement2 = _client_1;
    GuiceModuleAccess.BindingFactory _addConfiguredBinding = new GuiceModuleAccess.BindingFactory().addTypeToType(TypeReference.typeRef(IContainer.Manager.class), TypeReference.typeRef(StateBasedContainerManager.class)).addTypeToType(TypeReference.typeRef(IAllContainersState.Provider.class), TypeReference.typeRef(ResourceSetBasedAllContainersStateProvider.class)).addConfiguredBinding(IResourceDescriptions.class.getSimpleName(), statement1);
    String _simpleName = IResourceDescriptions.class.getSimpleName();
    String _plus = (_simpleName + "Persisted");
    _addConfiguredBinding.addConfiguredBinding(_plus, statement2).contributeTo(this.getLanguage().getRuntimeGenModule());
}
Also used : IAllContainersState(org.eclipse.xtext.resource.containers.IAllContainersState) GuiceModuleAccess(org.eclipse.xtext.xtext.generator.model.GuiceModuleAccess) StateBasedContainerManager(org.eclipse.xtext.resource.containers.StateBasedContainerManager) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) IResourceDescriptions(org.eclipse.xtext.resource.IResourceDescriptions) StateBasedContainerManager(org.eclipse.xtext.resource.containers.StateBasedContainerManager)

Example 58 with StringConcatenationClient

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

the class EMFGeneratorFragment2 method generate.

@Override
public void generate() {
    boolean _isEmpty = IterableExtensions.isEmpty(Iterables.<GeneratedMetamodel>filter(this.getGrammar().getMetamodelDeclarations(), GeneratedMetamodel.class));
    if (_isEmpty) {
        return;
    }
    try {
        final Grammar clonedGrammar = this.cloneGrammarIntoNewResourceSet(this.getGrammar());
        final ResourceSet workingResourceSet = clonedGrammar.eResource().getResourceSet();
        final Function1<GeneratedMetamodel, EPackage> _function = (GeneratedMetamodel it) -> {
            return it.getEPackage();
        };
        final List<EPackage> generatedPackages = IterableExtensions.<EPackage>toList(IterableExtensions.<GeneratedMetamodel, EPackage>map(Iterables.<GeneratedMetamodel>filter(clonedGrammar.getMetamodelDeclarations(), GeneratedMetamodel.class), _function));
        if ((this.genModel != null)) {
            this.registerUsedGenModel(workingResourceSet.getURIConverter(), clonedGrammar);
        }
        boolean _isEmpty_1 = generatedPackages.isEmpty();
        boolean _not = (!_isEmpty_1);
        if (_not) {
            final Map<String, EPackage> usedEPackages = this.findAllUsedEPackages(generatedPackages);
            final Map<String, EPackage> loadedEPackages = this.findEPackagesInGenPackages(usedEPackages.keySet(), workingResourceSet);
            final Map<EObject, EObject> eNamedElementMapping = this.createENamedElementMapping(usedEPackages, loadedEPackages);
            this.replaceReferencesInGeneratedPackages(generatedPackages, eNamedElementMapping);
            final Resource ePackageResource = this.createResourceForEPackages(clonedGrammar, generatedPackages, workingResourceSet);
            if ((!this.skipGenerate)) {
                StringConcatenation _builder = new StringConcatenation();
                _builder.append("Generating EMF model");
                {
                    if (this.generateEdit) {
                        {
                            if (this.generateEditor) {
                                _builder.append(", edit");
                            } else {
                                _builder.append(" and edit");
                            }
                        }
                    }
                }
                {
                    if (this.generateEditor) {
                        _builder.append(" and editor");
                    }
                }
                _builder.append(" code");
                EMFGeneratorFragment2.LOG.info(_builder);
                final GenModel genModel = this.getSaveAndReconcileGenModel(clonedGrammar, generatedPackages, workingResourceSet);
                genModel.reconcile();
                this.doGenerate(genModel);
                this.addProjectContributions(clonedGrammar, generatedPackages, workingResourceSet);
                if (this.bindEPackageAndEFactory) {
                    for (final EPackage pkg : generatedPackages) {
                        {
                            final GenPackage genPkg = GenModelUtil2.getGenPackage(pkg, genModel.eResource().getResourceSet());
                            GuiceModuleAccess.BindingFactory _bindingFactory = new GuiceModuleAccess.BindingFactory();
                            TypeReference _typeRef = TypeReference.typeRef(genPkg.getQualifiedPackageInterfaceName());
                            StringConcatenationClient _client = new StringConcatenationClient() {

                                @Override
                                protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                                    String _packageInterfaceName = genPkg.getPackageInterfaceName();
                                    _builder.append(_packageInterfaceName);
                                    _builder.append(".eINSTANCE");
                                }
                            };
                            GuiceModuleAccess.BindingFactory _addTypeToInstance = _bindingFactory.addTypeToInstance(_typeRef, _client);
                            TypeReference _typeRef_1 = TypeReference.typeRef(genPkg.getQualifiedFactoryInterfaceName());
                            StringConcatenationClient _client_1 = new StringConcatenationClient() {

                                @Override
                                protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                                    String _factoryInterfaceName = genPkg.getFactoryInterfaceName();
                                    _builder.append(_factoryInterfaceName);
                                    _builder.append(".eINSTANCE");
                                }
                            };
                            _addTypeToInstance.addTypeToInstance(_typeRef_1, _client_1).contributeTo(this.getLanguage().getRuntimeGenModule());
                        }
                    }
                }
            }
            this.saveResource(ePackageResource);
        }
        this.updateBuildProperties();
    } catch (final Throwable _t) {
        if (_t instanceof Exception) {
            final Exception e = (Exception) _t;
            EMFGeneratorFragment2.LOG.error("Failed to execute EMF generator", e);
        } else {
            throw Exceptions.sneakyThrow(_t);
        }
    }
}
Also used : GuiceModuleAccess(org.eclipse.xtext.xtext.generator.model.GuiceModuleAccess) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) Resource(org.eclipse.emf.ecore.resource.Resource) XMLResource(org.eclipse.emf.ecore.xmi.XMLResource) Grammar(org.eclipse.xtext.Grammar) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) GenPackage(org.eclipse.emf.codegen.ecore.genmodel.GenPackage) EPackage(org.eclipse.emf.ecore.EPackage) GeneratedMetamodel(org.eclipse.xtext.GeneratedMetamodel) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) GenModel(org.eclipse.emf.codegen.ecore.genmodel.GenModel) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference)

Example 59 with StringConcatenationClient

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

the class Formatter2Fragment2 method doGenerateStubFile.

protected void doGenerateStubFile() {
    boolean _isGenerateStub = this.isGenerateStub();
    boolean _not = (!_isGenerateStub);
    if (_not) {
        return;
    }
    boolean _isGenerateXtendStub = this.isGenerateXtendStub();
    if (_isGenerateXtendStub) {
        final XtendFileAccess xtendFile = this.fileAccessFactory.createXtendFile(this.getFormatter2Stub(this.getGrammar()));
        xtendFile.setResourceSet(this.getLanguage().getResourceSet());
        final LinkedHashMultimap<EClass, EReference> type2ref = LinkedHashMultimap.<EClass, EReference>create();
        this.getLocallyAssignedContainmentReferences(this.getLanguage().getGrammar(), type2ref);
        final LinkedHashMultimap<EClass, EReference> inheritedTypes = LinkedHashMultimap.<EClass, EReference>create();
        this.getInheritedContainmentReferences(this.getLanguage().getGrammar(), inheritedTypes, CollectionLiterals.<Grammar>newHashSet());
        final Set<EClass> types = type2ref.keySet();
        StringConcatenationClient _client = new StringConcatenationClient() {

            @Override
            protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                _builder.append("class ");
                String _simpleName = Formatter2Fragment2.this.getFormatter2Stub(Formatter2Fragment2.this.getGrammar()).getSimpleName();
                _builder.append(_simpleName);
                _builder.append(" extends ");
                TypeReference _stubSuperClass = Formatter2Fragment2.this.getStubSuperClass();
                _builder.append(_stubSuperClass);
                _builder.append(" {");
                _builder.newLineIfNotEmpty();
                _builder.append("\t");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("@");
                _builder.append(Inject.class, "\t");
                _builder.append(" extension ");
                TypeReference _grammarAccess = Formatter2Fragment2.this._grammarAccessExtensions.getGrammarAccess(Formatter2Fragment2.this.getGrammar());
                _builder.append(_grammarAccess, "\t");
                _builder.newLineIfNotEmpty();
                {
                    Iterable<EClass> _take = IterableExtensions.<EClass>take(types, 2);
                    for (final EClass type : _take) {
                        _builder.newLine();
                        _builder.append("\t");
                        StringConcatenationClient _generateFormatMethod = Formatter2Fragment2.this.generateFormatMethod(type, type2ref.get(type), inheritedTypes.containsKey(type));
                        _builder.append(_generateFormatMethod, "\t");
                        _builder.newLineIfNotEmpty();
                    }
                }
                _builder.append("\t");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("// TODO: implement for ");
                final Function1<EClass, String> _function = (EClass it) -> {
                    return it.getName();
                };
                String _join = IterableExtensions.join(IterableExtensions.<EClass, String>map(IterableExtensions.<EClass>drop(types, 2), _function), ", ");
                _builder.append(_join, "\t");
                _builder.newLineIfNotEmpty();
                _builder.append("}");
                _builder.newLine();
            }
        };
        xtendFile.setContent(_client);
        xtendFile.writeTo(this.getProjectConfig().getRuntime().getSrc());
    } else {
        String _name = this.getClass().getName();
        String _plus = (_name + " has been configured to generate a Java stub, but that\'s not yet supported. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=481563");
        Formatter2Fragment2.LOG.error(_plus);
    }
}
Also used : XtendFileAccess(org.eclipse.xtext.xtext.generator.model.XtendFileAccess) EClass(org.eclipse.emf.ecore.EClass) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference) EReference(org.eclipse.emf.ecore.EReference)

Example 60 with StringConcatenationClient

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

the class Formatter2Fragment2 method generate.

@Override
public void generate() {
    boolean _isGenerateStub = this.isGenerateStub();
    boolean _not = (!_isGenerateStub);
    if (_not) {
        return;
    }
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("binder.bind(");
            _builder.append(IPreferenceValuesProvider.class);
            _builder.append(".class).annotatedWith(");
            _builder.append(FormatterPreferences.class);
            _builder.append(".class).to(");
            _builder.append(FormatterPreferenceValuesProvider.class);
            _builder.append(".class);");
        }
    };
    final StringConcatenationClient statement = _client;
    new GuiceModuleAccess.BindingFactory().addTypeToType(TypeReference.typeRef(IFormatter2.class), this.getFormatter2Stub(this.getLanguage().getGrammar())).addConfiguredBinding(FormatterPreferences.class.getSimpleName(), statement).contributeTo(this.getLanguage().getRuntimeGenModule());
    new GuiceModuleAccess.BindingFactory().addTypeToType(TypeReference.typeRef("org.eclipse.xtext.ui.editor.formatting.IContentFormatterFactory"), TypeReference.typeRef("org.eclipse.xtext.ui.editor.formatting2.ContentFormatterFactory")).contributeTo(this.getLanguage().getEclipsePluginGenModule());
    ManifestAccess _manifest = this.getProjectConfig().getRuntime().getManifest();
    boolean _tripleNotEquals = (_manifest != null);
    if (_tripleNotEquals) {
        Set<String> _exportedPackages = this.getProjectConfig().getRuntime().getManifest().getExportedPackages();
        String _runtimeBasePackage = this._xtextGeneratorNaming.getRuntimeBasePackage(this.getGrammar());
        String _plus = (_runtimeBasePackage + ".formatting2");
        _exportedPackages.add(_plus);
    }
    this.doGenerateStubFile();
}
Also used : GuiceModuleAccess(org.eclipse.xtext.xtext.generator.model.GuiceModuleAccess) IFormatter2(org.eclipse.xtext.formatting2.IFormatter2) ManifestAccess(org.eclipse.xtext.xtext.generator.model.ManifestAccess) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient)

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