use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.
the class XtendHoverSignatureProvider method _signature.
protected String _signature(XtendFunction function, boolean typeAtEnd) {
JvmOperation inferredOperation = associations.getDirectlyInferredOperation(function);
if (inferredOperation != null) {
String returnTypeString = "void";
JvmTypeReference returnType = inferredOperation.getReturnType();
if (returnType != null) {
if (returnType instanceof JvmAnyTypeReference) {
throw new IllegalStateException();
} else {
returnTypeString = getTypeName(returnType);
}
}
StringBuilder signature = new StringBuilder();
String typeParameter = uiStrings.typeParameters(function.getTypeParameters());
if (typeParameter != null && typeParameter.length() > 0) {
signature.append(typeParameter).append(" ");
}
signature.append(returnTypeString).append(" ");
signature.append(function.getName()).append(hoverUiStrings.parameters(inferredOperation));
signature.append(getThrowsDeclaration(inferredOperation));
return signature.toString();
}
return function.getName() + "()";
}
use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.
the class LinkingTest method testTypeParameterReference_4.
@Test
public void testTypeParameterReference_4() throws Exception {
XtendFunction func = (XtendFunction) ((XtendClass) file("class X { def <Y> foo(Y y) { return y }}").getXtendTypes().get(0)).getMembers().get(0);
JvmOperation operation = associator.getDirectlyInferredOperation(func);
JvmTypeReference returnType = operation.getReturnType();
assertEquals("Y", returnType.getIdentifier());
JvmTypeReference paramType = operation.getParameters().get(0).getParameterType();
assertEquals("Y", paramType.getIdentifier());
}
use of org.eclipse.xtext.common.types.JvmTypeReference 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.JvmTypeReference in project xtext-xtend by eclipse.
the class LinkingTest method testImplicitPackageImport.
@Test
public void testImplicitPackageImport() throws Exception {
XtendFile file = file("package java.io class Foo implements Serializable {}");
List<JvmTypeReference> implementedInterfaces = ((XtendClass) file.getXtendTypes().get(0)).getImplements();
assertFalse(implementedInterfaces.isEmpty());
JvmType implementedInterface = implementedInterfaces.get(0).getType();
assertNotNull(implementedInterface);
assertEquals("java.io.Serializable", implementedInterface.getIdentifier());
}
use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.
the class LinkingTest method testTypeParameterReference_9.
@Test
public void testTypeParameterReference_9() throws Exception {
XtendFunction func = (XtendFunction) ((XtendClass) file("class X<Y> { def foo(Iterable<Y> iter) { for(y: iter) { return y } }}").getXtendTypes().get(0)).getMembers().get(0);
JvmOperation operation = associator.getDirectlyInferredOperation(func);
JvmTypeReference returnType = operation.getReturnType();
assertEquals("Y", returnType.getIdentifier());
JvmTypeReference paramType = operation.getParameters().get(0).getParameterType();
assertEquals("java.lang.Iterable<Y>", paramType.getIdentifier());
}
Aggregations