Search in sources :

Example 41 with XMemberFeatureCall

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

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

the class TypeProviderTest method testReturnTypeInConstructor_01.

@Test
public void testReturnTypeInConstructor_01() throws Exception {
    XtendConstructor constructor = constructor("new() {\n" + "	''.toString\n" + "}\n");
    XBlockExpression body = (XBlockExpression) constructor.getExpression();
    assertEquals("void", getExpectedType(body).getIdentifier());
    assertEquals("void", getExpectedReturnType(body).getIdentifier());
    XMemberFeatureCall toString = (XMemberFeatureCall) body.getExpressions().get(0);
    assertNull(getExpectedType(toString));
    assertNull(getExpectedReturnType(toString));
}
Also used : XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtendConstructor(org.eclipse.xtend.core.xtend.XtendConstructor) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) Test(org.junit.Test)

Example 43 with XMemberFeatureCall

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

the class XtendHoverSignatureProviderTest method testAutcastExpressions_2.

@Test
public void testAutcastExpressions_2() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package testPackage");
        _builder.newLine();
        _builder.append("class Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("CharSequence c = \"\"");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def foo() {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("if (c instanceof String) {");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("c.substring(1, 1)");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("switch(c){");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("String : c.length");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet());
        XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(xtendFile.getXtendTypes());
        Assert.assertEquals("CharSequence c", this.signatureProvider.getSignature(IterableExtensions.<XtendMember>head(((XtendClass) _head).getMembers())));
        XtendTypeDeclaration _head_1 = IterableExtensions.<XtendTypeDeclaration>head(xtendFile.getXtendTypes());
        XtendMember _get = ((XtendClass) _head_1).getMembers().get(1);
        final XtendFunction func = ((XtendFunction) _get);
        XExpression _expression = func.getExpression();
        final XBlockExpression block = ((XBlockExpression) _expression);
        XExpression _head_2 = IterableExtensions.<XExpression>head(block.getExpressions());
        final XIfExpression ifexpr = ((XIfExpression) _head_2);
        final XExpression then = ifexpr.getThen();
        XExpression _head_3 = IterableExtensions.<XExpression>head(((XBlockExpression) then).getExpressions());
        final XExpression target = ((XMemberFeatureCall) _head_3).getMemberCallTarget();
        Assert.assertEquals("String Foo.c", this.signatureProvider.getSignature(target));
        XExpression _get_1 = block.getExpressions().get(1);
        final XSwitchExpression switchExpr = ((XSwitchExpression) _get_1);
        XExpression _then = IterableExtensions.<XCasePart>head(switchExpr.getCases()).getThen();
        final XExpression expr = ((XMemberFeatureCall) _then).getMemberCallTarget();
        Assert.assertEquals("String Foo.c", this.signatureProvider.getSignature(expr));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XIfExpression(org.eclipse.xtext.xbase.XIfExpression) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XSwitchExpression(org.eclipse.xtext.xbase.XSwitchExpression) XExpression(org.eclipse.xtext.xbase.XExpression) Test(org.junit.Test)

Example 44 with XMemberFeatureCall

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

the class XtendHoverSignatureProviderTest method testAutcastExpressions_3.

