Search in sources :

Example 16 with JvmConstructor

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

the class EObjectLocationTests method testResolveAnonymousClassConstructorCall_3.

@Test
public void testResolveAnonymousClassConstructorCall_3() throws Exception {
    String model = "class Foo { val bar = new Bar('') {} } class Bar { new(String x) {} new() {} }";
    XtendFile file = file(model);
    XtextResource resource = (XtextResource) file.eResource();
    EObject constructor = eObjectAtOffsetHelper.resolveCrossReferencedElementAt(resource, model.indexOf("Bar"));
    assertTrue(constructor instanceof JvmConstructor);
    assertEquals("Bar", ((JvmConstructor) constructor).getDeclaringType().getSimpleName());
    assertEquals(1, ((JvmConstructor) constructor).getParameters().size());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) EObject(org.eclipse.emf.ecore.EObject) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 17 with JvmConstructor

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

the class InferredJvmModelTest method testInferredFunctionWithReturnType_02.

@Test
public void testInferredFunctionWithReturnType_02() throws Exception {
    XtendFile xtendFile = file("class Foo { def Iterable<String> create result: newArrayList newList() {} }");
    JvmGenericType inferredType = getInferredType(xtendFile);
    assertTrue(inferredType.getMembers().get(0) instanceof JvmConstructor);
    JvmOperation jvmOperation = (JvmOperation) inferredType.getMembers().get(1);
    XtendFunction xtendFunction = (XtendFunction) ((XtendClass) xtendFile.getXtendTypes().get(0)).getMembers().get(0);
    assertFalse(xtendFunction.getReturnType() == jvmOperation.getReturnType());
    assertEquals(xtendFunction.getReturnType().getType(), jvmOperation.getReturnType().getType());
}
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) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) Test(org.junit.Test)

Example 18 with JvmConstructor

use of org.eclipse.xtext.common.types.JvmConstructor 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 19 with JvmConstructor

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

the class FindReferencesTest method testFindReferencesToConstructor.

@Test
public void testFindReferencesToConstructor() throws Exception {
    XtendClass classFoo = (XtendClass) testHelper.xtendFile("Foo", "class Foo {}").getXtendTypes().get(0);
    XtendClass classBar = (XtendClass) testHelper.xtendFile("Bar", "class Bar { def bar() {new Foo()} }").getXtendTypes().get(0);
    waitForBuild();
    JvmConstructor inferredConstructor = associations.getInferredConstructor(classFoo);
    XtendFunction functionBar = (XtendFunction) classBar.getMembers().get(0);
    final MockAcceptor mockAcceptor = new MockAcceptor();
    mockAcceptor.expect(((XBlockExpression) functionBar.getExpression()).getExpressions().get(0), inferredConstructor, XCONSTRUCTOR_CALL__CONSTRUCTOR);
    findReferencesTester.checkFindReferences(classFoo, "Java References to Foo (/test.project/src/Foo.xtend)", mockAcceptor);
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) MockAcceptor(org.eclipse.xtend.ide.tests.findrefs.FindReferencesTestUtil.MockAcceptor) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) Test(org.junit.Test)

Example 20 with JvmConstructor

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

the class FindReferencesTest method testFindReferencesToAnonymousImplicitSuperConstructor.

@Test
public void testFindReferencesToAnonymousImplicitSuperConstructor() throws Exception {
    XtendClass classFoo = (XtendClass) testHelper.xtendFile("Foo", "class Foo {}").getXtendTypes().get(0);
    XtendClass classBar = (XtendClass) testHelper.xtendFile("Bar", "class Bar { val foo = new Foo{} }").getXtendTypes().get(0);
    waitForBuild();
    XtendField fieldFoo = (XtendField) classBar.getMembers().get(0);
    JvmConstructor inferredConstructor = associations.getInferredConstructor(classFoo);
    final MockAcceptor mockAcceptor = new MockAcceptor();
    mockAcceptor.expect(((AnonymousClass) fieldFoo.getInitialValue()).getConstructorCall(), inferredConstructor, XCONSTRUCTOR_CALL__CONSTRUCTOR);
    findReferencesTester.checkFindReferences(inferredConstructor, "Java References to Foo (/test.project/src/Foo.xtend)", mockAcceptor);
}
Also used : XtendClass(org.eclipse.xtend.core.xtend.XtendClass) MockAcceptor(org.eclipse.xtend.ide.tests.findrefs.FindReferencesTestUtil.MockAcceptor) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) XtendField(org.eclipse.xtend.core.xtend.XtendField) Test(org.junit.Test)

Aggregations

JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)42 Test (org.junit.Test)21 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)19 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)16 EObject (org.eclipse.emf.ecore.EObject)13 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)10 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)8 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)8 JvmMember (org.eclipse.xtext.common.types.JvmMember)8 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)7 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)7 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)6 XConstructorCall (org.eclipse.xtext.xbase.XConstructorCall)6 XtextResource (org.eclipse.xtext.resource.XtextResource)5 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)4 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)3 MockAcceptor (org.eclipse.xtend.ide.tests.findrefs.FindReferencesTestUtil.MockAcceptor)3 JvmField (org.eclipse.xtext.common.types.JvmField)3 URI (org.eclipse.emf.common.util.URI)2 JvmConstructorDeclarationImpl (org.eclipse.xtend.core.macro.declaration.JvmConstructorDeclarationImpl)2