Search in sources :

Example 56 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 57 with JvmTypeReference

use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.

the class LinkingTest method testTypeReference_0.

@Test
public void testTypeReference_0() throws Exception {
    XtendFunction func = function("def =>java.lang.Boolean foo() {[|true]}");
    XFunctionTypeRef type = (XFunctionTypeRef) func.getReturnType();
    JvmTypeReference returnType = type.getReturnType();
    assertEquals("java.lang.Boolean", returnType.getIdentifier());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XFunctionTypeRef(org.eclipse.xtext.xtype.XFunctionTypeRef) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) Test(org.junit.Test)

Example 58 with JvmTypeReference

use of org.eclipse.xtext.common.types.JvmTypeReference 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);
}
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 59 with JvmTypeReference

use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.

the class UIStringsTest method testReferenceToString_0.

/**
 * Only the simple name of the type is specified.
 * The JvmTypeReference is not a proxy.
 */
@Test
public void testReferenceToString_0() throws Exception {
    XtendFile file = file("package org.eclipse.xtend.core.tests.validation.uistrings\n" + "public interface InterfaceA { }\n" + "public class ClassB implements InterfaceA { }\n" + "public class ClassC extends ClassB {\n" + "}\n" + "class XtendClass1 {\n" + "  def test() {\n" + "    val x = new List<ClassC>\n" + "  }\n" + "}\n");
    XtendClass clazz = (XtendClass) file.getXtendTypes().get(3);
    XBlockExpression block = (XBlockExpression) ((XtendFunction) clazz.getMembers().get(0)).getExpression();
    XVariableDeclaration declaration = (XVariableDeclaration) block.getExpressions().get(0);
    XConstructorCall cons = (XConstructorCall) declaration.getRight();
    JvmTypeReference reference = cons.getTypeArguments().get(0);
    assertNotNull(reference);
    assertNotNull(reference.getType());
    assertFalse(reference.getType().eIsProxy());
    assertNotNull(reference.eResource());
    assertEquals("ClassC", this.uiStrings.referenceToString(reference, "the-default-label"));
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XVariableDeclaration(org.eclipse.xtext.xbase.XVariableDeclaration) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) XConstructorCall(org.eclipse.xtext.xbase.XConstructorCall) Test(org.junit.Test)

Example 60 with JvmTypeReference

use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.

the class UIStringsTest method testReferenceToString_4.

@Test
public void testReferenceToString_4() throws Exception {
    XtendFile file = file("class Foo { var test }");
    assertFalse(validationTestHelper.validate(file).isEmpty());
    XtendClass clazz = (XtendClass) file.getXtendTypes().get(0);
    XtendField field = (XtendField) clazz.getMembers().get(0);
    JvmField jvmField = associations.getJvmField(field);
    JvmTypeReference reference = jvmField.getType();
    assertNotNull(reference);
    assertNotNull(reference.getType());
    assertFalse(reference.getType().eIsProxy());
    assertNotNull(reference.eResource());
    assertEquals("Object", this.uiStrings.referenceToString(reference, "the-default-label"));
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmField(org.eclipse.xtext.common.types.JvmField) XtendField(org.eclipse.xtend.core.xtend.XtendField) Test(org.junit.Test)

Aggregations

JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)130 Test (org.junit.Test)58 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)46 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)38 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)36 JvmType (org.eclipse.xtext.common.types.JvmType)28 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)23 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)18 XExpression (org.eclipse.xtext.xbase.XExpression)18 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)17 EObject (org.eclipse.emf.ecore.EObject)15 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)12 JvmTypeParameter (org.eclipse.xtext.common.types.JvmTypeParameter)12 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)12 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)12 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)8 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)8 TypeReference (org.eclipse.xtend.lib.macro.declaration.TypeReference)8 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)8 JvmParameterizedTypeReference (org.eclipse.xtext.common.types.JvmParameterizedTypeReference)8