Search in sources :

Example 6 with JvmTypeReference

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() + "()";
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmAnyTypeReference(org.eclipse.xtext.common.types.JvmAnyTypeReference)

Example 7 with JvmTypeReference

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());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) Test(org.junit.Test)

Example 8 with JvmTypeReference

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);
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) Test(org.junit.Test)

Example 9 with JvmTypeReference

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());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmType(org.eclipse.xtext.common.types.JvmType) Test(org.junit.Test)

Example 10 with JvmTypeReference

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());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) Test(org.junit.Test)

Aggregations

JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)194 Test (org.junit.Test)98 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)68 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)47 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)46 JvmType (org.eclipse.xtext.common.types.JvmType)43 JvmParameterizedTypeReference (org.eclipse.xtext.common.types.JvmParameterizedTypeReference)41 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)36 JvmTypeParameter (org.eclipse.xtext.common.types.JvmTypeParameter)27 XExpression (org.eclipse.xtext.xbase.XExpression)22 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)18 JvmUpperBound (org.eclipse.xtext.common.types.JvmUpperBound)18 EObject (org.eclipse.emf.ecore.EObject)17 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)17 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)16 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)15 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)14 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)12 JvmField (org.eclipse.xtext.common.types.JvmField)12 JvmWildcardTypeReference (org.eclipse.xtext.common.types.JvmWildcardTypeReference)12