Search in sources :

Example 81 with JvmGenericType

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

the class InferredJvmModelTest method testInferredJvmConstructor.

@Test
public void testInferredJvmConstructor() throws Exception {
    XtendFile xtendFile = file("class Foo { }");
    JvmGenericType inferredType = getInferredType(xtendFile);
    XtendClass xtendClass = (XtendClass) xtendFile.getXtendTypes().get(0);
    assertEquals(1, inferredType.getMembers().size());
    JvmMember inferredFirstMember = inferredType.getMembers().get(0);
    assertTrue(inferredFirstMember instanceof JvmConstructor);
    assertEquals(JvmVisibility.PUBLIC, inferredFirstMember.getVisibility());
    assertEquals(associations.getInferredConstructor(xtendClass), inferredFirstMember);
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) JvmMember(org.eclipse.xtext.common.types.JvmMember) Test(org.junit.Test)

Example 82 with JvmGenericType

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

the class InferredJvmModelTest method testInferredFunctionWithTypeParameter.

@Test
public void testInferredFunctionWithTypeParameter() throws Exception {
    XtendFile xtendFile = file("class Foo<S> { def java.util.List<S> foo() {null} }");
    JvmGenericType inferredType = getInferredType(xtendFile);
    JvmOperation jvmOperation = (JvmOperation) inferredType.getMembers().get(1);
    assertEquals("java.util.List<S>", jvmOperation.getReturnType().getIdentifier());
    JvmTypeReference argument = ((JvmParameterizedTypeReference) jvmOperation.getReturnType()).getArguments().get(0);
    assertSame(inferredType, ((JvmTypeParameter) argument.getType()).getDeclarator());
    XtendFunction xtendFunction = (XtendFunction) ((XtendClass) xtendFile.getXtendTypes().get(0)).getMembers().get(0);
    assertEquals("java.util.List<S>", xtendFunction.getReturnType().getIdentifier());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) Test(org.junit.Test)

Example 83 with JvmGenericType

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

the class InferredJvmModelTest method testNameClashWithCreateExtension_00.

@Test
public void testNameClashWithCreateExtension_00() throws Exception {
    XtendFile xtendFile = file("package foo class Foo { def create new String() s(String x) { '' } String _createCache_s }");
    JvmGenericType inferredType = getInferredType(xtendFile);
    JvmField cacheVar = (JvmField) inferredType.getMembers().get(2);
    assertEquals("_createCache_s_1", cacheVar.getSimpleName());
    JvmOperation initializer = (JvmOperation) inferredType.getMembers().get(3);
    assertEquals("_init_s", initializer.getSimpleName());
    JvmField field = (JvmField) inferredType.getMembers().get(4);
    assertEquals("_createCache_s", field.getSimpleName());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmField(org.eclipse.xtext.common.types.JvmField) Test(org.junit.Test)

Example 84 with JvmGenericType

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

the class InferredJvmModelTest method testBug_340611_05.

@Test
public void testBug_340611_05() throws Exception {
    XtendFile xtendFile = file("class Bug340611 extends test.Dispatching {\n" + "    override dispatch doDispatch(StringBuilder sb) {\n" + "        null\n" + "    }\n" + "    def dispatch doDispatch(String s) {\n" + "        s\n" + "    }\n" + "}", false);
    JvmGenericType inferredType = getInferredType(xtendFile);
    assertEquals(3, IterableExtensions.size(inferredType.getDeclaredOperations()));
    Iterable<JvmOperation> operations = inferredType.getDeclaredOperations();
    JvmOperation dispatch = findByNameAndFirstParameterType(operations, "doDispatch", Object.class);
    assertEquals("java.lang.CharSequence", dispatch.getReturnType().getIdentifier());
    // two internal case methods
    JvmOperation stringParam = findByNameAndFirstParameterType(operations, "_doDispatch", StringBuilder.class);
    assertEquals("java.lang.StringBuilder", stringParam.getReturnType().getIdentifier());
    JvmOperation objectParam = findByNameAndFirstParameterType(operations, "_doDispatch", String.class);
    assertEquals("java.lang.CharSequence", objectParam.getReturnType().getIdentifier());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) Test(org.junit.Test)

Example 85 with JvmGenericType

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

the class InferredJvmModelTest method testInferredFunction_03.

@Test
public void testInferredFunction_03() throws Exception {
    XtendFile xtendFile = file("class Foo {def publicMethod(Object dummy) {} def public publicMethod() {} def protected protectedMethod() {} def private privateMethod() {} }");
    JvmGenericType inferredType = getInferredType(xtendFile);
    for (JvmOperation op : inferredType.getDeclaredOperations()) {
        assertEquals(JvmVisibility.get(op.getSimpleName().replace("Method", "").toUpperCase()), op.getVisibility());
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) Test(org.junit.Test)

Aggregations

JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)297 Test (org.junit.Test)237 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)117 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)64 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)56 JvmType (org.eclipse.xtext.common.types.JvmType)49 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)47 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)33 JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)33 JvmTypeParameter (org.eclipse.xtext.common.types.JvmTypeParameter)33 JvmField (org.eclipse.xtext.common.types.JvmField)31 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)30 EObject (org.eclipse.emf.ecore.EObject)28 Resource (org.eclipse.emf.ecore.resource.Resource)28 JvmMember (org.eclipse.xtext.common.types.JvmMember)25 JvmParameterizedTypeReference (org.eclipse.xtext.common.types.JvmParameterizedTypeReference)24 JvmTypeConstraint (org.eclipse.xtext.common.types.JvmTypeConstraint)21 JvmUpperBound (org.eclipse.xtext.common.types.JvmUpperBound)17 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)15 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)15