use of org.eclipse.xtext.common.types.JvmTypeParameter in project xtext-xtend by eclipse.
the class LinkingTest method testTypeParameterReference.
@Test
public void testTypeParameterReference() throws Exception {
XtendFunction func = function("def <X> X foo(X x) {x}");
JvmTypeReference returnType = func.getReturnType();
JvmTypeParameter typeParamDecl = (JvmTypeParameter) returnType.getType();
assertEquals("X", typeParamDecl.getIdentifier());
assertEquals("X", typeParamDecl.getName());
JvmTypeReference paramType = func.getParameters().get(0).getParameterType();
assertEquals(typeParamDecl, paramType.getType());
}
use of org.eclipse.xtext.common.types.JvmTypeParameter in project xtext-xtend by eclipse.
the class LinkingTest method testTypeParameterShadowsType_2.
@Test
public void testTypeParameterShadowsType_2() throws Exception {
XtendFunction func = (XtendFunction) ((XtendClass) file("class A {} class B<A> { def A foo(A x) {x}}").getXtendTypes().get(1)).getMembers().get(0);
JvmTypeReference returnType = func.getReturnType();
JvmTypeParameter typeParamDecl = (JvmTypeParameter) returnType.getType();
assertEquals("A", typeParamDecl.getIdentifier());
JvmTypeParameter param = (JvmTypeParameter) func.getParameters().get(0).getParameterType().getType();
assertSame(typeParamDecl, param);
}
use of org.eclipse.xtext.common.types.JvmTypeParameter in project xtext-xtend by eclipse.
the class LinkingTest method testTypeParameterShadowsType_1.
@Test
public void testTypeParameterShadowsType_1() throws Exception {
XtendFunction func = (XtendFunction) ((XtendClass) file("class A {} class B { def <A> A foo(A x) {x}}").getXtendTypes().get(1)).getMembers().get(0);
JvmTypeReference returnType = func.getReturnType();
JvmTypeParameter typeParamDecl = (JvmTypeParameter) returnType.getType();
assertEquals("A", typeParamDecl.getIdentifier());
JvmTypeParameter param = (JvmTypeParameter) func.getParameters().get(0).getParameterType().getType();
assertSame(typeParamDecl, param);
}
use of org.eclipse.xtext.common.types.JvmTypeParameter 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());
}
use of org.eclipse.xtext.common.types.JvmTypeParameter in project xtext-xtend by eclipse.
the class ExtractMethodRefactoring method appendMethodSignature.
protected void appendMethodSignature(ISourceAppender appendable) {
if (visibility != JvmVisibility.PUBLIC)
appendable.append(getVisibility().getName().toLowerCase()).append(" ");
appendable.append("def ");
if (isStatic)
appendable.append("static ");
if (!neededTypeParameters.isEmpty()) {
JvmOperation operation = associations.getDirectlyInferredOperation(originalMethod);
if (operation != null) {
appendable.append("<");
boolean isFirst = true;
for (JvmTypeParameter typeParameter : operation.getTypeParameters()) {
if (neededTypeParameters.contains(typeParameter)) {
if (!isFirst)
appendable.append(", ");
isFirst = false;
appendable.append(typeParameter);
}
}
appendable.append("> ");
}
}
if (isExplicitlyDeclareReturnType) {
appendable.append(returnType).append(" ");
}
appendable.append(methodName).append("(");
boolean isFirst = true;
for (ParameterInfo parameterInfo : getParameterInfos()) {
if (!isFirst)
appendable.append(", ");
isFirst = false;
appendable.append(parameter2type.get(parameterInfo)).append(" ").append(parameterInfo.getNewName());
}
appendable.append(")");
}
Aggregations