Search in sources :

Example 46 with XMemberFeatureCall

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

the class CreateMemberQuickfixes method addQuickfixes.

@Override
public void addQuickfixes(Issue issue, IssueResolutionAcceptor issueResolutionAcceptor, IXtextDocument xtextDocument, XtextResource resource, EObject referenceOwner, EReference unresolvedReference) throws Exception {
    if (referenceOwner instanceof XAbstractFeatureCall) {
        XAbstractFeatureCall call = (XAbstractFeatureCall) referenceOwner;
        String newMemberName = (issue.getData() != null && issue.getData().length > 0) ? issue.getData()[0] : null;
        if (newMemberName != null) {
            if (call instanceof XMemberFeatureCall) {
                if (!call.isExplicitOperationCallOrBuilderSyntax()) {
                    newFieldQuickfix(newMemberName, call, issue, issueResolutionAcceptor);
                    newGetterQuickfixes(newMemberName, call, issue, issueResolutionAcceptor);
                }
                newMethodQuickfixes(newMemberName, call, issue, issueResolutionAcceptor);
            } else if (call instanceof XFeatureCall) {
                if (!call.isExplicitOperationCallOrBuilderSyntax()) {
                    if (logicalContainerProvider.getNearestLogicalContainer(call) instanceof JvmExecutable)
                        newLocalVariableQuickfix(newMemberName, call, issue, issueResolutionAcceptor);
                    newFieldQuickfix(newMemberName, call, issue, issueResolutionAcceptor);
                    newGetterQuickfixes(newMemberName, call, issue, issueResolutionAcceptor);
                }
                newMethodQuickfixes(newMemberName, call, issue, issueResolutionAcceptor);
            } else if (call instanceof XAssignment) {
                newSetterQuickfix(issue, issueResolutionAcceptor, newMemberName, call);
                XAssignment assigment = (XAssignment) call;
                if (assigment.getAssignable() == null) {
                    newLocalVariableQuickfix(newMemberName, call, issue, issueResolutionAcceptor);
                    newFieldQuickfix(newMemberName, call, issue, issueResolutionAcceptor);
                } else if (isThis(assigment)) {
                    newFieldQuickfix(newMemberName, call, issue, issueResolutionAcceptor);
                }
            }
        }
        if (call.isOperation()) {
            JvmIdentifiableElement feature = call.getFeature();
            if (feature.eIsProxy()) {
                String operatorMethodName = getOperatorMethodName(call);
                if (operatorMethodName != null)
                    newMethodQuickfixes(operatorMethodName, call, issue, issueResolutionAcceptor);
            }
        }
        if (call instanceof XFeatureCall && call.getFeature() instanceof JvmConstructor) {
            newConstructorQuickfix(issue, issueResolutionAcceptor, (XFeatureCall) call);
        }
    }
    if (referenceOwner instanceof XConstructorCall) {
        newConstructorQuickfix(issue, issueResolutionAcceptor, (XConstructorCall) referenceOwner);
    }
}
Also used : JvmExecutable(org.eclipse.xtext.common.types.JvmExecutable) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) XConstructorCall(org.eclipse.xtext.xbase.XConstructorCall) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) XAssignment(org.eclipse.xtext.xbase.XAssignment)

Example 47 with XMemberFeatureCall

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

the class ExtractMethodRefactoring method createMethodCallEdit.

protected void createMethodCallEdit(DocumentRewriter.Section methodCallSection, ITextRegion expressionRegion) throws BadLocationException {
    if (firstExpression.eContainer() instanceof RichString) {
        methodCallSection.append("�");
    }
    if (isNeedsReturnExpression()) {
        JvmIdentifiableElement returnFeature = ((XFeatureCall) returnExpression).getFeature();
        if (isFinalFeature(returnFeature))
            methodCallSection.append("val ");
        else
            methodCallSection.append("var ");
        methodCallSection.append(returnFeature.getSimpleName()).append(" = ");
    }
    boolean needsSurroundingParentheses = false;
    if (firstExpression.eContainer() instanceof XMemberFeatureCall) {
        if (((XMemberFeatureCall) firstExpression.eContainer()).getMemberCallArguments().size() == 1) {
            String expressionExpanded = document.get(expressionRegion.getOffset() - 1, expressionRegion.getLength() + 2);
            if (!expressionExpanded.startsWith("(") || !expressionExpanded.endsWith(")")) {
                needsSurroundingParentheses = true;
                methodCallSection.append("(");
            }
        }
    }
    methodCallSection.append(methodName).append("(");
    boolean isFirst = true;
    for (ParameterInfo parameterInfo : getParameterInfos()) {
        if (!isFirst)
            methodCallSection.append(", ");
        isFirst = false;
        methodCallSection.append(parameterInfo.getOldName());
    }
    methodCallSection.append(")");
    if (needsSurroundingParentheses)
        methodCallSection.append(")");
    if (lastExpression.eContainer() instanceof RichString) {
        methodCallSection.append("�");
    }
}
Also used : RichString(org.eclipse.xtend.core.xtend.RichString) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) RichString(org.eclipse.xtend.core.xtend.RichString) ParameterInfo(org.eclipse.jdt.internal.corext.refactoring.ParameterInfo)

Example 48 with XMemberFeatureCall

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

