Search in sources :

Example 71 with XBlockExpression

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

the class LinkingTest method testBug464264_01.

@Test
public void testBug464264_01() throws Exception {
    XtendFile file = file("import java.util.List\n" + "class C {\n" + "	def m(I i, List<CharSequence> list) {\n" + "		i.strings += list.map[it]\n" + "	}\n" + "	interface I {\n" + "		def List<String> getStrings()\n" + "	}\n" + "}");
    XtendClass c = (XtendClass) file.getXtendTypes().get(0);
    XtendFunction m = (XtendFunction) c.getMembers().get(0);
    XBlockExpression body = (XBlockExpression) m.getExpression();
    XBinaryOperation featureCall = (XBinaryOperation) body.getExpressions().get(0);
    JvmIdentifiableElement feature = featureCall.getFeature();
    assertEquals("org.eclipse.xtext.xbase.lib.CollectionExtensions.operator_add(java.util.Collection,java.lang.Iterable)", feature.getIdentifier());
    assertNull(featureCall.getImplicitReceiver());
    assertNull(featureCall.getImplicitFirstArgument());
    List<Diagnostic> errors = c.eResource().getErrors();
    assertEquals(1, errors.size());
    assertEquals("Type mismatch: cannot convert from List<CharSequence> to Iterable<? extends String>", errors.get(0).getMessage());
}
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) XtextLinkingDiagnostic(org.eclipse.xtext.linking.impl.XtextLinkingDiagnostic) Diagnostic(org.eclipse.emf.ecore.resource.Resource.Diagnostic) XBinaryOperation(org.eclipse.xtext.xbase.XBinaryOperation) Test(org.junit.Test)

Example 72 with XBlockExpression

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

the class Bug409780Test method testConstraintsInfluenceFeatureScope_02.

@Test
public void testConstraintsInfluenceFeatureScope_02() throws Exception {
    XtendFile file = file("class C {\n" + "	def private a(Iterable<CharSequence> it) {\n" + "		map[ b.append('') ]\n" + "	}\n" + "	def private <T extends Appendable> T b(CharSequence c) {}\n" + "}");
    XtendClass c = (XtendClass) file.getXtendTypes().get(0);
    XtendFunction m = (XtendFunction) c.getMembers().get(0);
    XBlockExpression body = (XBlockExpression) m.getExpression();
    XFeatureCall featureCall = (XFeatureCall) body.getExpressions().get(0);
    JvmIdentifiableElement method = featureCall.getFeature();
    assertEquals("org.eclipse.xtext.xbase.lib.IterableExtensions.map(java.lang.Iterable,org.eclipse.xtext.xbase.lib.Functions$Function1)", method.getIdentifier());
    assertTrue(featureCall.isStatic());
    assertTrue(featureCall.isExtension());
    assertFalse(featureCall.isTypeLiteral());
    LightweightTypeReference type = getType(featureCall);
    assertEquals("java.lang.Iterable<java.lang.Appendable>", type.getIdentifier());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) 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 73 with XBlockExpression

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

the class Bug409780Test method testMissingTypeArgumentInference.

@Test
public void testMissingTypeArgumentInference() throws Exception {
    XtendFile file = file("class C {\n" + "	def private <T extends Appendable> Iterable<T> a(Iterable<CharSequence> it) {\n" + "		map[ b ]\n" + "	}\n" + "	def private <T extends Appendable> T b(CharSequence c) {}\n" + "}");
    XtendClass c = (XtendClass) file.getXtendTypes().get(0);
    XtendFunction m = (XtendFunction) c.getMembers().get(0);
    XBlockExpression body = (XBlockExpression) m.getExpression();
    XFeatureCall featureCall = (XFeatureCall) body.getExpressions().get(0);
    JvmIdentifiableElement method = featureCall.getFeature();
    assertEquals("org.eclipse.xtext.xbase.lib.IterableExtensions.map(java.lang.Iterable,org.eclipse.xtext.xbase.lib.Functions$Function1)", method.getIdentifier());
    assertTrue(featureCall.isStatic());
    assertTrue(featureCall.isExtension());
    assertFalse(featureCall.isTypeLiteral());
    LightweightTypeReference type = getType(featureCall);
    assertEquals("java.lang.Iterable<T>", type.getIdentifier());
    LightweightTypeReference expectedType = getExpectedType(featureCall);
    assertEquals("java.lang.Iterable<T>", expectedType.getIdentifier());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) 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 74 with XBlockExpression

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

the class TypeProviderTest method testTypeOfRichStringWithNoExpectedString_1.

@Test
public void testTypeOfRichStringWithNoExpectedString_1() throws Exception {
    XtendFunction function = function("def foo(String x) {" + "println('''someString''')" + "}");
    XBlockExpression block = (XBlockExpression) function.getExpression();
    XAbstractFeatureCall call = (XAbstractFeatureCall) block.getExpressions().get(0);
    XExpression expression = call.getExplicitArguments().get(0);
    // TODO propagate the expectation better via unbound type parameters
    // could still be a charsequence, here
    assertEquals("java.lang.String", getType(expression).getIdentifier());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XExpression(org.eclipse.xtext.xbase.XExpression) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) Test(org.junit.Test)

Example 75 with XBlockExpression

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

the class TypeProviderTest method doTestBug403357.

protected void doTestBug403357(String expression, String expectation) throws Exception {
    XtendFile file = file("import java.util.List\n" + "class C {\n" + "	def static m() {\n" + "		printMe(" + expression + ")\n" + "		" + expression + ".printMe\n" + "		val list = " + expression + "\n" + "		printMe(list)\n" + "		list.printMe\n" + "	}\n" + "	static def void printMe(List<String> listOfStrings) {}" + "}\n");
    XtendClass c = (XtendClass) file.getXtendTypes().get(0);
    XtendFunction function = (XtendFunction) c.getMembers().get(0);
    XBlockExpression body = (XBlockExpression) function.getExpression();
    XFeatureCall featureCall = (XFeatureCall) body.getExpressions().get(0);
    XExpression firstArgument = featureCall.getFeatureCallArguments().get(0);
    assertEquals(expectation, getType(firstArgument).getSimpleName());
    XMemberFeatureCall memberFeatureCall = (XMemberFeatureCall) body.getExpressions().get(1);
    XExpression target = memberFeatureCall.getMemberCallTarget();
    assertEquals(expectation, getType(target).getSimpleName());
    XFeatureCall deferredFeatureCall = (XFeatureCall) body.getExpressions().get(3);
    XExpression deferredFirstArgument = deferredFeatureCall.getFeatureCallArguments().get(0);
    assertEquals(expectation, getType(deferredFirstArgument).getSimpleName());
    XMemberFeatureCall deferredMemberFeatureCall = (XMemberFeatureCall) body.getExpressions().get(4);
    XExpression deferredTarget = deferredMemberFeatureCall.getMemberCallTarget();
    assertEquals(expectation, getType(deferredTarget).getSimpleName());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) XExpression(org.eclipse.xtext.xbase.XExpression)

Aggregations

XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)236 Test (org.junit.Test)210 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)198 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)169 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)126 XExpression (org.eclipse.xtext.xbase.XExpression)84 XMemberFeatureCall (org.eclipse.xtext.xbase.XMemberFeatureCall)84 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)70 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)58 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)56 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)55 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)29 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)26 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)21 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)12 XConstructorCall (org.eclipse.xtext.xbase.XConstructorCall)10 XVariableDeclaration (org.eclipse.xtext.xbase.XVariableDeclaration)10 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)10 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)9 XtendConstructor (org.eclipse.xtend.core.xtend.XtendConstructor)9