Search in sources :

Example 11 with XVariableDeclaration

use of org.eclipse.xtext.xbase.XVariableDeclaration 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 12 with XVariableDeclaration

use of org.eclipse.xtext.xbase.XVariableDeclaration 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)

Aggregations

XVariableDeclaration (org.eclipse.xtext.xbase.XVariableDeclaration)12 Test (org.junit.Test)9 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)8 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)8 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)7 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)6 XExpression (org.eclipse.xtext.xbase.XExpression)6 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)5 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)5 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)4 XConstructorCall (org.eclipse.xtext.xbase.XConstructorCall)4 RichString (org.eclipse.xtend.core.xtend.RichString)3 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)3 EObject (org.eclipse.emf.ecore.EObject)2 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)2 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)2 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)2 CoreException (org.eclipse.core.runtime.CoreException)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 ParameterInfo (org.eclipse.jdt.internal.corext.refactoring.ParameterInfo)1