Search in sources :

Example 56 with XFeatureCall

use of org.eclipse.xtext.xbase.XFeatureCall in project xtext-xtend by eclipse.

the class LinkingTest method testStaticNestedClass_01.

@Test
public void testStaticNestedClass_01() throws Exception {
    XtendFile file = file("class C {\n" + "  static class D {\n" + "    def static void m(CharSequence c) { m('') }\n" + "  }\n" + "  def void m(String s) {}\n" + "}");
    XtendClass c = (XtendClass) file.getXtendTypes().get(0);
    XtendClass d = (XtendClass) c.getMembers().get(0);
    XtendFunction m = (XtendFunction) d.getMembers().get(0);
    XBlockExpression body = (XBlockExpression) m.getExpression();
    XFeatureCall featureCall = (XFeatureCall) body.getExpressions().get(0);
    JvmIdentifiableElement feature = featureCall.getFeature();
    assertEquals("C$D.m(java.lang.CharSequence)", feature.getIdentifier());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) Test(org.junit.Test)

Example 57 with XFeatureCall

use of org.eclipse.xtext.xbase.XFeatureCall in project xtext-xtend by eclipse.

the class LinkingTest method testBug345827_01.

@Test
public void testBug345827_01() throws Exception {
    XtendFunction function = function("def String name() {\n" + "  var name = ''\n" + "  name" + "}");
    XBlockExpression block = (XBlockExpression) function.getExpression();
    XFeatureCall featureCall = (XFeatureCall) block.getExpressions().get(1);
    // TODO actually we should prefer the function in case 'explicitOperationCall' is true
    // for a featureCall
    assertSame(block.getExpressions().get(0), featureCall.getFeature());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) Test(org.junit.Test)

Example 58 with XFeatureCall

use of org.eclipse.xtext.xbase.XFeatureCall in project xtext-xtend by eclipse.

the class LinkingTest method testTypeOfSuper.

@Test
public void testTypeOfSuper() throws Exception {
    String classAsString = "class Foo extends java.util.ArrayList<String> {" + "	def m() {\n" + "		super.add(null)\n" + "	}\n" + "}";
    XtendClass clazz = clazz(classAsString);
    XtendFunction function = (XtendFunction) clazz.getMembers().get(0);
    XExpression body = function.getExpression();
    XBlockExpression block = (XBlockExpression) body;
    XMemberFeatureCall featureCall = (XMemberFeatureCall) block.getExpressions().get(0);
    XFeatureCall superCall = (XFeatureCall) featureCall.getMemberCallTarget();
    LightweightTypeReference type = getType(superCall);
    assertEquals("java.util.ArrayList<java.lang.String>", type.getIdentifier());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) XExpression(org.eclipse.xtext.xbase.XExpression) Test(org.junit.Test)

Example 59 with XFeatureCall

use of org.eclipse.xtext.xbase.XFeatureCall in project xtext-xtend by eclipse.

the class LinkingTest method testBug345827_04.

@Test
public void testBug345827_04() throws Exception {
    XtendFunction function = function("def String name(String param) {\n" + "  var name = ''\n" + "  name('param')" + "}");
    XBlockExpression block = (XBlockExpression) function.getExpression();
    XFeatureCall featureCall = (XFeatureCall) block.getExpressions().get(1);
    assertSame(associator.getDirectlyInferredOperation(function), featureCall.getFeature());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) Test(org.junit.Test)

Example 60 with XFeatureCall

use of org.eclipse.xtext.xbase.XFeatureCall in project xtext-xtend by eclipse.

the class LinkingTest method testDeclaredConstructor_01.

@Test
public void testDeclaredConstructor_01() throws Exception {
    XtendClass clazz = clazz("class Foo { " + "  int i" + "  new(int i) { this.i = i }" + "}");
    assertEquals(2, clazz.getMembers().size());
    XtendConstructor constructor = (XtendConstructor) clazz.getMembers().get(1);
    XAssignment assignment = (XAssignment) ((XBlockExpression) constructor.getExpression()).getExpressions().get(0);
    JvmField field = (JvmField) assignment.getFeature();
    assertEquals("i", field.getSimpleName());
    XFeatureCall target = (XFeatureCall) assignment.getAssignable();
    JvmDeclaredType identifiableElement = (JvmDeclaredType) target.getFeature();
    assertEquals("Foo", identifiableElement.getSimpleName());
    XFeatureCall value = (XFeatureCall) assignment.getValue();
    JvmFormalParameter parameter = (JvmFormalParameter) value.getFeature();
    assertEquals("i", parameter.getSimpleName());
}
Also used : XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtendConstructor(org.eclipse.xtend.core.xtend.XtendConstructor) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmField(org.eclipse.xtext.common.types.JvmField) XAssignment(org.eclipse.xtext.xbase.XAssignment) Test(org.junit.Test)

Aggregations

XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)93 Test (org.junit.Test)81 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)72 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)67 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)62 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)29 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)26 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)20 XMemberFeatureCall (org.eclipse.xtext.xbase.XMemberFeatureCall)19 XExpression (org.eclipse.xtext.xbase.XExpression)14 RichString (org.eclipse.xtend.core.xtend.RichString)7 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)7 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)6 XtendConstructor (org.eclipse.xtend.core.xtend.XtendConstructor)5 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)5 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)5 EObject (org.eclipse.emf.ecore.EObject)4 XtendField (org.eclipse.xtend.core.xtend.XtendField)4 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)4 ParameterInfo (org.eclipse.jdt.internal.corext.refactoring.ParameterInfo)3