Search in sources :

Example 66 with StringConcatenationClient

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

the class GrammarAccessFragment2 method generate.

@Override
public void generate() {
    final GuiceModuleAccess.BindingFactory bindingFactory = new GuiceModuleAccess.BindingFactory();
    String _name = this.getLanguage().getGrammar().getName();
    boolean _notEquals = (!Objects.equal(_name, "org.eclipse.xtext.common.Terminals"));
    if (_notEquals) {
        TypeReference _typeRef = TypeReference.typeRef(ClassLoader.class);
        StringConcatenationClient _client = new StringConcatenationClient() {

            @Override
            protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                _builder.append("getClass().getClassLoader()");
            }
        };
        bindingFactory.addTypeToInstance(_typeRef, _client);
    }
    bindingFactory.addTypeToType(TypeReference.typeRef(IGrammarAccess.class), this._grammarAccessExtensions.getGrammarAccess(this.getLanguage().getGrammar())).contributeTo(this.getLanguage().getRuntimeGenModule());
    ManifestAccess _manifest = this.getProjectConfig().getRuntime().getManifest();
    boolean _tripleNotEquals = (_manifest != null);
    if (_tripleNotEquals) {
        String _runtimeBasePackage = this._xtextGeneratorNaming.getRuntimeBasePackage(this.getGrammar());
        String _runtimeBasePackage_1 = this._xtextGeneratorNaming.getRuntimeBasePackage(this.getGrammar());
        String _plus = (_runtimeBasePackage_1 + ".services");
        this.getProjectConfig().getRuntime().getManifest().getExportedPackages().addAll(Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList(_runtimeBasePackage, _plus)));
    }
    this.doGenerateGrammarAccess();
    this.writeGrammar();
}
Also used : GuiceModuleAccess(org.eclipse.xtext.xtext.generator.model.GuiceModuleAccess) ManifestAccess(org.eclipse.xtext.xtext.generator.model.ManifestAccess) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference)

Example 67 with StringConcatenationClient

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

the class GrammarAccessFragment2 method _cache.

protected StringConcatenationClient _cache(final TerminalRule it) {
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("private final ");
            _builder.append(TerminalRule.class);
            _builder.append(" ");
            String _gaRuleAccessorLocalVarName = GrammarAccessFragment2.this.gaRuleAccessorLocalVarName(it);
            _builder.append(_gaRuleAccessorLocalVarName);
            _builder.append(";");
            _builder.newLineIfNotEmpty();
        }
    };
    return _client;
}
Also used : StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient)

Example 68 with StringConcatenationClient

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

the class GrammarAccessFragment2 method loadElementStatement.

protected StringConcatenationClient loadElementStatement(final AbstractElement ele) {
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("(");
            TypeReference _typeRef = TypeReference.typeRef(ele.eClass(), GrammarAccessFragment2.this.getLanguage());
            _builder.append(_typeRef);
            _builder.append(")");
            String _loadElementParentStatement = GrammarAccessFragment2.this.loadElementParentStatement(ele);
            _builder.append(_loadElementParentStatement);
            _builder.append(".eContents().get(");
            int _indexOf = ele.eContainer().eContents().indexOf(ele);
            _builder.append(_indexOf);
            _builder.append(")");
        }
    };
    return _client;
}
Also used : StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference)

Example 69 with StringConcatenationClient

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

the class EmfAdaptableProcessor method doTransform.

