Search in sources :

Example 6 with AbstractConstructorBuilder

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

the class MemberFromSuperImplementor method appendConstructorFromSuper.

public void appendConstructorFromSuper(final XtendClass overrider, final IResolvedConstructor superConstructor, final ISourceAppender appendable) {
    final JvmGenericType inferredType = this.associations.getInferredType(overrider);
    final AbstractConstructorBuilder constructorBuilder = this.codeBuilderFactory.createConstructorBuilder(inferredType);
    this.initializeExecutableBuilder(constructorBuilder, inferredType, superConstructor);
    final Procedure1<ISourceAppender> _function = (ISourceAppender it) -> {
        boolean _isEmpty = superConstructor.getResolvedParameterTypes().isEmpty();
        boolean _not = (!_isEmpty);
        if (_not) {
            StringConcatenation _builder = new StringConcatenation();
            _builder.append("super(");
            final Function1<JvmFormalParameter, String> _function_1 = (JvmFormalParameter it_1) -> {
                return it_1.getSimpleName();
            };
            String _join = IterableExtensions.join(ListExtensions.<JvmFormalParameter, String>map(superConstructor.getDeclaration().getParameters(), _function_1), ", ");
            _builder.append(_join);
            _builder.append(")");
            it.append(_builder);
        }
    };
    constructorBuilder.setBodyGenerator(_function);
    boolean _isValid = constructorBuilder.isValid();
    if (_isValid) {
        constructorBuilder.build(appendable);
    }
}
Also used : AbstractConstructorBuilder(org.eclipse.xtend.ide.codebuilder.AbstractConstructorBuilder) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) ISourceAppender(org.eclipse.xtext.xbase.compiler.ISourceAppender)

Example 7 with AbstractConstructorBuilder

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

the class CreateMemberQuickfixes method newConstructorQuickfix.

protected void newConstructorQuickfix(Issue issue, IssueResolutionAcceptor issueResolutionAcceptor, JvmDeclaredType ownerType, XExpression call, List<XExpression> arguments) {
    if (ownerType != null) {
        List<LightweightTypeReference> parameterTypes = getResolvedArgumentTypes(call, logicalContainerProvider.getNearestLogicalContainer(call), arguments);
        AbstractConstructorBuilder constructorBuilder = codeBuilderFactory.createConstructorBuilder(ownerType);
        constructorBuilder.setContext(call);
        for (LightweightTypeReference parameterType : parameterTypes) constructorBuilder.newParameterBuilder().setType(parameterType);
        constructorBuilder.setVisibility(JvmVisibility.PUBLIC);
        StringBuffer label = new StringBuffer("Create constructor '");
        if (constructorBuilder.getOwnerSource() instanceof XtendClass)
            label.append("new");
        else
            label.append(ownerType.getSimpleName());
        label.append("(");
        boolean isFirst = true;
        for (LightweightTypeReference parameterType : parameterTypes) {
            if (!isFirst)
                label.append(", ");
            isFirst = false;
            label.append(parameterType.getSimpleName());
        }
        label.append(")'");
        if (getCallersType(call) != ownerType)
            label.append(" in '").append(ownerType.getSimpleName()).append("'");
        quickfixFactory.addQuickfix(constructorBuilder, label.toString(), issue, issueResolutionAcceptor);
    }
}
Also used : LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) AbstractConstructorBuilder(org.eclipse.xtend.ide.codebuilder.AbstractConstructorBuilder) XtendClass(org.eclipse.xtend.core.xtend.XtendClass)

Example 8 with AbstractConstructorBuilder

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

the class ConstructorBuilderTest method testXtendParameterNames.

@Test
public void testXtendParameterNames() {
    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();
        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("protected new(Foo bar, Bar foo) {");
    _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) 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)

Example 9 with AbstractConstructorBuilder

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

the class ConstructorBuilderTest method testXtendExceptions.

@Test
public void testXtendExceptions() {
    AbstractConstructorBuilder _createConstructorBuilder = this._codeBuilderFactory.createConstructorBuilder(this.getXtendClass());
    final Procedure1<AbstractConstructorBuilder> _function = (AbstractConstructorBuilder it) -> {
        it.setContext(this.getXtendClass());
        LightweightTypeReference _createTypeRef = this.createTypeRef(Exception.class, this.getXtendClass());
        LightweightTypeReference _createTypeRef_1 = this.createTypeRef(RuntimeException.class, this.getXtendClass());
        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("new() throws Exception, RuntimeException {");
    _builder.newLine();
    _builder.append("  ");
    _builder.append(AbstractBuilderTest.DEFAULT_BODY, "  ");
    _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 10 with AbstractConstructorBuilder

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

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