Search in sources :

Example 1 with AbstractMethodBuilder

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

the class MethodBuilderTest method testJavaException.

@Test
public void testJavaException() {
    AbstractMethodBuilder _createMethodBuilder = this._codeBuilderFactory.createMethodBuilder(this.getJavaClass());
    final Procedure1<AbstractMethodBuilder> _function = (AbstractMethodBuilder it) -> {
        it.setContext(this.getJavaClass());
        it.setMethodName("foo");
        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)));
    };
    AbstractMethodBuilder _doubleArrow = ObjectExtensions.<AbstractMethodBuilder>operator_doubleArrow(_createMethodBuilder, _function);
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("void foo() 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) 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 2 with AbstractMethodBuilder

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

the class MethodBuilderTest method testJavaAbstractBody.

@Test
public void testJavaAbstractBody() {
    AbstractMethodBuilder _createMethodBuilder = this._codeBuilderFactory.createMethodBuilder(this.getJavaClass());
    final Procedure1<AbstractMethodBuilder> _function = (AbstractMethodBuilder it) -> {
        it.setContext(this.getJavaClass());
        it.setAbstractFlag(true);
        it.setMethodName("foo");
    };
    AbstractMethodBuilder _doubleArrow = ObjectExtensions.<AbstractMethodBuilder>operator_doubleArrow(_createMethodBuilder, _function);
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("abstract void foo();");
    this.assertBuilds(_doubleArrow, _builder.toString());
}
Also used : 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 3 with AbstractMethodBuilder

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

the class MethodBuilderTest method testXtendTypeParameter.

@Test
public void testXtendTypeParameter() {
    AbstractMethodBuilder _createMethodBuilder = this._codeBuilderFactory.createMethodBuilder(this.getXtendClass());
    final Procedure1<AbstractMethodBuilder> _function = (AbstractMethodBuilder it) -> {
        it.setContext(this.getXtendClass());
        it.setMethodName("foo");
        JvmTypeParameter _createJvmTypeParameter = this._typesFactory.createJvmTypeParameter();
        final Procedure1<JvmTypeParameter> _function_1 = (JvmTypeParameter it_1) -> {
            it_1.setName("T");
        };
        JvmTypeParameter _doubleArrow = ObjectExtensions.<JvmTypeParameter>operator_doubleArrow(_createJvmTypeParameter, _function_1);
        JvmTypeParameter _createJvmTypeParameter_1 = this._typesFactory.createJvmTypeParameter();
        final Procedure1<JvmTypeParameter> _function_2 = (JvmTypeParameter it_1) -> {
            it_1.setName("U");
        };
        JvmTypeParameter _doubleArrow_1 = ObjectExtensions.<JvmTypeParameter>operator_doubleArrow(_createJvmTypeParameter_1, _function_2);
        it.setTypeParameters(Collections.<JvmTypeParameter>unmodifiableList(CollectionLiterals.<JvmTypeParameter>newArrayList(_doubleArrow, _doubleArrow_1)));
    };
    AbstractMethodBuilder _doubleArrow = ObjectExtensions.<AbstractMethodBuilder>operator_doubleArrow(_createMethodBuilder, _function);
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("def <T,U> foo() {");
    _builder.newLine();
    _builder.append("  ");
    _builder.append(AbstractBuilderTest.DEFAULT_BODY, "  ");
    _builder.newLineIfNotEmpty();
    _builder.append("}");
    this.assertBuilds(_doubleArrow, _builder.toString());
}
Also used : JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) 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 4 with AbstractMethodBuilder

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

the class MethodBuilderTest method testSetContextOnParameters.

@Test
public void testSetContextOnParameters() {
    AbstractMethodBuilder _createMethodBuilder = this._codeBuilderFactory.createMethodBuilder(this.getXtendClass());
    final Procedure1<AbstractMethodBuilder> _function = (AbstractMethodBuilder it) -> {
        final AbstractParameterBuilder builder = it.newParameterBuilder();
        Assert.assertNull(builder.getContext());
        it.setContext(this.getXtendClass());
        Assert.assertEquals(this.getXtendClass(), builder.getContext());
    };
    ObjectExtensions.<AbstractMethodBuilder>operator_doubleArrow(_createMethodBuilder, _function);
}
Also used : AbstractParameterBuilder(org.eclipse.xtend.ide.codebuilder.AbstractParameterBuilder) AbstractMethodBuilder(org.eclipse.xtend.ide.codebuilder.AbstractMethodBuilder) Test(org.junit.Test) AbstractBuilderTest(org.eclipse.xtend.ide.tests.codebuilder.AbstractBuilderTest)

Example 5 with AbstractMethodBuilder

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

the class MethodBuilderTest method testXtendOverrride.

@Test
public void testXtendOverrride() {
    AbstractMethodBuilder _createMethodBuilder = this._codeBuilderFactory.createMethodBuilder(this.getXtendClass());
    final Procedure1<AbstractMethodBuilder> _function = (AbstractMethodBuilder it) -> {
        it.setContext(this.getXtendClass());
        it.setMethodName("foo");
        it.setOverrideFlag(true);
    };
    AbstractMethodBuilder _doubleArrow = ObjectExtensions.<AbstractMethodBuilder>operator_doubleArrow(_createMethodBuilder, _function);
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("override foo() {");
    _builder.newLine();
    _builder.append("  ");
    _builder.append(AbstractBuilderTest.DEFAULT_BODY, "  ");
    _builder.newLineIfNotEmpty();
    _builder.append("}");
    this.assertBuilds(_doubleArrow, _builder.toString());
}
Also used : 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)

Aggregations

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