Search in sources :

Example 6 with ISourceAppender

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

the class AbstractCodeBuilder method appendTypeParameters.

protected ISourceAppender appendTypeParameters(final ISourceAppender appendable, final List<JvmTypeParameter> typeParameters) {
    ISourceAppender _xblockexpression = null;
    {
        final Iterator<JvmTypeParameter> iterator = typeParameters.iterator();
        boolean _hasNext = iterator.hasNext();
        if (_hasNext) {
            appendable.append("<");
            do {
                {
                    final JvmTypeParameter typeParameter = iterator.next();
                    appendable.append(typeParameter.getName());
                    final Function1<JvmUpperBound, Boolean> _function = (JvmUpperBound it) -> {
                        String _identifier = it.getTypeReference().getIdentifier();
                        return Boolean.valueOf((!Objects.equal(_identifier, "java.lang.Object")));
                    };
                    final Iterable<JvmUpperBound> upperBounds = IterableExtensions.<JvmUpperBound>filter(Iterables.<JvmUpperBound>filter(typeParameter.getConstraints(), JvmUpperBound.class), _function);
                    boolean _isEmpty = IterableExtensions.isEmpty(upperBounds);
                    boolean _not = (!_isEmpty);
                    if (_not) {
                        appendable.append(" extends ");
                        boolean isFirst = true;
                        final StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(this.services, this.context);
                        for (final JvmUpperBound upperBound : upperBounds) {
                            {
                                if ((!isFirst)) {
                                    appendable.append(" & ");
                                }
                                isFirst = false;
                                this.appendType(appendable, owner.toLightweightTypeReference(upperBound.getTypeReference()), "Object");
                            }
                        }
                    }
                    boolean _hasNext_1 = iterator.hasNext();
                    if (_hasNext_1) {
                        appendable.append(",");
                    }
                }
            } while (iterator.hasNext());
            appendable.append("> ");
        }
        _xblockexpression = appendable;
    }
    return _xblockexpression;
}
Also used : JvmUpperBound(org.eclipse.xtext.common.types.JvmUpperBound) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) Iterator(java.util.Iterator) ISourceAppender(org.eclipse.xtext.xbase.compiler.ISourceAppender) StandardTypeReferenceOwner(org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner)

Example 7 with ISourceAppender

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

the class AbstractExecutableBuilder method appendThrowsClause.

protected ISourceAppender appendThrowsClause(final ISourceAppender appendable) {
    ISourceAppender _xblockexpression = null;
    {
        final Iterator<LightweightTypeReference> iterator = this.exceptions.iterator();
        boolean _hasNext = iterator.hasNext();
        if (_hasNext) {
            appendable.append(" throws ");
            do {
                {
                    final LightweightTypeReference typeRef = iterator.next();
                    if ((typeRef != null)) {
                        this.appendType(appendable, typeRef, "Exception");
                    }
                    boolean _hasNext_1 = iterator.hasNext();
                    if (_hasNext_1) {
                        appendable.append(", ");
                    }
                }
            } while (iterator.hasNext());
        }
        _xblockexpression = appendable;
    }
    return _xblockexpression;
}
Also used : LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) Iterator(java.util.Iterator) ISourceAppender(org.eclipse.xtext.xbase.compiler.ISourceAppender)

Example 8 with ISourceAppender

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

the class AbstractExecutableBuilder method appendParameters.

protected ISourceAppender appendParameters(final ISourceAppender appendable) {
    ISourceAppender _xblockexpression = null;
    {
        appendable.append("(");
        final HashSet<String> notAllowed = CollectionLiterals.<String>newHashSet();
        boolean _isEmpty = this.parameterBuilders.isEmpty();
        boolean _not = (!_isEmpty);
        if (_not) {
            AbstractParameterBuilder _last = IterableExtensions.<AbstractParameterBuilder>last(this.parameterBuilders);
            _last.setVarArgsFlag(this.varArgsFlag);
        }
        int _size = this.parameterBuilders.size();
        ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, _size, true);
        for (final Integer i : _doubleDotLessThan) {
            {
                final AbstractParameterBuilder parameterBuilder = this.parameterBuilders.get((i).intValue());
                final VariableNameAcceptor acceptor = new VariableNameAcceptor(notAllowed);
                String _name = parameterBuilder.getName();
                boolean _tripleEquals = (_name == null);
                if (_tripleEquals) {
                    this._jdtVariableCompletions.getVariableProposals(parameterBuilder.getType().getIdentifier(), this.getContext(), JdtVariableCompletions.VariableType.PARAMETER, notAllowed, acceptor);
                    parameterBuilder.setName(acceptor.getVariableName());
                }
                parameterBuilder.build(appendable);
                int _size_1 = this.parameterBuilders.size();
                int _minus = (_size_1 - 1);
                boolean _notEquals = ((i).intValue() != _minus);
                if (_notEquals) {
                    appendable.append(", ");
                }
            }
        }
        _xblockexpression = appendable.append(")");
    }
    return _xblockexpression;
}
Also used : AbstractParameterBuilder(org.eclipse.xtend.ide.codebuilder.AbstractParameterBuilder) ISourceAppender(org.eclipse.xtext.xbase.compiler.ISourceAppender) ExclusiveRange(org.eclipse.xtext.xbase.lib.ExclusiveRange) VariableNameAcceptor(org.eclipse.xtend.ide.codebuilder.VariableNameAcceptor) HashSet(java.util.HashSet)