@Override
public void doTransform(final MutableClassDeclaration annotatedClass, @Extension final TransformationContext context) {
    final MutableClassDeclaration adapterClass = context.findClass(this.getAdapterClassName(annotatedClass));
    final Procedure1<MutableMethodDeclaration> _function = (MutableMethodDeclaration it) -> {
        it.addParameter("emfObject", context.newTypeReference(Notifier.class));
        it.setReturnType(context.newTypeReference(annotatedClass));
        it.setStatic(true);
        StringConcatenationClient _client = new StringConcatenationClient() {

            @Override
            protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                _builder.append("for (");
                _builder.append(Adapter.class);
                _builder.append(" adapter : emfObject.eAdapters()) {");
                _builder.newLineIfNotEmpty();
                _builder.append("\t");
                _builder.append("if (adapter instanceof ");
                _builder.append(adapterClass, "\t");
                _builder.append(") {");
                _builder.newLineIfNotEmpty();
                _builder.append("\t\t");
                _builder.append("return ((");
                _builder.append(adapterClass, "\t\t");
                _builder.append(") adapter).get();");
                _builder.newLineIfNotEmpty();
                _builder.append("\t");
                _builder.append("}");
                _builder.newLine();
                _builder.append("}");
                _builder.newLine();
                _builder.append("return null;");
                _builder.newLine();
            }
        };
        it.setBody(_client);
    };
    annotatedClass.addMethod("findInEmfObject", _function);
    final Procedure1<MutableMethodDeclaration> _function_1 = (MutableMethodDeclaration it) -> {
        it.addParameter("emfObject", context.newTypeReference(Notifier.class));
        it.setReturnType(context.newTypeReference(annotatedClass));
        it.setStatic(true);
        StringConcatenationClient _client = new StringConcatenationClient() {

            @Override
            protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                _builder.append(List.class);
                _builder.append("<");
                _builder.append(Adapter.class);
                _builder.append("> adapters = emfObject.eAdapters();");
                _builder.newLineIfNotEmpty();
                _builder.append("for(int i = 0, max = adapters.size(); i < max; i++) {");
                _builder.newLine();
                _builder.append("\t");
                _builder.append(Adapter.class, "\t");
                _builder.append(" adapter = adapters.get(i);");
                _builder.newLineIfNotEmpty();
                _builder.append("\t");
                _builder.append("if (adapter instanceof ");
                _builder.append(adapterClass, "\t");
                _builder.append(") {");
                _builder.newLineIfNotEmpty();
                _builder.append("\t\t");
                _builder.append("emfObject.eAdapters().remove(i);");
                _builder.newLine();
                _builder.append("\t\t");
                _builder.append("return ((");
                _builder.append(adapterClass, "\t\t");
                _builder.append(") adapter).get();");
                _builder.newLineIfNotEmpty();
                _builder.append("\t");
                _builder.append("}");
                _builder.newLine();
                _builder.append("}");
                _builder.newLine();
                _builder.append("return null;");
                _builder.newLine();
            }
        };
        it.setBody(_client);
    };
    annotatedClass.addMethod("removeFromEmfObject", _function_1);
    final Procedure1<MutableMethodDeclaration> _function_2 = (MutableMethodDeclaration it) -> {
        it.addParameter("emfObject", context.newTypeReference(Notifier.class));
        it.setReturnType(context.getPrimitiveVoid());
        StringConcatenationClient _client = new StringConcatenationClient() {

            @Override
            protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                String _simpleName = annotatedClass.getSimpleName();
                _builder.append(_simpleName);
                _builder.append(" result = findInEmfObject(emfObject);");
                _builder.newLineIfNotEmpty();
                _builder.append("if (result != null)");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("throw new IllegalStateException(\"The given EMF object already contains an adapter for ");
                String _simpleName_1 = annotatedClass.getSimpleName();
                _builder.append(_simpleName_1, "\t");
                _builder.append("\");");
                _builder.newLineIfNotEmpty();
                _builder.append(adapterClass);
                _builder.append(" adapter = new ");
                _builder.append(adapterClass);
                _builder.append("(this);");
                _builder.newLineIfNotEmpty();
                _builder.append("emfObject.eAdapters().add(adapter);");
                _builder.newLine();
            }
        };
        it.setBody(_client);
    };
    annotatedClass.addMethod("attachToEmfObject", _function_2);
    adapterClass.setExtendedClass(context.newTypeReference(AdapterImpl.class));
    final Procedure1<MutableFieldDeclaration> _function_3 = (MutableFieldDeclaration it) -> {
        it.setType(context.newTypeReference(annotatedClass));
    };
    adapterClass.addField("element", _function_3);
    final Procedure1<MutableConstructorDeclaration> _function_4 = (MutableConstructorDeclaration it) -> {
        it.addParameter("element", context.newTypeReference(annotatedClass));
        StringConcatenationClient _client = new StringConcatenationClient() {

            @Override
            protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                _builder.append("this.element = element;");
                _builder.newLine();
            }
        };
        it.setBody(_client);
    };
    adapterClass.addConstructor(_function_4);
    final Procedure1<MutableMethodDeclaration> _function_5 = (MutableMethodDeclaration it) -> {
        it.setReturnType(context.newTypeReference(annotatedClass));
        StringConcatenationClient _client = new StringConcatenationClient() {

            @Override
            protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                _builder.append("return this.element;");
                _builder.newLine();
            }
        };
        it.setBody(_client);
    };
    adapterClass.addMethod("get", _function_5);
    final Procedure1<MutableMethodDeclaration> _function_6 = (MutableMethodDeclaration it) -> {
        it.addAnnotation(context.newAnnotationReference(Override.class));
        it.addParameter("object", context.newTypeReference(Object.class));
        it.setReturnType(context.getPrimitiveBoolean());
        StringConcatenationClient _client = new StringConcatenationClient() {

            @Override
            protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                _builder.append("return object == ");
                _builder.append(annotatedClass);
                _builder.append(".class;");
                _builder.newLineIfNotEmpty();
            }
        };
        it.setBody(_client);
    };
    adapterClass.addMethod("isAdapterForType", _function_6);
}
Also used : MutableFieldDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableFieldDeclaration) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) MutableMethodDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableMethodDeclaration) AdapterImpl(org.eclipse.emf.common.notify.impl.AdapterImpl) Adapter(org.eclipse.emf.common.notify.Adapter) MutableClassDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration) MutableConstructorDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableConstructorDeclaration) List(java.util.List)

Example 70 with StringConcatenationClient

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

the class LogProcessor method doTransform.

@Override
public void doTransform(final MutableClassDeclaration cls, @Extension final TransformationContext context) {
    final Procedure1<MutableFieldDeclaration> _function = (MutableFieldDeclaration it) -> {
        it.setStatic(true);
        it.setFinal(true);
        it.setType(context.newTypeReference(Logger.class));
        StringConcatenationClient _client = new StringConcatenationClient() {

            @Override
            protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                _builder.append(Logger.class);
                _builder.append(".getLogger(");
                String _simpleName = cls.getSimpleName();
                _builder.append(_simpleName);
                _builder.append(".class)");
                _builder.newLineIfNotEmpty();
            }
        };
        it.setInitializer(_client);
        context.setPrimarySourceElement(it, cls);
    };
    cls.addField("LOG", _function);
}
Also used : MutableFieldDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableFieldDeclaration) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) Logger(org.apache.log4j.Logger)

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