Search in sources :

Example 1 with StringConcatenationClient

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

the class XtendGenerator method generateMembersInBody.

@Override
public ITreeAppendable generateMembersInBody(final JvmDeclaredType it, final ITreeAppendable appendable, final GeneratorConfig config) {
    ITreeAppendable _xifexpression = null;
    boolean _isLocal = it.isLocal();
    if (_isLocal) {
        ITreeAppendable _xblockexpression = null;
        {
            appendable.append("{").increaseIndentation();
            EObject _head = IterableExtensions.<EObject>head(this.getSourceElements(it));
            final AnonymousClass anonymousClass = ((AnonymousClass) _head);
            if (((!appendable.hasName(Pair.<String, JvmDeclaredType>of("this", it))) && this.needSyntheticThisVariable(anonymousClass, it))) {
                final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(anonymousClass);
                final LightweightTypeReference actualType = resolvedTypes.getActualType(anonymousClass);
                Pair<String, JvmDeclaredType> _mappedTo = Pair.<String, JvmDeclaredType>of("this", it);
                final String thisName = appendable.declareSyntheticVariable(_mappedTo, "_this");
                appendable.newLine().append("final ").append(actualType).append(" ").append(thisName).append(" = this;");
            }
            final Function1<JvmField, Boolean> _function = (JvmField it_1) -> {
                boolean _xblockexpression_1 = false;
                {
                    Procedure1<? super ITreeAppendable> _compilationStrategy = this._jvmTypeExtensions.getCompilationStrategy(it_1);
                    boolean _tripleNotEquals = (_compilationStrategy != null);
                    if (_tripleNotEquals) {
                        return Boolean.valueOf(true);
                    } else {
                        StringConcatenationClient _compilationTemplate = this._jvmTypeExtensions.getCompilationTemplate(it_1);
                        boolean _tripleNotEquals_1 = (_compilationTemplate != null);
                        if (_tripleNotEquals_1) {
                            return Boolean.valueOf(true);
                        } else {
                            boolean _not = (!(it_1.isFinal() && it_1.isStatic()));
                            if (_not) {
                                final XExpression expression = this._iLogicalContainerProvider.getAssociatedExpression(it_1);
                                if (((expression != null) && config.isGenerateExpressions())) {
                                    return Boolean.valueOf(true);
                                }
                            }
                        }
                    }
                    _xblockexpression_1 = false;
                }
                return Boolean.valueOf(_xblockexpression_1);
            };
            final Iterable<JvmField> fieldsWithInitializer = IterableExtensions.<JvmField>filter(it.getDeclaredFields(), _function);
            boolean _isEmpty = IterableExtensions.isEmpty(fieldsWithInitializer);
            boolean _not = (!_isEmpty);
            if (_not) {
                appendable.newLine().append("{").increaseIndentation();
                final Procedure1<LoopParams> _function_1 = (LoopParams it_1) -> {
                    final Function1<ITreeAppendable, ITreeAppendable> _function_2 = (ITreeAppendable it_2) -> {
                        return it_2.newLine();
                    };
                    it_1.setSeparator(_function_2);
                };
                final Procedure1<JvmField> _function_2 = (JvmField it_1) -> {
                    final ITreeAppendable memberAppendable = this._treeAppendableUtil.traceWithComments(appendable, it_1);
                    memberAppendable.openScope();
                    appendable.newLine();
                    final ITreeAppendable tracedAppendable = appendable.trace(it_1);
                    this._treeAppendableUtil.traceSignificant(tracedAppendable, it_1).append(it_1.getSimpleName());
                    this.generateInitialization(it_1, tracedAppendable, config);
                    tracedAppendable.append(";");
                    memberAppendable.closeScope();
                };
                this._loopExtensions.<JvmField>forEach(appendable, fieldsWithInitializer, _function_1, _function_2);
                appendable.decreaseIndentation().newLine().append("}");
            }
            final Procedure1<LoopParams> _function_3 = (LoopParams it_1) -> {
                final Function1<ITreeAppendable, ITreeAppendable> _function_4 = (ITreeAppendable it_2) -> {
                    return it_2.newLine();
                };
                it_1.setSeparator(_function_4);
            };
            final Procedure1<JvmMember> _function_4 = (JvmMember it_1) -> {
                final ITreeAppendable memberAppendable = this._treeAppendableUtil.traceWithComments(appendable, it_1);
                memberAppendable.openScope();
                this.generateMember(it_1, memberAppendable, config);
                memberAppendable.closeScope();
            };
            this._loopExtensions.<JvmMember>forEach(appendable, this.getMembersToBeCompiled(it), _function_3, _function_4);
            _xblockexpression = appendable.decreaseIndentation().newLine().append("}");
        }
        _xifexpression = _xblockexpression;
    } else {
        _xifexpression = super.generateMembersInBody(it, appendable, config);
    }
    return _xifexpression;
}
Also used : LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) IResolvedTypes(org.eclipse.xtext.xbase.typesystem.IResolvedTypes) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) ITreeAppendable(org.eclipse.xtext.xbase.compiler.output.ITreeAppendable) LoopParams(org.eclipse.xtext.xbase.compiler.LoopParams) AnonymousClass(org.eclipse.xtend.core.xtend.AnonymousClass) EObject(org.eclipse.emf.ecore.EObject) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) XExpression(org.eclipse.xtext.xbase.XExpression) JvmMember(org.eclipse.xtext.common.types.JvmMember) JvmField(org.eclipse.xtext.common.types.JvmField) Pair(org.eclipse.xtext.xbase.lib.Pair)