Example 9 with ISourceAppender

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

the class MemberFromSuperImplementor method getImplementedInterface.

private Procedure1<? super ISourceAppender> getImplementedInterface(final JvmDeclaredType subType, final JvmDeclaredType superInterface) {
    if (((superInterface instanceof JvmGenericType) && ((JvmGenericType) superInterface).isInterface())) {
        final Function1<JvmTypeReference, Boolean> _function = (JvmTypeReference it) -> {
            JvmType _type = it.getType();
            return Boolean.valueOf(Objects.equal(_type, superInterface));
        };
        boolean _exists = IterableExtensions.<JvmTypeReference>exists(subType.getSuperTypes(), _function);
        if (_exists) {
            final Procedure1<ISourceAppender> _function_1 = (ISourceAppender it) -> {
                it.append(superInterface).append(".");
            };
            return _function_1;
        }
        final Function1<JvmTypeReference, Boolean> _function_2 = (JvmTypeReference it) -> {
            return Boolean.valueOf(this.isInterface(it.getType()));
        };
        final Function1<JvmTypeReference, JvmDeclaredType> _function_3 = (JvmTypeReference it) -> {
            JvmType _type = it.getType();
            return ((JvmDeclaredType) _type);
        };
        final Function1<JvmDeclaredType, Boolean> _function_4 = (JvmDeclaredType it) -> {
            Procedure1<? super ISourceAppender> _implementedInterface = this.getImplementedInterface(it, superInterface);
            return Boolean.valueOf((_implementedInterface != null));
        };
        final JvmDeclaredType interfaze = IterableExtensions.<JvmDeclaredType>findFirst(IterableExtensions.<JvmTypeReference, JvmDeclaredType>map(IterableExtensions.<JvmTypeReference>filter(subType.getSuperTypes(), _function_2), _function_3), _function_4);
        if ((interfaze != null)) {
            final Procedure1<ISourceAppender> _function_5 = (ISourceAppender it) -> {
                it.append(interfaze).append(".");
            };
            return _function_5;
        }
    }
    return null;
}
Also used : JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmType(org.eclipse.xtext.common.types.JvmType) ISourceAppender(org.eclipse.xtext.xbase.compiler.ISourceAppender)

Example 10 with ISourceAppender

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

the class ConstructorBuilderTest method testXtendCustomBody.

@Test
public void testXtendCustomBody() {
    AbstractConstructorBuilder _createConstructorBuilder = this._codeBuilderFactory.createConstructorBuilder(this.getXtendClass());
    final Procedure1<AbstractConstructorBuilder> _function = (AbstractConstructorBuilder it) -> {
        it.setContext(this.getXtendClass());
        final Procedure1<ISourceAppender> _function_1 = (ISourceAppender it_1) -> {
            it_1.append("return");
        };
        it.setBodyGenerator(_function_1);
    };
    AbstractConstructorBuilder _doubleArrow = ObjectExtensions.<AbstractConstructorBuilder>operator_doubleArrow(_createConstructorBuilder, _function);
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("new() {");
    _builder.newLine();
    _builder.append("  ");
    _builder.append("return");
    _builder.newLine();
    _builder.append("}");
    this.assertBuilds(_doubleArrow, _builder.toString());
}
Also used : AbstractConstructorBuilder(org.eclipse.xtend.ide.codebuilder.AbstractConstructorBuilder) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) ISourceAppender(org.eclipse.xtext.xbase.compiler.ISourceAppender) Test(org.junit.Test) AbstractBuilderTest(org.eclipse.xtend.ide.tests.codebuilder.AbstractBuilderTest)

Aggregations

ISourceAppender (org.eclipse.xtext.xbase.compiler.ISourceAppender)10 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)6 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)5 AbstractBuilderTest (org.eclipse.xtend.ide.tests.codebuilder.AbstractBuilderTest)4 Test (org.junit.Test)4 AbstractConstructorBuilder (org.eclipse.xtend.ide.codebuilder.AbstractConstructorBuilder)3 AbstractMethodBuilder (org.eclipse.xtend.ide.codebuilder.AbstractMethodBuilder)3 Iterator (java.util.Iterator)2 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)2 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)2 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)2 JvmTypeParameter (org.eclipse.xtext.common.types.JvmTypeParameter)2 JvmUpperBound (org.eclipse.xtext.common.types.JvmUpperBound)2 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Consumer (java.util.function.Consumer)1 EList (org.eclipse.emf.common.util.EList)1 AbstractParameterBuilder (org.eclipse.xtend.ide.codebuilder.AbstractParameterBuilder)1