use of org.eclipse.xtend.core.xtend.XtendClass in project xtext-xtend by eclipse.
the class LinkingTest method testImplicitFirstArgument_05.
@Test
public void testImplicitFirstArgument_05() throws Exception {
XtendClass clazz = clazz("import static extension test.ImplicitFirstArgumentStatics.*\n" + "class MyXtendClass {\n" + " def testExtensionMethods(CharSequence it) {\n" + " withObject\n" + " }\n" + " extension String" + " def withObject(Object obj) { null }" + "}");
XtendFunction func = (XtendFunction) clazz.getMembers().get(0);
XFeatureCall fifth = (XFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(0);
JvmOperation fifthFeature = (JvmOperation) fifth.getFeature();
assertEquals("MyXtendClass.withObject(java.lang.Object)", fifthFeature.getIdentifier());
assertEquals(1, fifthFeature.getParameters().size());
assertNotNull(fifth.getImplicitFirstArgument());
assertEquals("it", ((XAbstractFeatureCall) fifth.getImplicitFirstArgument()).getFeature().getSimpleName());
XFeatureCall fifthReceiver = (XFeatureCall) fifth.getImplicitReceiver();
assertTrue(fifthReceiver.getFeature() instanceof JvmGenericType);
assertNull(fifth.getInvalidFeatureIssueCode(), fifth.getInvalidFeatureIssueCode());
}
use of org.eclipse.xtend.core.xtend.XtendClass in project xtext-xtend by eclipse.
the class LinkingTest method testFeatureScope_3.
@Test
public void testFeatureScope_3() throws Exception {
XtendFile file = file("import java.lang.String class X { def String foo(String foo) {[String foo|foo]}}");
XtendClass xClass = ((XtendClass) file.getXtendTypes().get(0));
XtendFunction func = (XtendFunction) xClass.getMembers().get(0);
XClosure closure = (XClosure) ((XBlockExpression) func.getExpression()).getExpressions().get(0);
XAbstractFeatureCall featureCall1 = (XAbstractFeatureCall) (((XBlockExpression) closure.getExpression()).getExpressions().get(0));
assertEquals(closure.getFormalParameters().get(0), featureCall1.getFeature());
}
use of org.eclipse.xtend.core.xtend.XtendClass in project xtext-xtend by eclipse.
the class LinkingTest method testInstanceOverExtension_04.
@Test
public void testInstanceOverExtension_04() throws Exception {
XtendClass clazz = clazz("" + "class C {" + " def m(java.util.List<String> list) {\n" + " list.get(0)\n" + " }\n" + "}");
XAbstractFeatureCall substring = findSingleFeatureCall(clazz);
assertEquals("java.util.List.get(int)", substring.getFeature().getIdentifier());
}
use of org.eclipse.xtend.core.xtend.XtendClass in project xtext-xtend by eclipse.
the class LinkingTest method testBug345433_01.
@Test
public void testBug345433_01() throws Exception {
String classAsString = "import static extension org.eclipse.xtext.GrammarUtil.*\n" + "class Foo {" + " org.eclipse.xtext.Grammar grammar\n" + " def function1() {\n" + " grammar.containedRuleCalls.filter(e | " + " !e.isAssigned() && !e.isEObjectRuleCall()" + " ).map(e | e.rule)\n" + " }\n" + " def function2() {\n" + " newArrayList(function1().head())\n" + " }\n" + "}";
XtendClass clazz = clazz(classAsString);
IResourceValidator validator = ((XtextResource) clazz.eResource()).getResourceServiceProvider().getResourceValidator();
List<Issue> issues = validator.validate(clazz.eResource(), CheckMode.ALL, CancelIndicator.NullImpl);
assertTrue("Resource contained errors : " + issues.toString(), issues.isEmpty());
XtendFunction function1 = (XtendFunction) clazz.getMembers().get(1);
JvmOperation operation1 = associator.getDirectlyInferredOperation(function1);
assertEquals("java.lang.Iterable<org.eclipse.xtext.AbstractRule>", operation1.getReturnType().getIdentifier());
XtendFunction function2 = (XtendFunction) clazz.getMembers().get(2);
JvmOperation operation2 = associator.getDirectlyInferredOperation(function2);
assertEquals("java.util.ArrayList<org.eclipse.xtext.AbstractRule>", operation2.getReturnType().getIdentifier());
}
use of org.eclipse.xtend.core.xtend.XtendClass in project xtext-xtend by eclipse.
the class UnicodeEscapeLinkingTest method testIdentifiersWithUnicode_01.
@Test
public void testIdentifiersWithUnicode_01() throws Exception {
XtendClass clazz = clazz("class A {\n" + " String a\n" + " def m() {\n" + " \\u0061\n" + " }\n" + "}");
XFeatureCall call = (XFeatureCall) ((XBlockExpression) ((XtendFunction) clazz.getMembers().get(1)).getExpression()).getExpressions().get(0);
JvmIdentifiableElement feature = call.getFeature();
assertFalse(feature.eIsProxy());
assertSame(feature, associator.getJvmField((XtendField) clazz.getMembers().get(0)));
}
Aggregations