Example 2 with StringConcatenationClient

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

the class MutableJvmFieldDeclarationImpl method setConstantValueAsDouble.

@Override
public void setConstantValueAsDouble(final double value) {
    this.internalGenericSetConstantValue(Double.valueOf(value));
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append(value);
            _builder.append("d");
        }
    };
    this.getCompilationUnit().setCompilationTemplate(this.getDelegate(), _client);
}
Also used : StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient)

Example 3 with StringConcatenationClient

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

the class MutableJvmFieldDeclarationImpl method setConstantValueAsLong.

@Override
public void setConstantValueAsLong(final long value) {
    this.internalGenericSetConstantValue(Long.valueOf(value));
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append(value);
            _builder.append("L");
        }
    };
    this.getCompilationUnit().setCompilationTemplate(this.getDelegate(), _client);
}
Also used : StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient)

Example 4 with StringConcatenationClient

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

the class AddInterfaceWithDefaultProcessor method doTransform.

@Override
public void doTransform(final MutableClassDeclaration annotatedClass, @Extension final TransformationContext context) {
    super.doTransform(annotatedClass, context);
    Type _findTypeGlobally = context.findTypeGlobally("de.test.Test");
    final MutableInterfaceDeclaration ifType = ((MutableInterfaceDeclaration) _findTypeGlobally);
    final Procedure1<MutableMethodDeclaration> _function = (MutableMethodDeclaration it) -> {
        StringConcatenationClient _client = new StringConcatenationClient() {

            @Override
            protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                _builder.append("System.out.println(\"Hello World\");");
            }
        };
        it.setBody(_client);
        it.setDefault(true);
    };
    ifType.addMethod("sayHello", _function);
}
Also used : MutableInterfaceDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableInterfaceDeclaration) Type(org.eclipse.xtend.lib.macro.declaration.Type) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) MutableMethodDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableMethodDeclaration)

Example 5 with StringConcatenationClient

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

the class Bug446364Processor method doTransform.

@Override
public void doTransform(final MutableClassDeclaration annotatedClass, @Extension final TransformationContext context) {
    String _stringValue = IterableExtensions.head(annotatedClass.getAnnotations()).getStringValue("value");
    if (_stringValue != null) {
        switch(_stringValue) {
            case "rename":
                final Consumer<MutableMethodDeclaration> _function = (MutableMethodDeclaration it) -> {
                    String _simpleName = it.getSimpleName();
                    String _plus = ("prefix_" + _simpleName);
                    it.setSimpleName(_plus);
                };
                annotatedClass.getDeclaredMethods().forEach(_function);
                break;
            case "changeBody":
                final Consumer<MutableMethodDeclaration> _function_1 = (MutableMethodDeclaration it) -> {
                    StringConcatenationClient _client = new StringConcatenationClient() {

                        @Override
                        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                            _builder.append("return null;");
                        }
                    };
                    it.setBody(_client);
                };
                annotatedClass.getDeclaredMethods().forEach(_function_1);
                break;
        }
    }
}
Also used : StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) MutableMethodDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableMethodDeclaration)

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