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"));
}
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"));
}
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());
}
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()));
}
Aggregations