Search in sources :

Example 76 with StringConcatenationClient

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

the class ResourceFactoryFragment2 method generate.

@Override
public void generate() {
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append(IResourceFactory.class);
            _builder.append(" resourceFactory = injector.getInstance(");
            _builder.append(IResourceFactory.class);
            _builder.append(".class);");
            _builder.newLineIfNotEmpty();
            _builder.append(IResourceServiceProvider.class);
            _builder.append(" serviceProvider = injector.getInstance(");
            _builder.append(IResourceServiceProvider.class);
            _builder.append(".class);");
            _builder.newLineIfNotEmpty();
            _builder.newLine();
            {
                List<String> _fileExtensions = ResourceFactoryFragment2.this.getLanguage().getFileExtensions();
                for (final String fileExtension : _fileExtensions) {
                    _builder.append(Resource.class);
                    _builder.append(".Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(\"");
                    _builder.append(fileExtension);
                    _builder.append("\", resourceFactory);");
                    _builder.newLineIfNotEmpty();
                    _builder.append(IResourceServiceProvider.class);
                    _builder.append(".Registry.INSTANCE.getExtensionToFactoryMap().put(\"");
                    _builder.append(fileExtension);
                    _builder.append("\", serviceProvider);");
                    _builder.newLineIfNotEmpty();
                }
            }
        }
    };
    this.getLanguage().getRuntimeGenSetup().getRegistrations().add(_client);
    IBundleProjectConfig _eclipsePlugin = this.getProjectConfig().getEclipsePlugin();
    PluginXmlAccess _pluginXml = null;
    if (_eclipsePlugin != null) {
        _pluginXml = _eclipsePlugin.getPluginXml();
    }
    boolean _tripleNotEquals = (_pluginXml != null);
    if (_tripleNotEquals) {
        List<CharSequence> _entries = this.getProjectConfig().getEclipsePlugin().getPluginXml().getEntries();
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("<!-- adding resource factories -->");
        _builder.newLine();
        {
            List<String> _fileExtensions = this.getLanguage().getFileExtensions();
            for (final String fileExtension : _fileExtensions) {
                _builder.append("<extension");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("point=\"org.eclipse.emf.ecore.extension_parser\">");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("<parser");
                _builder.newLine();
                _builder.append("\t\t");
                _builder.append("class=\"");
                TypeReference _eclipsePluginExecutableExtensionFactory = this._xtextGeneratorNaming.getEclipsePluginExecutableExtensionFactory(this.getGrammar());
                _builder.append(_eclipsePluginExecutableExtensionFactory, "\t\t");
                _builder.append(":org.eclipse.xtext.resource.IResourceFactory\"");
                _builder.newLineIfNotEmpty();
                _builder.append("\t\t");
                _builder.append("type=\"");
                _builder.append(fileExtension, "\t\t");
                _builder.append("\">");
                _builder.newLineIfNotEmpty();
                _builder.append("\t");
                _builder.append("</parser>");
                _builder.newLine();
                _builder.append("</extension>");
                _builder.newLine();
                _builder.append("<extension point=\"org.eclipse.xtext.extension_resourceServiceProvider\">");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("<resourceServiceProvider");
                _builder.newLine();
                _builder.append("\t\t");
                _builder.append("class=\"");
                TypeReference _eclipsePluginExecutableExtensionFactory_1 = this._xtextGeneratorNaming.getEclipsePluginExecutableExtensionFactory(this.getGrammar());
                _builder.append(_eclipsePluginExecutableExtensionFactory_1, "\t\t");
                _builder.append(":org.eclipse.xtext.ui.resource.IResourceUIServiceProvider\"");
                _builder.newLineIfNotEmpty();
                _builder.append("\t\t");
                _builder.append("uriExtension=\"");
                _builder.append(fileExtension, "\t\t");
                _builder.append("\">");
                _builder.newLineIfNotEmpty();
                _builder.append("\t");
                _builder.append("</resourceServiceProvider>");
                _builder.newLine();
                _builder.append("</extension>");
                _builder.newLine();
            }
        }
        _entries.add(_builder.toString());
    }
}
Also used : IBundleProjectConfig(org.eclipse.xtext.xtext.generator.model.project.IBundleProjectConfig) PluginXmlAccess(org.eclipse.xtext.xtext.generator.model.PluginXmlAccess) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) Resource(org.eclipse.emf.ecore.resource.Resource) IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) List(java.util.List) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference)

Example 77 with StringConcatenationClient

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

the class ImportNamespacesScopingFragment2 method generateJavaScopeProvider.

