Search in sources :

Example 6 with AbstractParameterBuilder

use of org.eclipse.xtend.ide.codebuilder.AbstractParameterBuilder in project xtext-xtend by eclipse.

the class MethodBuilderTest method testStaticXtendMethod.

@Test
public void testStaticXtendMethod() {
    AbstractMethodBuilder _createMethodBuilder = this._codeBuilderFactory.createMethodBuilder(this.getXtendClass());
    final Procedure1<AbstractMethodBuilder> _function = (AbstractMethodBuilder it) -> {
        it.setContext(this.getXtendClass());
        it.setMethodName("foo");
        it.setReturnType(this.createTypeRef(this.getXtendClass()));
        it.setVisibility(JvmVisibility.PROTECTED);
        it.setStaticFlag(true);
        AbstractParameterBuilder _newParameterBuilder = it.newParameterBuilder();
        _newParameterBuilder.setType(this.createTypeRef(this.getXtendClass()));
    };
    AbstractMethodBuilder _doubleArrow = ObjectExtensions.<AbstractMethodBuilder>operator_doubleArrow(_createMethodBuilder, _function);
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("def protected static foo(Foo foo) {");
    _builder.newLine();
    _builder.append("  ");
    _builder.append(AbstractBuilderTest.DEFAULT_BODY, "  ");
    _builder.newLineIfNotEmpty();
    _builder.append("}");
    this.assertBuilds(_doubleArrow, _builder.toString());
}
Also used : AbstractParameterBuilder(org.eclipse.xtend.ide.codebuilder.AbstractParameterBuilder) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) AbstractMethodBuilder(org.eclipse.xtend.ide.codebuilder.AbstractMethodBuilder) Test(org.junit.Test) AbstractBuilderTest(org.eclipse.xtend.ide.tests.codebuilder.AbstractBuilderTest)

Example 7 with AbstractParameterBuilder

use of org.eclipse.xtend.ide.codebuilder.AbstractParameterBuilder in project xtext-xtend by eclipse.

the class MethodBuilderTest method testXtendNamedParameter.

@Test
public void testXtendNamedParameter() {
    AbstractMethodBuilder _createMethodBuilder = this._codeBuilderFactory.createMethodBuilder(this.getXtendClass());
    final Procedure1<AbstractMethodBuilder> _function = (AbstractMethodBuilder it) -> {
        it.setContext(this.getXtendClass());
        it.setMethodName("foo");
        AbstractParameterBuilder _newParameterBuilder = it.newParameterBuilder();
        final Procedure1<AbstractParameterBuilder> _function_1 = (AbstractParameterBuilder it_1) -> {
            it_1.setName("bar");
            it_1.setType(this.createTypeRef(this.getXtendClass()));
        };
        ObjectExtensions.<AbstractParameterBuilder>operator_doubleArrow(_newParameterBuilder, _function_1);
        AbstractParameterBuilder _newParameterBuilder_1 = it.newParameterBuilder();
        final Procedure1<AbstractParameterBuilder> _function_2 = (AbstractParameterBuilder it_1) -> {
            it_1.setName("baz");
            it_1.setType(this.createTypeRef(this.getXtendClass()));
        };
        ObjectExtensions.<AbstractParameterBuilder>operator_doubleArrow(_newParameterBuilder_1, _function_2);
    };
    AbstractMethodBuilder _doubleArrow = ObjectExtensions.<AbstractMethodBuilder>operator_doubleArrow(_createMethodBuilder, _function);
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("def foo(Foo bar, Foo baz) {");
    _builder.newLine();
    _builder.append("  ");
    _builder.append(AbstractBuilderTest.DEFAULT_BODY, "  ");
    _builder.newLineIfNotEmpty();
    _builder.append("}");
    this.assertBuilds(_doubleArrow, _builder.toString());
}
Also used : AbstractParameterBuilder(org.eclipse.xtend.ide.codebuilder.AbstractParameterBuilder) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) AbstractMethodBuilder(org.eclipse.xtend.ide.codebuilder.AbstractMethodBuilder) Test(org.junit.Test) AbstractBuilderTest(org.eclipse.xtend.ide.tests.codebuilder.AbstractBuilderTest)

Example 8 with AbstractParameterBuilder

use of org.eclipse.xtend.ide.codebuilder.AbstractParameterBuilder in project xtext-xtend by eclipse.

the class MethodBuilderTest method testXtendMethod.

