Search in sources :

Example 21 with XConstructorCall

use of org.eclipse.xtext.xbase.XConstructorCall in project xtext-xtend by eclipse.

the class UIStringsTest method testReferenceToString_1.

/**
 * Only the simple name of the type is specified.
 * The JvmTypeReference is proxy.
 */
@Test
public void testReferenceToString_1() throws Exception {
    XtendFile file1 = 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");
    assertNotNull(file1);
    XtendFile file2 = file("package org.eclipse.xtend.core.tests.validation.uistrings\n" + "class XtendClass1 {\n" + "  def test() {\n" + "    val x = new List<ClassC>\n" + "  }\n" + "}\n");
    XtendClass clazz = (XtendClass) file2.getXtendTypes().get(0);
    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());
    assertTrue(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 22 with XConstructorCall

use of org.eclipse.xtext.xbase.XConstructorCall in project xtext-xtend by eclipse.

the class UIStringsTest method testReferenceToString_2.

/**
 * The qualified name of the type is specified.
 * The JvmTypeReference is not a proxy.
 */
@Test
public void testReferenceToString_2() 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<org.eclipse.xtend.core.tests.validation.uistrings.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 23 with XConstructorCall

use of org.eclipse.xtext.xbase.XConstructorCall in project xtext-xtend by eclipse.

the class InferredJvmModelShadowingJavaLinkingTests method testLinkInferredJvmConstructor.

@Test
public void testLinkInferredJvmConstructor() throws Exception {
    XtendClass foo = classFile("test/Foo", "package test class Foo {}");
    XtendClass bar = classFile("test/Bar", "package test class Bar { def bar() {new Foo()} }");
    final XExpression block = ((XtendFunction) bar.getMembers().get(0)).getExpression();
    XConstructorCall constructorCall = (XConstructorCall) ((XBlockExpression) block).getExpressions().get(0);
    assertEquals(associations.getInferredConstructor(foo), constructorCall.getConstructor());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XConstructorCall(org.eclipse.xtext.xbase.XConstructorCall) XExpression(org.eclipse.xtext.xbase.XExpression) Test(org.junit.Test)

Example 24 with XConstructorCall

use of org.eclipse.xtext.xbase.XConstructorCall in project xtext-xtend by eclipse.

the class InferredJvmModelShadowingJavaLinkingTests method testLinkJavaConstructor.

@Test
public void testLinkJavaConstructor() throws Exception {
    XtendClass bar = classFile("test/Bar", "package test class Bar { def bar() {new Foo()} }");
    final XExpression block = ((XtendFunction) bar.getMembers().get(0)).getExpression();
    XConstructorCall constructorCall = (XConstructorCall) ((XBlockExpression) block).getExpressions().get(0);
    assertTrue(isJavaElement(constructorCall.getConstructor()));
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XConstructorCall(org.eclipse.xtext.xbase.XConstructorCall) XExpression(org.eclipse.xtext.xbase.XExpression) Test(org.junit.Test)

Aggregations

XConstructorCall (org.eclipse.xtext.xbase.XConstructorCall)24 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)12 Test (org.junit.Test)11 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)9 XExpression (org.eclipse.xtext.xbase.XExpression)9 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)8 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)8 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)7 JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)6 EObject (org.eclipse.emf.ecore.EObject)5 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)5 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)5 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)5 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)4 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)3 XVariableDeclaration (org.eclipse.xtext.xbase.XVariableDeclaration)3 RichString (org.eclipse.xtend.core.xtend.RichString)2 XtendField (org.eclipse.xtend.core.xtend.XtendField)2 JvmParameterizedTypeReference (org.eclipse.xtext.common.types.JvmParameterizedTypeReference)2 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)2