protected void generateJavaScopeProvider() {
    TypeReference _scopeProviderClass = this.getScopeProviderClass(this.getGrammar());
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("/**");
            _builder.newLine();
            _builder.append(" ");
            _builder.append("* This class contains custom scoping description.");
            _builder.newLine();
            _builder.append(" ");
            _builder.append("* ");
            _builder.newLine();
            _builder.append(" ");
            _builder.append("* See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#scoping");
            _builder.newLine();
            _builder.append(" ");
            _builder.append("* on how and when to use it.");
            _builder.newLine();
            _builder.append(" ");
            _builder.append("*/");
            _builder.newLine();
            _builder.append("public class ");
            String _simpleName = ImportNamespacesScopingFragment2.this.getScopeProviderClass(ImportNamespacesScopingFragment2.this.getGrammar()).getSimpleName();
            _builder.append(_simpleName);
            _builder.append(" extends ");
            TypeReference _abstractScopeProviderClass = ImportNamespacesScopingFragment2.this.getAbstractScopeProviderClass(ImportNamespacesScopingFragment2.this.getGrammar());
            _builder.append(_abstractScopeProviderClass);
            _builder.append(" {");
            _builder.newLineIfNotEmpty();
            _builder.newLine();
            _builder.append("}");
            _builder.newLine();
        }
    };
    this.fileAccessFactory.createJavaFile(_scopeProviderClass, _client).writeTo(this.getProjectConfig().getRuntime().getSrc());
}
Also used : StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference)

Example 78 with StringConcatenationClient

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

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

the class SerializerFragment2 method genMethodSequenceComment.

private StringConcatenationClient genMethodSequenceComment(final IGrammarConstraintProvider.IConstraint c) {
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("// This method is commented out because it has the same signature as another method in this class.");
            _builder.newLine();
            _builder.append("// This is probably a bug in Xtext\'s serializer, please report it here: ");
            _builder.newLine();
            _builder.append("// https://bugs.eclipse.org/bugs/enter_bug.cgi?product=TMF");
            _builder.newLine();
            _builder.append("//");
            _builder.newLine();
            _builder.append("// Contexts:");
            _builder.newLine();
            _builder.append("//     ");
            String _replaceAll = IterableExtensions.join(IterableExtensions.<ISerializationContext>sort(c.getContexts()), "\n").replaceAll("\\n", "\n//     ");
            _builder.append(_replaceAll);
            _builder.newLineIfNotEmpty();
            _builder.append("//");
            _builder.newLine();
            _builder.append("// Constraint:");
            _builder.newLine();
            _builder.append("//     ");
            {
                IGrammarConstraintProvider.IConstraintElement _body = c.getBody();
                boolean _tripleEquals = (_body == null);
                if (_tripleEquals) {
                    _builder.append("{");
                    String _name = c.getType().getName();
                    _builder.append(_name);
                    _builder.append("}");
                } else {
                    String _replaceAll_1 = c.getBody().toString().replaceAll("\\n", "\n//     ");
                    _builder.append(_replaceAll_1);
                }
            }
            _builder.newLineIfNotEmpty();
            _builder.append("//");
            _builder.newLine();
            _builder.append("// protected void sequence_");
            String _simpleName = c.getSimpleName();
            _builder.append(_simpleName);
            _builder.append("(");
            _builder.append(ISerializationContext.class);
            _builder.append(" context, ");
            EClass _type = c.getType();
            _builder.append(_type);
            _builder.append(" semanticObject) { }");
            _builder.newLineIfNotEmpty();
        }
    };
    return _client;
}
Also used : EClass(org.eclipse.emf.ecore.EClass) ISerializationContext(org.eclipse.xtext.serializer.ISerializationContext) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient)

Example 80 with StringConcatenationClient

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

the class SerializerFragment2 method genGetUnassignedRuleCallTokens.

private StringConcatenationClient genGetUnassignedRuleCallTokens() {
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("@Override");
            _builder.newLine();
            _builder.append("protected String getUnassignedRuleCallToken(");
            _builder.append(EObject.class);
            _builder.append(" semanticObject, ");
            _builder.append(RuleCall.class);
            _builder.append(" ruleCall, ");
            _builder.append(INode.class);
            _builder.append(" node) {");
            _builder.newLineIfNotEmpty();
            {
                Iterable<Pair<Integer, AbstractRule>> _indexed = IterableExtensions.<AbstractRule>indexed(SerializerFragment2.this.unassignedCalledTokenRules());
                for (final Pair<Integer, AbstractRule> rule : _indexed) {
                    _builder.append("\t");
                    {
                        Integer _key = rule.getKey();
                        boolean _greaterThan = ((_key).intValue() > 0);
                        if (_greaterThan) {
                            _builder.append("else ");
                        }
                    }
                    _builder.append("if (ruleCall.getRule() == grammarAccess.");
                    String _gaAccessor = SerializerFragment2.this._grammarAccessExtensions.gaAccessor(rule.getValue());
                    _builder.append(_gaAccessor, "\t");
                    _builder.append(")");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("return ");
                    CharSequence _unassignedCalledTokenRuleName = SerializerFragment2.this.unassignedCalledTokenRuleName(rule.getValue());
                    _builder.append(_unassignedCalledTokenRuleName, "\t\t");
                    _builder.append("(semanticObject, ruleCall, node);");
                    _builder.newLineIfNotEmpty();
                }
            }
            _builder.append("\t");
            _builder.append("return \"\";");
            _builder.newLine();
            _builder.append("}");
            _builder.newLine();
        }
    };
    return _client;
}
Also used : StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) AbstractRule(org.eclipse.xtext.AbstractRule) Pair(org.eclipse.xtext.xbase.lib.Pair)

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