@Test
public void testAutcastExpressions_3() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package testPackage");
        _builder.newLine();
        _builder.append("class Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def foo(CharSequence c) {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("if (c instanceof String) {");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("c.substring(1, 1)");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("switch(c){");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("String : c.length");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet());
        XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(xtendFile.getXtendTypes());
        XtendMember _head_1 = IterableExtensions.<XtendMember>head(((XtendClass) _head).getMembers());
        final XtendFunction func = ((XtendFunction) _head_1);
        Assert.assertEquals("CharSequence c - foo(CharSequence)", this.signatureProvider.getSignature(IterableExtensions.<XtendParameter>head(func.getParameters())));
        XExpression _expression = func.getExpression();
        final XBlockExpression block = ((XBlockExpression) _expression);
        XExpression _head_2 = IterableExtensions.<XExpression>head(block.getExpressions());
        final XIfExpression ifexpr = ((XIfExpression) _head_2);
        final XExpression then = ifexpr.getThen();
        XExpression _head_3 = IterableExtensions.<XExpression>head(((XBlockExpression) then).getExpressions());
        final XExpression target = ((XMemberFeatureCall) _head_3).getMemberCallTarget();
        Assert.assertEquals("String c", this.signatureProvider.getSignature(target));
        XExpression _get = block.getExpressions().get(1);
        final XSwitchExpression switchExpr = ((XSwitchExpression) _get);
        XExpression _then = IterableExtensions.<XCasePart>head(switchExpr.getCases()).getThen();
        final XExpression expr = ((XMemberFeatureCall) _then).getMemberCallTarget();
        Assert.assertEquals("String c", this.signatureProvider.getSignature(expr));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtendParameter(org.eclipse.xtend.core.xtend.XtendParameter) XIfExpression(org.eclipse.xtext.xbase.XIfExpression) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XSwitchExpression(org.eclipse.xtext.xbase.XSwitchExpression) XExpression(org.eclipse.xtext.xbase.XExpression) Test(org.junit.Test)

Example 45 with XMemberFeatureCall

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

the class XtendHoverSerializer method computeUnsugaredExpression.

public String computeUnsugaredExpression(EObject object) {
    if (object instanceof XAbstractFeatureCall) {
        StringBuilder stringBuilder = new StringBuilder();
        XAbstractFeatureCall featureCall = (XAbstractFeatureCall) object;
        JvmIdentifiableElement feature = featureCall.getFeature();
        if (feature != null && !feature.eIsProxy()) {
            // Static extensions which are no expliciteOperationCalls
            if (featureCall instanceof XMemberFeatureCall && feature instanceof JvmOperation && !((XMemberFeatureCall) featureCall).isExplicitOperationCall()) {
                JvmOperation jvmOperation = (JvmOperation) feature;
                if (jvmOperation.isStatic()) {
                    return stringBuilder.append(getStaticCallDesugaredVersion(featureCall, jvmOperation)).toString();
                }
            }
            // Static calls with implicit receiver or implicit first argument
            if (featureCall.getImplicitReceiver() != null || featureCall.getImplicitFirstArgument() != null) {
                if (featureCall.isStatic()) {
                    return stringBuilder.append(getStaticCallDesugaredVersion(featureCall, (JvmMember) feature)).toString();
                }
                XExpression receiver = featureCall.getActualReceiver();
                if (receiver instanceof XMemberFeatureCall) {
                    stringBuilder.append(THIS).append(DELIMITER);
                    stringBuilder.append(((XMemberFeatureCall) receiver).getFeature().getSimpleName()).append(DELIMITER);
                } else if (receiver instanceof XAbstractFeatureCall) {
                    JvmIdentifiableElement receiverFeature = ((XAbstractFeatureCall) receiver).getFeature();
                    if (receiverFeature == feature.eContainer()) {
                        stringBuilder.append(THIS).append(DELIMITER);
                    } else {
                        stringBuilder.append(receiverFeature.getSimpleName()).append(DELIMITER);
                    }
                }
                stringBuilder.append(feature.getSimpleName());
                if (feature instanceof JvmExecutable)
                    stringBuilder.append(computeArguments(featureCall));
                return stringBuilder.toString();
            }
        }
    }
    return "";
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmExecutable(org.eclipse.xtext.common.types.JvmExecutable) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) XExpression(org.eclipse.xtext.xbase.XExpression) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall)

Aggregations

XMemberFeatureCall (org.eclipse.xtext.xbase.XMemberFeatureCall)88 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)82 Test (org.junit.Test)82 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)78 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)74 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)46 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)39 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)19 XExpression (org.eclipse.xtext.xbase.XExpression)14 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)7 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)6 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)5 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)5 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)5 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)4 XIfExpression (org.eclipse.xtext.xbase.XIfExpression)4 XSwitchExpression (org.eclipse.xtext.xbase.XSwitchExpression)4 XtendParameter (org.eclipse.xtend.core.xtend.XtendParameter)3 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)2 RichString (org.eclipse.xtend.core.xtend.RichString)2