use of org.eclipse.xtend.ide.codebuilder.AbstractMethodBuilder in project xtext-xtend by eclipse.
the class MethodBuilderTest method testXtendExceptions.
@Test
public void testXtendExceptions() {
AbstractMethodBuilder _createMethodBuilder = this._codeBuilderFactory.createMethodBuilder(this.getXtendClass());
final Procedure1<AbstractMethodBuilder> _function = (AbstractMethodBuilder it) -> {
it.setContext(this.getXtendClass());
it.setMethodName("foo");
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)));
};
AbstractMethodBuilder _doubleArrow = ObjectExtensions.<AbstractMethodBuilder>operator_doubleArrow(_createMethodBuilder, _function);
StringConcatenation _builder = new StringConcatenation();
_builder.append("def foo() 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.AbstractMethodBuilder in project xtext-xtend by eclipse.
the class MemberFromSuperImplementor method appendOverrideFunction.
public void appendOverrideFunction(final XtendTypeDeclaration overrider, final IResolvedOperation overriddenOperation, final ISourceAppender appendable) {
final JvmDeclaredType inferredType = this.associations.getInferredType(overrider);
final AbstractMethodBuilder methodBuilder = this.codeBuilderFactory.createMethodBuilder(inferredType);
this.initializeExecutableBuilder(methodBuilder, inferredType, overriddenOperation);
methodBuilder.setOverrideFlag(true);
methodBuilder.setMethodName(overriddenOperation.getDeclaration().getSimpleName());
methodBuilder.setReturnType(overriddenOperation.getResolvedReturnType());
boolean _isSynchronized = overriddenOperation.getDeclaration().isSynchronized();
if (_isSynchronized) {
methodBuilder.setSynchronizedFlag(true);
}
boolean _isEmpty = overriddenOperation.getResolvedTypeParameters().isEmpty();
boolean _not = (!_isEmpty);
if (_not) {
final ArrayList<JvmTypeParameter> typeParameters = CollectionLiterals.<JvmTypeParameter>newArrayList();
final Procedure2<JvmTypeParameter, Integer> _function = (JvmTypeParameter typeParam, Integer idx) -> {
final JvmTypeParameter newTypeParam = this.typesFactory.createJvmTypeParameter();
newTypeParam.setName(typeParam.getName());
final Consumer<LightweightTypeReference> _function_1 = (LightweightTypeReference it) -> {
final JvmUpperBound upperBound = this.typesFactory.createJvmUpperBound();
upperBound.setTypeReference(it.toJavaCompliantTypeReference());
EList<JvmTypeConstraint> _constraints = newTypeParam.getConstraints();
_constraints.add(upperBound);
};
overriddenOperation.getResolvedTypeParameterConstraints((idx).intValue()).forEach(_function_1);
typeParameters.add(newTypeParam);
};
IterableExtensions.<JvmTypeParameter>forEach(overriddenOperation.getResolvedTypeParameters(), _function);
methodBuilder.setTypeParameters(typeParameters);
}
boolean _isAbstract = overriddenOperation.getDeclaration().isAbstract();
boolean _not_1 = (!_isAbstract);
if (_not_1) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("super.");
{
List<JvmTypeParameter> _resolvedTypeParameters = overriddenOperation.getResolvedTypeParameters();
boolean _hasElements = false;
for (final JvmTypeParameter typeParam : _resolvedTypeParameters) {
if (!_hasElements) {
_hasElements = true;
_builder.append("<");
} else {
_builder.appendImmediate(", ", "");
}
String _simpleName = typeParam.getSimpleName();
_builder.append(_simpleName);
}
if (_hasElements) {
_builder.append(">");
}
}
String _simpleName_1 = overriddenOperation.getDeclaration().getSimpleName();
_builder.append(_simpleName_1);
_builder.append("(");
final Function1<JvmFormalParameter, String> _function_1 = (JvmFormalParameter it) -> {
return it.getSimpleName();
};
String _join = IterableExtensions.join(ListExtensions.<JvmFormalParameter, String>map(overriddenOperation.getDeclaration().getParameters(), _function_1), ", ");
_builder.append(_join);
_builder.append(")");
final String body = _builder.toString();
final Procedure1<? super ISourceAppender> superTypeRef = this.getImplementedInterface(inferredType, overriddenOperation.getDeclaration().getDeclaringType());
final Procedure1<ISourceAppender> _function_2 = (ISourceAppender it) -> {
if (superTypeRef != null) {
superTypeRef.apply(it);
}
it.append(body);
};
methodBuilder.setBodyGenerator(_function_2);
}
boolean _isValid = methodBuilder.isValid();
if (_isValid) {
methodBuilder.build(appendable);
}
}
use of org.eclipse.xtend.ide.codebuilder.AbstractMethodBuilder in project xtext-xtend by eclipse.
the class CreateMemberQuickfixes method newMethodQuickfix.
protected void newMethodQuickfix(JvmDeclaredType containerType, String name, /* @Nullable */
LightweightTypeReference returnType, List<LightweightTypeReference> parameterTypes, boolean isStatic, boolean isAbstract, boolean isExtension, boolean isLocal, XAbstractFeatureCall call, final Issue issue, final IssueResolutionAcceptor issueResolutionAcceptor) {
AbstractMethodBuilder methodBuilder = codeBuilderFactory.createMethodBuilder(containerType);
methodBuilder.setMethodName(name);
methodBuilder.setReturnType(returnType);
for (LightweightTypeReference parameterType : parameterTypes) methodBuilder.newParameterBuilder().setType(parameterType);
methodBuilder.setContext(call);
methodBuilder.setVisibility(JvmVisibility.PUBLIC);
methodBuilder.setStaticFlag(isStatic);
methodBuilder.setAbstractFlag(isAbstract);
StringBuffer label = new StringBuffer("Create ");
if (isStatic)
label.append("static ");
if (isExtension)
label.append("extension ");
label.append("method '").append(name).append("(");
boolean isFirst = true;
for (LightweightTypeReference parameterType : parameterTypes) {
if (!isFirst)
label.append(", ");
isFirst = false;
label.append(parameterType.getSimpleName());
}
label.append(")'");
if (!isLocal)
label.append(" in '" + containerType.getSimpleName() + "'");
quickfixFactory.addQuickfix(methodBuilder, label.toString(), issue, issueResolutionAcceptor);
}
use of org.eclipse.xtend.ide.codebuilder.AbstractMethodBuilder in project xtext-xtend by eclipse.
the class MethodBuilderTest method testJavaNamedParameter.
@Test
public void testJavaNamedParameter() {
AbstractMethodBuilder _createMethodBuilder = this._codeBuilderFactory.createMethodBuilder(this.getJavaClass());
final Procedure1<AbstractMethodBuilder> _function = (AbstractMethodBuilder it) -> {
it.setContext(this.getJavaClass());
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("void foo(Foo bar, Foo baz) {");
_builder.newLine();
_builder.append(" ");
_builder.append(AbstractBuilderTest.DEFAULT_BODY, " ");
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.append("}");
this.assertBuilds(_doubleArrow, _builder.toString());
}
use of org.eclipse.xtend.ide.codebuilder.AbstractMethodBuilder in project xtext-xtend by eclipse.
the class MethodBuilderTest method testJavaOverride.
@Test
public void testJavaOverride() {
AbstractMethodBuilder _createMethodBuilder = this._codeBuilderFactory.createMethodBuilder(this.getJavaClass());
final Procedure1<AbstractMethodBuilder> _function = (AbstractMethodBuilder it) -> {
it.setContext(this.getJavaClass());
it.setMethodName("foo");
it.setOverrideFlag(true);
};
AbstractMethodBuilder _doubleArrow = ObjectExtensions.<AbstractMethodBuilder>operator_doubleArrow(_createMethodBuilder, _function);
StringConcatenation _builder = new StringConcatenation();
_builder.append("@Override");
_builder.newLine();
_builder.append("void foo() {");
_builder.newLine();
_builder.append(" ");
_builder.append(AbstractBuilderTest.DEFAULT_BODY, " ");
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.append("}");
this.assertBuilds(_doubleArrow, _builder.toString());
}
Aggregations