Search in sources :

Example 1 with ITreeAppendable

use of org.eclipse.xtext.xbase.compiler.output.ITreeAppendable in project xtext-xtend by eclipse.

the class XtendGenerator method generateJavaConstant.

private ITreeAppendable generateJavaConstant(final Object value, final ITreeAppendable appendable) {
    ITreeAppendable _xifexpression = null;
    if ((value instanceof Float)) {
        _xifexpression = appendable.append(((Float) value).toString()).append("f");
    } else {
        ITreeAppendable _xifexpression_1 = null;
        if ((value instanceof Long)) {
            _xifexpression_1 = appendable.append(((Long) value).toString()).append("l");
        } else {
            ITreeAppendable _xifexpression_2 = null;
            if ((value instanceof Character)) {
                _xifexpression_2 = appendable.append(Integer.toString(((Character) value).charValue()));
            } else {
                ITreeAppendable _xifexpression_3 = null;
                if ((value instanceof CharSequence)) {
                    _xifexpression_3 = appendable.append("\"").append(this.doConvertToJavaString(((CharSequence) value).toString())).append("\"");
                } else {
                    ITreeAppendable _xifexpression_4 = null;
                    if (((value instanceof Number) || (value instanceof Boolean))) {
                        _xifexpression_4 = appendable.append(value.toString());
                    } else {
                        _xifexpression_4 = appendable.append("null /* ERROR: illegal constant value */");
                    }
                    _xifexpression_3 = _xifexpression_4;
                }
                _xifexpression_2 = _xifexpression_3;
            }
            _xifexpression_1 = _xifexpression_2;
        }
        _xifexpression = _xifexpression_1;
    }
    return _xifexpression;
}
Also used : ITreeAppendable(org.eclipse.xtext.xbase.compiler.output.ITreeAppendable)

Example 2 with ITreeAppendable

use of org.eclipse.xtext.xbase.compiler.output.ITreeAppendable 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 3 with ITreeAppendable

use of org.eclipse.xtext.xbase.compiler.output.ITreeAppendable in project xtext-xtend by eclipse.

the class CompilationUnitImpl method setCompilationStrategy.

public void setCompilationStrategy(final JvmExecutable executable, final CompilationStrategy compilationStrategy) {
    this.checkCanceled();
    final Procedure1<ITreeAppendable> _function = (ITreeAppendable it) -> {
        final CompilationContextImpl context = new CompilationContextImpl(it, this);
        it.append(this.trimTrailingLinebreak(compilationStrategy.compile(context), executable));
    };
    this.jvmTypesBuilder.setBody(executable, _function);
}
Also used : CompilationContextImpl(org.eclipse.xtend.core.macro.CompilationContextImpl) ITreeAppendable(org.eclipse.xtext.xbase.compiler.output.ITreeAppendable)

Example 4 with ITreeAppendable

use of org.eclipse.xtext.xbase.compiler.output.ITreeAppendable in project xtext-xtend by eclipse.

the class CompilationUnitImpl method setCompilationStrategy.

public void setCompilationStrategy(final JvmField field, final CompilationStrategy compilationStrategy) {
    this.checkCanceled();
    final Procedure1<ITreeAppendable> _function = (ITreeAppendable it) -> {
        final CompilationContextImpl context = new CompilationContextImpl(it, this);
        it.append(compilationStrategy.compile(context));
    };
    this.jvmTypesBuilder.setInitializer(field, _function);
}
Also used : CompilationContextImpl(org.eclipse.xtend.core.macro.CompilationContextImpl) ITreeAppendable(org.eclipse.xtext.xbase.compiler.output.ITreeAppendable)

Example 5 with ITreeAppendable

use of org.eclipse.xtext.xbase.compiler.output.ITreeAppendable in project xtext-xtend by eclipse.

the class XtendCompiler method compileAnonymousClassBody.

protected void compileAnonymousClassBody(AnonymousClass anonymousClass, JvmDeclaredType type, ITreeAppendable b) {
    ITreeAppendable appendable = b.trace(anonymousClass, true);
    appendable.append(" ");
    appendable.openScope();
    GeneratorConfig config = generatorConfigProvider.get(anonymousClass);
    jvmModelGenerator.assignThisAndSuper(appendable, type, config);
    jvmModelGenerator.generateMembersInBody(type, appendable, config);
    appendable.closeScope();
}
Also used : GeneratorConfig(org.eclipse.xtext.xbase.compiler.GeneratorConfig) ITreeAppendable(org.eclipse.xtext.xbase.compiler.output.ITreeAppendable)

Aggregations

ITreeAppendable (org.eclipse.xtext.xbase.compiler.output.ITreeAppendable)9 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)3 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)3 EObject (org.eclipse.emf.ecore.EObject)2 CompilationContextImpl (org.eclipse.xtend.core.macro.CompilationContextImpl)2 JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)2 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)2 JvmField (org.eclipse.xtext.common.types.JvmField)2 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)2 JvmMember (org.eclipse.xtext.common.types.JvmMember)2 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)2 XExpression (org.eclipse.xtext.xbase.XExpression)2 Later (org.eclipse.xtext.xbase.compiler.Later)2 LoopParams (org.eclipse.xtext.xbase.compiler.LoopParams)2 Pair (org.eclipse.xtext.xbase.lib.Pair)2 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)2 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)2 Arrays (java.util.Arrays)1 StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)1 JvmExecutable (org.eclipse.xtext.common.types.JvmExecutable)1