Search in sources :

Example 76 with JvmOperation

use of org.eclipse.xtext.common.types.JvmOperation 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());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) Issue(org.eclipse.xtext.validation.Issue) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) IResourceValidator(org.eclipse.xtext.validation.IResourceValidator) Test(org.junit.Test)

Example 77 with JvmOperation

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

the class ParserTest method testRichStringFOR_03.

@Test
public void testRichStringFOR_03() throws Exception {
    XtendFunction function = function("def withForLoop(String it) '''�it��val it = 1..10��FOR i: it SEPARATOR it��ENDFOR�'''");
    final RichString richString = (RichString) function.getExpression();
    assertTrue(richString.getExpressions().get(0) instanceof RichStringLiteral);
    assertTrue(richString.getExpressions().get(1) instanceof XFeatureCall);
    JvmOperation operation = associations.getDirectlyInferredOperation(function);
    assertSame(operation.getParameters().get(0), ((XAbstractFeatureCall) richString.getExpressions().get(1)).getFeature());
    assertTrue(richString.getExpressions().get(2) instanceof RichStringLiteral);
    assertTrue(richString.getExpressions().get(3) instanceof XVariableDeclaration);
    assertTrue(richString.getExpressions().get(4) instanceof RichStringLiteral);
    assertTrue(richString.getExpressions().get(5) instanceof RichStringForLoop);
    final RichStringForLoop rsFor = (RichStringForLoop) richString.getExpressions().get(5);
    assertTrue(rsFor.getForExpression() instanceof XFeatureCall);
    assertSame(richString.getExpressions().get(3), ((XAbstractFeatureCall) rsFor.getForExpression()).getFeature());
    assertEquals("i", rsFor.getDeclaredParam().getName());
    assertTrue(rsFor.getSeparator() instanceof XFeatureCall);
    assertSame(richString.getExpressions().get(3), ((XAbstractFeatureCall) rsFor.getSeparator()).getFeature());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XVariableDeclaration(org.eclipse.xtext.xbase.XVariableDeclaration) RichString(org.eclipse.xtend.core.xtend.RichString) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) RichStringLiteral(org.eclipse.xtend.core.xtend.RichStringLiteral) RichStringForLoop(org.eclipse.xtend.core.xtend.RichStringForLoop) Test(org.junit.Test)

Example 78 with JvmOperation

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

the class LinkingTest method testTypeParameterReference_18.

@Test
public void testTypeParameterReference_18() throws Exception {
    XtendFunction func = (XtendFunction) ((XtendClass) file("class X<Z> { def foo() { new X }}").getXtendTypes().get(0)).getMembers().get(0);
    JvmOperation operation = associator.getDirectlyInferredOperation(func);
    JvmTypeReference returnType = operation.getReturnType();
    assertEquals("X<java.lang.Object>", returnType.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 79 with JvmOperation

use of org.eclipse.xtext.common.types.JvmOperation 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 80 with JvmOperation

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

the class LinkingTest method testTypeParameterReference_11.

@Test
public void testTypeParameterReference_11() throws Exception {
    XtendFunction func = (XtendFunction) ((XtendClass) file("class X<Z> implements Iterable<Z> { def Iterable<Z> foo() { val result = new X result }}").getXtendTypes().get(0)).getMembers().get(0);
    JvmOperation operation = associator.getDirectlyInferredOperation(func);
    JvmTypeReference returnType = operation.getReturnType();
    assertEquals("java.lang.Iterable<Z>", returnType.getIdentifier());
    LightweightTypeReference bodyType = getType(func.getExpression());
    assertEquals("X<Z>", bodyType.getIdentifier());
    LightweightTypeReference bodyReturnType = getReturnType(func.getExpression());
    assertEquals("X<Z>", bodyReturnType.getIdentifier());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) 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