Search in sources :

Example 1 with AbstractConstructorBuilder

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

the class ConstructorBuilderTest method testJavaConstructor.

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

Example 2 with AbstractConstructorBuilder

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

the class ConstructorBuilderTest method testXtendConstructor.

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

Example 3 with AbstractConstructorBuilder

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

the class ConstructorBuilderTest method testJavaCustomBody.

@Test
public void testJavaCustomBody() {
    AbstractConstructorBuilder _createConstructorBuilder = this._codeBuilderFactory.createConstructorBuilder(this.getJavaClass());
    final Procedure1<AbstractConstructorBuilder> _function = (AbstractConstructorBuilder it) -> {
        it.setContext(this.getJavaClass());
        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("Bar() {");
    _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)

Example 4 with AbstractConstructorBuilder

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

the class ConstructorBuilderTest method testJavaException.

@Test
public void testJavaException() {
    AbstractConstructorBuilder _createConstructorBuilder = this._codeBuilderFactory.createConstructorBuilder(this.getJavaClass());
    final Procedure1<AbstractConstructorBuilder> _function = (AbstractConstructorBuilder it) -> {
        it.setContext(this.getJavaClass());
        LightweightTypeReference _createTypeRef = this.createTypeRef(Exception.class, this.getJavaClass());
        LightweightTypeReference _createTypeRef_1 = this.createTypeRef(RuntimeException.class, this.getJavaClass());
        it.setExceptions(Collections.<LightweightTypeReference>unmodifiableList(CollectionLiterals.<LightweightTypeReference>newArrayList(_createTypeRef, _createTypeRef_1)));
    };
    AbstractConstructorBuilder _doubleArrow = ObjectExtensions.<AbstractConstructorBuilder>operator_doubleArrow(_createConstructorBuilder, _function);
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("Bar() throws Exception, RuntimeException {");
    _builder.newLine();
    _builder.append("  ");
    _builder.append(AbstractBuilderTest.DEFAULT_BODY, "  ");
    _builder.append(";");
    _builder.newLineIfNotEmpty();
    _builder.append("}");
    this.assertBuilds(_doubleArrow, _builder.toString());
}
Also used : LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) AbstractConstructorBuilder(org.eclipse.xtend.ide.codebuilder.AbstractConstructorBuilder) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test) AbstractBuilderTest(org.eclipse.xtend.ide.tests.codebuilder.AbstractBuilderTest)

Example 5 with AbstractConstructorBuilder

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

the class ConstructorBuilderTest method testJavaParameterNames.

@Test
public void testJavaParameterNames() {
    AbstractConstructorBuilder _createConstructorBuilder = this._codeBuilderFactory.createConstructorBuilder(this.getJavaClass());
    final Procedure1<AbstractConstructorBuilder> _function = (AbstractConstructorBuilder it) -> {
        it.setContext(this.getJavaClass());
        it.setVisibility(JvmVisibility.PRIVATE);
        AbstractParameterBuilder _newParameterBuilder = it.newParameterBuilder();
        final Procedure1<AbstractParameterBuilder> _function_1 = (AbstractParameterBuilder it_1) -> {
            it_1.setType(this.createTypeRef(this.getXtendClass()));
            it_1.setName("bar");
        };
        ObjectExtensions.<AbstractParameterBuilder>operator_doubleArrow(_newParameterBuilder, _function_1);
        AbstractParameterBuilder _newParameterBuilder_1 = it.newParameterBuilder();
        final Procedure1<AbstractParameterBuilder> _function_2 = (AbstractParameterBuilder it_1) -> {
            it_1.setType(this.createTypeRef(this.getJavaClass()));
            it_1.setName("foo");
        };
        ObjectExtensions.<AbstractParameterBuilder>operator_doubleArrow(_newParameterBuilder_1, _function_2);
    };
    AbstractConstructorBuilder _doubleArrow = ObjectExtensions.<AbstractConstructorBuilder>operator_doubleArrow(_createConstructorBuilder, _function);
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("private Bar(Foo bar, Bar foo) {");
    _builder.newLine();
    _builder.append("  ");
    _builder.append(AbstractBuilderTest.DEFAULT_BODY, "  ");
    _builder.append(";");
    _builder.newLineIfNotEmpty();
    _builder.append("}");
    this.assertBuilds(_doubleArrow, _builder.toString());
}
Also used : AbstractConstructorBuilder(org.eclipse.xtend.ide.codebuilder.AbstractConstructorBuilder) AbstractParameterBuilder(org.eclipse.xtend.ide.codebuilder.AbstractParameterBuilder) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test) AbstractBuilderTest(org.eclipse.xtend.ide.tests.codebuilder.AbstractBuilderTest)

Aggregations

AbstractConstructorBuilder (org.eclipse.xtend.ide.codebuilder.AbstractConstructorBuilder)10 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)9 AbstractBuilderTest (org.eclipse.xtend.ide.tests.codebuilder.AbstractBuilderTest)8 Test (org.junit.Test)8 AbstractParameterBuilder (org.eclipse.xtend.ide.codebuilder.AbstractParameterBuilder)4 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)4 ISourceAppender (org.eclipse.xtext.xbase.compiler.ISourceAppender)3 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)3 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)1 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)1 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)1 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)1