Search in sources :

Example 76 with XBlockExpression

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

the class TypeProviderTest method testExpectationRelevantExpressionType_01.

@Test
public void testExpectationRelevantExpressionType_01() throws Exception {
    String clazzString = "import java.util.Set\n" + "import org.eclipse.xtext.xbase.typesystem.util.TypeParameterSubstitutor\n" + "import org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference\n" + "class C extends TypeParameterSubstitutor<Set<String>> {\n" + "  override substitute(LightweightTypeReference original) {\n" + "    original.accept(this, newHashSet)\n" + "  }" + "}";
    XtendClass clazz = (XtendClass) file(clazzString, false).getXtendTypes().get(0);
    XtendFunction function = (XtendFunction) clazz.getMembers().get(0);
    XBlockExpression body = (XBlockExpression) function.getExpression();
    XMemberFeatureCall invocation = (XMemberFeatureCall) body.getExpressions().get(0);
    XFeatureCall newHashSet = (XFeatureCall) invocation.getActualArguments().get(1);
    assertEquals("newHashSet", newHashSet.getFeature().getSimpleName());
    assertEquals("Set<String>", getExpectedType(newHashSet).getSimpleName());
    assertEquals("HashSet<String>", getType(newHashSet).getSimpleName());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) Test(org.junit.Test)

Example 77 with XBlockExpression

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

the class TypeProviderTest method testTypeOfRichStringWithExpectedString_3.

@Ignore("TODO improve expectation if the expected type is an unresolved type parameter")
@Test
public void testTypeOfRichStringWithExpectedString_3() throws Exception {
    XtendFunction function = function("def foo(String x) {" + "System::out.println('''someString''')" + "}");
    XBlockExpression block = (XBlockExpression) function.getExpression();
    XMemberFeatureCall call = (XMemberFeatureCall) block.getExpressions().get(0);
    XExpression expression = call.getMemberCallArguments().get(0);
    assertEquals("java.lang.String", getType(expression).getIdentifier());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) XExpression(org.eclipse.xtext.xbase.XExpression) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 78 with XBlockExpression

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

the class TypeProviderTest method testExpectationRelevantExpressionType_06.

@Test
public void testExpectationRelevantExpressionType_06() throws Exception {
    String clazzString = "class C<T> {\n" + "  def String m(String s, Class<? extends T>[] types) {\n" + "    this.m('', newArrayList)\n" + "  }\n" + "}";
    XtendClass clazz = (XtendClass) file(clazzString, false).getXtendTypes().get(0);
    XtendFunction function = (XtendFunction) clazz.getMembers().get(0);
    XBlockExpression body = (XBlockExpression) function.getExpression();
    XMemberFeatureCall invocation = (XMemberFeatureCall) body.getExpressions().get(0);
    XFeatureCall newArrayList = (XFeatureCall) invocation.getActualArguments().get(1);
    assertEquals("newArrayList", newArrayList.getFeature().getSimpleName());
    assertEquals("Class<? extends T>[]", getExpectedType(newArrayList).getSimpleName());
    assertEquals("ArrayList<Class<? extends T>>", getType(newArrayList).getSimpleName());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) Test(org.junit.Test)

Example 79 with XBlockExpression

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

the class TypeProviderTest method testExpectationRelevantExpressionType_04.

@Test
public void testExpectationRelevantExpressionType_04() throws Exception {
    String clazzString = "class C<T> {\n" + "  def String m(String s, Class<T>[] types) {\n" + "    this.m('', newArrayList)\n" + "  }\n" + "}";
    XtendClass clazz = (XtendClass) file(clazzString, false).getXtendTypes().get(0);
    XtendFunction function = (XtendFunction) clazz.getMembers().get(0);
    XBlockExpression body = (XBlockExpression) function.getExpression();
    XMemberFeatureCall invocation = (XMemberFeatureCall) body.getExpressions().get(0);
    XFeatureCall newArrayList = (XFeatureCall) invocation.getActualArguments().get(1);
    assertEquals("newArrayList", newArrayList.getFeature().getSimpleName());
    assertEquals("Class<T>[]", getExpectedType(newArrayList).getSimpleName());
    assertEquals("ArrayList<Class<T>>", getType(newArrayList).getSimpleName());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) Test(org.junit.Test)

Example 80 with XBlockExpression

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

the class TypeProviderTest method testExpectationRelevantExpressionType_02.

@Test
public void testExpectationRelevantExpressionType_02() throws Exception {
    String clazzString = "import java.util.Set\n" + "import org.eclipse.xtext.xbase.typesystem.util.TypeParameterSubstitutor\n" + "import org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference\n" + "class C<T> extends TypeParameterSubstitutor<Set<T>> {\n" + "  override substitute(LightweightTypeReference original) {\n" + "    original.accept(this, newHashSet)\n" + "  }" + "}";
    XtendClass clazz = (XtendClass) file(clazzString, false).getXtendTypes().get(0);
    XtendFunction function = (XtendFunction) clazz.getMembers().get(0);
    XBlockExpression body = (XBlockExpression) function.getExpression();
    XMemberFeatureCall invocation = (XMemberFeatureCall) body.getExpressions().get(0);
    XFeatureCall newHashSet = (XFeatureCall) invocation.getActualArguments().get(1);
    assertEquals("newHashSet", newHashSet.getFeature().getSimpleName());
    assertEquals("HashSet<T>", getType(newHashSet).getSimpleName());
    assertEquals("Set<T>", getExpectedType(newHashSet).getSimpleName());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) Test(org.junit.Test)

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