Search in sources :

Example 81 with JvmOperation

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

the class LinkingTest method testTypeParameterReference_2.

@Test
public void testTypeParameterReference_2() throws Exception {
    XtendFunction func = (XtendFunction) ((XtendClass) file("class X<Y> { def foo(Y y) { return y }}").getXtendTypes().get(0)).getMembers().get(0);
    JvmOperation operation = associator.getDirectlyInferredOperation(func);
    JvmTypeReference returnType = operation.getReturnType();
    assertEquals("Y", returnType.getIdentifier());
    JvmTypeReference paramType = operation.getParameters().get(0).getParameterType();
    assertEquals("Y", paramType.getIdentifier());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) Test(org.junit.Test)

Example 82 with JvmOperation

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

the class LinkingTest method testImplicitFirstArgument_04.

@Test
public void testImplicitFirstArgument_04() throws Exception {
    XtendClass clazz = clazz("import static extension test.ImplicitFirstArgumentStatics.*\n" + "class MyXtendClass {\n" + "  def testExtensionMethods(CharSequence it) {\n" + "    unique" + "  }\n" + "  extension String" + "}");
    XtendFunction func = (XtendFunction) clazz.getMembers().get(0);
    XFeatureCall forth = (XFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(0);
    JvmOperation forthFeature = (JvmOperation) forth.getFeature();
    assertEquals("test.ImplicitFirstArgumentStatics.unique()", forthFeature.getIdentifier());
    assertNull(forth.getImplicitFirstArgument());
    assertNull(forth.getImplicitReceiver());
    assertNull(forth.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) Test(org.junit.Test)

Example 83 with JvmOperation

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

the class LinkingTest method testBug345827_05.

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

Example 84 with JvmOperation

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

the class LinkingTest method testTypeParameterReference_10.

@Test
public void testTypeParameterReference_10() throws Exception {
    XtendFunction func = (XtendFunction) ((XtendClass) file("class X<Y> { def foo(Iterable<Y> iter) { for(y: iter) { return y } null }}").getXtendTypes().get(0)).getMembers().get(0);
    JvmOperation operation = associator.getDirectlyInferredOperation(func);
    JvmTypeReference returnType = operation.getReturnType();
    assertEquals("Y", returnType.getIdentifier());
    JvmTypeReference paramType = operation.getParameters().get(0).getParameterType();
    assertEquals("java.lang.Iterable<Y>", paramType.getIdentifier());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) Test(org.junit.Test)

Example 85 with JvmOperation

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

the class LinkingTest method testCreateExtension_00.

@Test
public void testCreateExtension_00() throws Exception {
    XtendClass clazz = clazz("class Foo { " + "  def create list: newArrayList('foo') getListWithFooAnd(String s) {" + "	list" + "   this.getListWithFooAnd('')" + "  }" + "}");
    assertEquals(1, clazz.getMembers().size());
    XtendFunction func = (XtendFunction) clazz.getMembers().get(0);
    XFeatureCall featureCall = (XFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(0);
    Set<EObject> elements = associator.getJvmElements(func);
    Iterable<JvmOperation> filter = filter(elements, JvmOperation.class);
    JvmOperation initializer = filter(filter, new Predicate<JvmOperation>() {

        @Override
        public boolean apply(JvmOperation input) {
            return input.getSimpleName().startsWith("_init_");
        }
    }).iterator().next();
    assertEquals(initializer.getParameters().get(0), featureCall.getFeature());
    XAbstractFeatureCall recursiveFeatureCall = (XAbstractFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(1);
    assertEquals("Foo.getListWithFooAnd(java.lang.String)", recursiveFeatureCall.getFeature().getIdentifier());
}
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) EObject(org.eclipse.emf.ecore.EObject) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) Test(org.junit.Test)

Aggregations

JvmOperation (org.eclipse.xtext.common.types.JvmOperation)202 Test (org.junit.Test)127 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)101 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)73 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)71 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)62 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)49 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)38 EObject (org.eclipse.emf.ecore.EObject)30 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)26 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)22 XExpression (org.eclipse.xtext.xbase.XExpression)20 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)20 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)20 JvmField (org.eclipse.xtext.common.types.JvmField)18 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)15 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)15 JvmMember (org.eclipse.xtext.common.types.JvmMember)15 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)11 DispatchHelper (org.eclipse.xtend.core.jvmmodel.DispatchHelper)10