Search in sources :

Example 41 with XFeatureCall

use of org.eclipse.xtext.xbase.XFeatureCall 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 42 with XFeatureCall

use of org.eclipse.xtext.xbase.XFeatureCall 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 43 with XFeatureCall

use of org.eclipse.xtext.xbase.XFeatureCall 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)

Example 44 with XFeatureCall

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

the class ReorderedFeatureCallArgumentsTest method toArguments.

protected IFeatureCallArguments toArguments(final String signature, final String invocation, final boolean receiver) {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("def void m(");
        _builder.append(signature);
        _builder.append(") {");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append("m(");
        _builder.append(invocation, "\t");
        _builder.append(")");
        _builder.newLineIfNotEmpty();
        _builder.append("}");
        _builder.newLine();
        final String functionString = _builder.toString();
        final XtendFunction function = this.function(functionString);
        XExpression _expression = function.getExpression();
        final XBlockExpression body = ((XBlockExpression) _expression);
        XExpression _head = IterableExtensions.<XExpression>head(body.getExpressions());
        final XFeatureCall featureCall = ((XFeatureCall) _head);
        final EList<XExpression> arguments = featureCall.getFeatureCallArguments();
        final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function);
        final IFeatureCallArguments result = this.factory.createStandardArguments(arguments, operation.getParameters(), receiver, this.getOwner());
        Class<? extends IFeatureCallArguments> _class = result.getClass();
        boolean _equals = Objects.equal(_class, ReorderedFeatureCallArguments.class);
        Assert.assertTrue(_equals);
        return result;
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
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) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XExpression(org.eclipse.xtext.xbase.XExpression) IFeatureCallArguments(org.eclipse.xtext.xbase.typesystem.arguments.IFeatureCallArguments)

Example 45 with XFeatureCall

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

the class ReorderedVarArgFeatureCallArgumentsTest method toArguments.

protected IFeatureCallArguments toArguments(final String signature, final String invocation, final boolean receiver) {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("def void m(");
        _builder.append(signature);
        _builder.append(") {");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append("m(");
        _builder.append(invocation, "\t");
        _builder.append(")");
        _builder.newLineIfNotEmpty();
        _builder.append("}");
        _builder.newLine();
        final String functionString = _builder.toString();
        final XtendFunction function = this.function(functionString);
        XExpression _expression = function.getExpression();
        final XBlockExpression body = ((XBlockExpression) _expression);
        XExpression _head = IterableExtensions.<XExpression>head(body.getExpressions());
        final XFeatureCall featureCall = ((XFeatureCall) _head);
        final EList<XExpression> arguments = featureCall.getFeatureCallArguments();
        final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function);
        final IFeatureCallArguments result = this.factory.createVarArgArguments(arguments, operation.getParameters(), receiver, this.getOwner());
        Class<? extends IFeatureCallArguments> _class = result.getClass();
        boolean _equals = Objects.equal(_class, ReorderedVarArgFeatureCallArguments.class);
        Assert.assertTrue(_equals);
        return result;
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
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) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XExpression(org.eclipse.xtext.xbase.XExpression) IFeatureCallArguments(org.eclipse.xtext.xbase.typesystem.arguments.IFeatureCallArguments)

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