the class XtendHoverSignatureProviderTest method test381185.

@Test
public void test381185() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package testPackage");
        _builder.newLine();
        _builder.append("class Foo{");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("Bar b");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def bar(){ ");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("b.foo");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        _builder.append("class Bar {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("Foo f");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def foo() {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("f.bar");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        _builder.newLine();
        final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet());
        final XtendClass clazz = IterableExtensions.<XtendClass>head(Iterables.<XtendClass>filter(xtendFile.getXtendTypes(), XtendClass.class));
        final XtendClass clazz2 = IterableExtensions.<XtendClass>head(IterableExtensions.<XtendClass>drop(Iterables.<XtendClass>filter(xtendFile.getXtendTypes(), XtendClass.class), 1));
        XtendMember _get = clazz.getMembers().get(1);
        final XtendFunction function1 = ((XtendFunction) _get);
        XtendMember _get_1 = clazz2.getMembers().get(1);
        final XtendFunction function2 = ((XtendFunction) _get_1);
        XExpression _expression = function1.getExpression();
        final XBlockExpression expression1 = ((XBlockExpression) _expression);
        XExpression _expression_1 = function2.getExpression();
        final XBlockExpression expression2 = ((XBlockExpression) _expression_1);
        XExpression _get_2 = expression1.getExpressions().get(0);
        final XMemberFeatureCall call1 = ((XMemberFeatureCall) _get_2);
        XExpression _get_3 = expression2.getExpressions().get(0);
        final XMemberFeatureCall call2 = ((XMemberFeatureCall) _get_3);
        Assert.assertEquals("Object Bar.foo()", this.signatureProvider.getSignature(call1.getFeature()));
        Assert.assertEquals("Object Foo.bar()", this.signatureProvider.getSignature(call2.getFeature()));
        XExpression _memberCallTarget = call1.getMemberCallTarget();
        Assert.assertEquals("Bar Foo.b", this.signatureProvider.getSignature(((XFeatureCall) _memberCallTarget).getFeature()));
        XExpression _memberCallTarget_1 = call2.getMemberCallTarget();
        Assert.assertEquals("Foo Bar.f", this.signatureProvider.getSignature(((XFeatureCall) _memberCallTarget_1).getFeature()));
    } 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) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XExpression(org.eclipse.xtext.xbase.XExpression) Test(org.junit.Test)

Example 49 with XMemberFeatureCall

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

the class XtendHoverSignatureProviderTest method testAutcastExpressions.

@Test
public void testAutcastExpressions() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package testPackage");
        _builder.newLine();
        _builder.append("class Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def foo() {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("val 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);
        XExpression _expression = func.getExpression();
        final XBlockExpression block = ((XBlockExpression) _expression);
        final XExpression dec = IterableExtensions.<XExpression>head(block.getExpressions());
        Assert.assertEquals("CharSequence c", this.signatureProvider.getSignature(dec));
        XExpression _get = block.getExpressions().get(1);
        final XIfExpression ifexpr = ((XIfExpression) _get);
        final XExpression then = ifexpr.getThen();
        XExpression _head_2 = IterableExtensions.<XExpression>head(((XBlockExpression) then).getExpressions());
        final XExpression target = ((XMemberFeatureCall) _head_2).getMemberCallTarget();
        Assert.assertEquals("String c", this.signatureProvider.getSignature(target));
        XExpression _get_1 = block.getExpressions().get(2);
        final XSwitchExpression switchExpr = ((XSwitchExpression) _get_1);
        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) 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 50 with XMemberFeatureCall

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

the class ErrorTest method testErrorModel_017.

@Test
public void testErrorModel_017() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("import static extension Throwables.*");
    _builder.newLine();
    _builder.append("import java.net.URI");
    _builder.newLine();
    _builder.newLine();
    _builder.append("class Throwables {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def static <T> T propagate(()=>T proc, (Exception)=>Exception handler) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("try {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("proc.apply");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("} catch(Exception e) {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("throw handler.apply(e)");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.append("class Client {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("valuri = [| new URI(\'\')].propagate [ new IllegalArgumentException(it) ]");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final XtendFile file = this.processWithoutException(_builder);
    final XtendTypeDeclaration client = IterableExtensions.<XtendTypeDeclaration>last(file.getXtendTypes());
    XtendMember _head = IterableExtensions.<XtendMember>head(client.getMembers());
    final XtendField field = ((XtendField) _head);
    XExpression _initialValue = field.getInitialValue();
    final XMemberFeatureCall initializer = ((XMemberFeatureCall) _initialValue);
    XExpression _head_1 = IterableExtensions.<XExpression>head(initializer.getMemberCallArguments());
    final XClosure closure = ((XClosure) _head_1);
    final JvmFormalParameter implicit = IterableExtensions.<JvmFormalParameter>head(closure.getImplicitFormalParameters());
    Assert.assertNotNull(implicit);
    final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(implicit);
    Assert.assertNotNull(resolvedTypes.getActualType(implicit));
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) XClosure(org.eclipse.xtext.xbase.XClosure) IResolvedTypes(org.eclipse.xtext.xbase.typesystem.IResolvedTypes) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XExpression(org.eclipse.xtext.xbase.XExpression) XtendField(org.eclipse.xtend.core.xtend.XtendField) Test(org.junit.Test)

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