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