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);
}
}
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);
}
}
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());
}
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());
}
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());
}
Aggregations