Search in sources :

Example 11 with JvmField

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

the class InferredJvmModelTest method testExtensionToAnnotation_01.

@Test
public void testExtensionToAnnotation_01() throws Exception {
    XtendFile xtendFile = file("class C { extension String }");
    JvmGenericType inferredType = getInferredType(xtendFile);
    JvmField jvmField = (JvmField) inferredType.getMembers().get(1);
    assertEquals("_string", jvmField.getSimpleName());
    List<JvmAnnotationReference> annotations = jvmField.getAnnotations();
    assertEquals(1, annotations.size());
    assertEquals(Extension.class.getCanonicalName(), annotations.get(0).getAnnotation().getQualifiedName());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) Extension(org.eclipse.xtext.xbase.lib.Extension) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmField(org.eclipse.xtext.common.types.JvmField) JvmAnnotationReference(org.eclipse.xtext.common.types.JvmAnnotationReference) Test(org.junit.Test)

Example 12 with JvmField

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

the class InferredJvmModelTest method testInferredFunction_06.

@Test
public void testInferredFunction_06() throws Exception {
    XtendFile xtendFile = file("class Foo { def Iterable<? super CharSequence> create result: newArrayList(s) newList(String s) {} }");
    JvmGenericType inferredType = getInferredType(xtendFile);
    XtendClass xtendClass = (XtendClass) xtendFile.getXtendTypes().get(0);
    EList<JvmMember> jvmMembers = inferredType.getMembers();
    assertEquals(4, jvmMembers.size());
    JvmMember jvmMember = jvmMembers.get(1);
    assertTrue(jvmMember instanceof JvmOperation);
    XtendFunction xtendFunction = (XtendFunction) xtendClass.getMembers().get(0);
    assertEquals(xtendFunction.getName(), jvmMember.getSimpleName());
    assertEquals(JvmVisibility.PUBLIC, jvmMember.getVisibility());
    assertEquals("java.lang.Iterable<? extends java.lang.Object & super java.lang.CharSequence>", ((JvmOperation) jvmMember).getReturnType().getIdentifier());
    JvmField cacheVar = (JvmField) jvmMembers.get(2);
    assertEquals("_createCache_" + xtendFunction.getName(), cacheVar.getSimpleName());
    assertEquals(JvmVisibility.PRIVATE, cacheVar.getVisibility());
    assertEquals("java.util.HashMap<java.util.ArrayList<? extends java.lang.Object>, java.lang.Iterable<? extends java.lang.Object & super java.lang.CharSequence>>", cacheVar.getType().getIdentifier());
    JvmOperation privateInitializer = (JvmOperation) jvmMembers.get(3);
    assertEquals("_init_" + xtendFunction.getName(), privateInitializer.getSimpleName());
    assertEquals(JvmVisibility.PRIVATE, privateInitializer.getVisibility());
    assertEquals("java.util.ArrayList<java.lang.CharSequence>", privateInitializer.getParameters().get(0).getParameterType().getIdentifier());
    assertEquals("java.lang.String", privateInitializer.getParameters().get(1).getParameterType().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) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmMember(org.eclipse.xtext.common.types.JvmMember) JvmField(org.eclipse.xtext.common.types.JvmField) Test(org.junit.Test)

Example 13 with JvmField

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

the class InferredJvmModelTest method testInferredFunction_02.

@Test
public void testInferredFunction_02() throws Exception {
    XtendFile xtendFile = file("class Foo { def create result: newArrayList(s) newList(String s) {} }");
    JvmGenericType inferredType = getInferredType(xtendFile);
    XtendClass xtendClass = (XtendClass) xtendFile.getXtendTypes().get(0);
    EList<JvmMember> jvmMembers = inferredType.getMembers();
    assertEquals(4, jvmMembers.size());
    JvmMember jvmMember = jvmMembers.get(1);
    assertTrue(jvmMember instanceof JvmOperation);
    XtendFunction xtendFunction = (XtendFunction) xtendClass.getMembers().get(0);
    assertEquals(xtendFunction.getName(), jvmMember.getSimpleName());
    assertEquals(JvmVisibility.PUBLIC, jvmMember.getVisibility());
    assertEquals("java.util.ArrayList<java.lang.String>", ((JvmOperation) jvmMember).getReturnType().getIdentifier());
    JvmField cacheVar = (JvmField) jvmMembers.get(2);
    assertEquals("_createCache_" + xtendFunction.getName(), cacheVar.getSimpleName());
    assertEquals(JvmVisibility.PRIVATE, cacheVar.getVisibility());
    assertEquals("java.util.HashMap<java.util.ArrayList<? extends java.lang.Object>, java.util.ArrayList<java.lang.String>>", cacheVar.getType().getIdentifier());
    JvmOperation privateInitializer = (JvmOperation) jvmMembers.get(3);
    assertEquals("_init_" + xtendFunction.getName(), privateInitializer.getSimpleName());
    assertEquals(JvmVisibility.PRIVATE, privateInitializer.getVisibility());
    assertEquals("java.util.ArrayList<java.lang.String>", privateInitializer.getParameters().get(0).getParameterType().getIdentifier());
    assertEquals("java.lang.String", privateInitializer.getParameters().get(1).getParameterType().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) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmMember(org.eclipse.xtext.common.types.JvmMember) JvmField(org.eclipse.xtext.common.types.JvmField) Test(org.junit.Test)

Example 14 with JvmField

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

the class LinkingTest method testImplicitFirstArgument_03.

@Test
public void testImplicitFirstArgument_03() throws Exception {
    XtendClass clazz = clazz("import static extension test.ImplicitFirstArgumentStatics.*\n" + "class MyXtendClass {\n" + "  def testExtensionMethods(CharSequence it) {\n" + "    toLowerCase\n" + "  }\n" + "  extension String" + "}");
    XtendFunction func = (XtendFunction) clazz.getMembers().get(0);
    XFeatureCall third = (XFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(0);
    JvmOperation thirdFeature = (JvmOperation) third.getFeature();
    assertEquals("java.lang.String.toLowerCase()", thirdFeature.getIdentifier());
    assertNull(third.getImplicitFirstArgument());
    XMemberFeatureCall thirdReceiver = (XMemberFeatureCall) third.getImplicitReceiver();
    assertTrue(thirdReceiver.getFeature() instanceof JvmField);
    assertNull(third.getInvalidFeatureIssueCode(), third.getInvalidFeatureIssueCode());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) JvmField(org.eclipse.xtext.common.types.JvmField) Test(org.junit.Test)

Example 15 with JvmField

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

the class LinkingTest method testImplicitFirstArgument_06.

@Test
public void testImplicitFirstArgument_06() throws Exception {
    XtendClass clazz = clazz("import static extension test.ImplicitFirstArgumentStatics.*\n" + "class MyXtendClass {\n" + "  def testExtensionMethods(CharSequence it) {\n" + "    contains\n" + "  }\n" + "  extension String" + "}");
    XtendFunction func = (XtendFunction) clazz.getMembers().get(0);
    XFeatureCall sixth = (XFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(0);
    JvmOperation sixthFeature = (JvmOperation) sixth.getFeature();
    assertEquals("java.lang.String.contains(java.lang.CharSequence)", sixthFeature.getIdentifier());
    assertEquals("java.lang.String", sixthFeature.getDeclaringType().getQualifiedName());
    assertNotNull(sixth.getImplicitFirstArgument());
    assertEquals("it", ((XAbstractFeatureCall) sixth.getImplicitFirstArgument()).getFeature().getSimpleName());
    XMemberFeatureCall sixthReceiver = (XMemberFeatureCall) sixth.getImplicitReceiver();
    assertTrue(sixthReceiver.getFeature() instanceof JvmField);
    assertNull(sixth.getInvalidFeatureIssueCode(), sixth.getInvalidFeatureIssueCode());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) JvmField(org.eclipse.xtext.common.types.JvmField) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) Test(org.junit.Test)

Aggregations

JvmField (org.eclipse.xtext.common.types.JvmField)36 Test (org.junit.Test)24 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)19 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)18 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)17 JvmMember (org.eclipse.xtext.common.types.JvmMember)12 EObject (org.eclipse.emf.ecore.EObject)9 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)9 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)8 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)7 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)5 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)4 JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)3 JvmEnumerationLiteral (org.eclipse.xtext.common.types.JvmEnumerationLiteral)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Set (java.util.Set)2 InternalEObject (org.eclipse.emf.ecore.InternalEObject)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)2