@Test
public void testXtendMethod() {
    AbstractMethodBuilder _createMethodBuilder = this._codeBuilderFactory.createMethodBuilder(this.getXtendClass());
    final Procedure1<AbstractMethodBuilder> _function = (AbstractMethodBuilder it) -> {
        it.setContext(this.getXtendClass());
        it.setMethodName("foo");
        it.setReturnType(this.createTypeRef(this.getXtendClass()));
        it.setVisibility(JvmVisibility.PUBLIC);
        AbstractParameterBuilder _newParameterBuilder = it.newParameterBuilder();
        _newParameterBuilder.setType(this.createTypeRef(this.getXtendClass()));
        AbstractParameterBuilder _newParameterBuilder_1 = it.newParameterBuilder();
        _newParameterBuilder_1.setType(this.createTypeRef(this.getXtendClass()));
    };
    AbstractMethodBuilder _doubleArrow = ObjectExtensions.<AbstractMethodBuilder>operator_doubleArrow(_createMethodBuilder, _function);
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("def foo(Foo foo, Foo foo2) {");
    _builder.newLine();
    _builder.append("  ");
    _builder.append(AbstractBuilderTest.DEFAULT_BODY, "  ");
    _builder.newLineIfNotEmpty();
    _builder.append("}");
    this.assertBuilds(_doubleArrow, _builder.toString());
}
Also used : AbstractParameterBuilder(org.eclipse.xtend.ide.codebuilder.AbstractParameterBuilder) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) AbstractMethodBuilder(org.eclipse.xtend.ide.codebuilder.AbstractMethodBuilder) Test(org.junit.Test) AbstractBuilderTest(org.eclipse.xtend.ide.tests.codebuilder.AbstractBuilderTest)

Example 9 with AbstractParameterBuilder

use of org.eclipse.xtend.ide.codebuilder.AbstractParameterBuilder in project xtext-xtend by eclipse.

the class MethodBuilderTest method testStaticJavaMethod.

@Test
public void testStaticJavaMethod() {
    AbstractMethodBuilder _createMethodBuilder = this._codeBuilderFactory.createMethodBuilder(this.getJavaClass());
    final Procedure1<AbstractMethodBuilder> _function = (AbstractMethodBuilder it) -> {
        it.setContext(this.getJavaClass());
        it.setMethodName("bar");
        it.setReturnType(this.createTypeRef(this.getJavaClass()));
        it.setVisibility(JvmVisibility.PRIVATE);
        it.setStaticFlag(true);
        AbstractParameterBuilder _newParameterBuilder = it.newParameterBuilder();
        _newParameterBuilder.setType(this.createTypeRef(this.getJavaClass()));
    };
    AbstractMethodBuilder _doubleArrow = ObjectExtensions.<AbstractMethodBuilder>operator_doubleArrow(_createMethodBuilder, _function);
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("private static Bar bar(Bar bar) {");
    _builder.newLine();
    _builder.append("  ");
    _builder.append(AbstractBuilderTest.DEFAULT_BODY, "  ");
    _builder.append(";");
    _builder.newLineIfNotEmpty();
    _builder.append("}");
    this.assertBuilds(_doubleArrow, _builder.toString());
}
Also used : AbstractParameterBuilder(org.eclipse.xtend.ide.codebuilder.AbstractParameterBuilder) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) AbstractMethodBuilder(org.eclipse.xtend.ide.codebuilder.AbstractMethodBuilder) Test(org.junit.Test) AbstractBuilderTest(org.eclipse.xtend.ide.tests.codebuilder.AbstractBuilderTest)

Example 10 with AbstractParameterBuilder

use of org.eclipse.xtend.ide.codebuilder.AbstractParameterBuilder 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)

Aggregations

AbstractParameterBuilder (org.eclipse.xtend.ide.codebuilder.AbstractParameterBuilder)13 AbstractBuilderTest (org.eclipse.xtend.ide.tests.codebuilder.AbstractBuilderTest)11 Test (org.junit.Test)11 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)10 AbstractMethodBuilder (org.eclipse.xtend.ide.codebuilder.AbstractMethodBuilder)7 AbstractConstructorBuilder (org.eclipse.xtend.ide.codebuilder.AbstractConstructorBuilder)4 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)4 HashSet (java.util.HashSet)1 VariableNameAcceptor (org.eclipse.xtend.ide.codebuilder.VariableNameAcceptor)1 JvmAnnotationReference (org.eclipse.xtext.common.types.JvmAnnotationReference)1 JvmExecutable (org.eclipse.xtext.common.types.JvmExecutable)1 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)1 ISourceAppender (org.eclipse.xtext.xbase.compiler.ISourceAppender)1 ExclusiveRange (org.eclipse.xtext.xbase.lib.ExclusiveRange)1 Extension (org.eclipse.xtext.xbase.lib.Extension)1 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)1