Search in sources :

Example 61 with XAbstractFeatureCall

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

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

the class CreateMemberQuickfixes method getReceiverType.

/* @Nullable */
protected LightweightTypeReference getReceiverType(XAbstractFeatureCall featureCall) {
    XExpression actualReceiver = featureCall.getActualReceiver();
    ITypeReferenceOwner owner = new StandardTypeReferenceOwner(services, featureCall);
    if (actualReceiver == null) {
        JvmDeclaredType callersType = getCallersType(featureCall);
        if (callersType != null)
            return owner.newParameterizedTypeReference(callersType);
    } else if (actualReceiver instanceof XAbstractFeatureCall && ((XAbstractFeatureCall) actualReceiver).isTypeLiteral()) {
        JvmType type = (JvmType) ((XAbstractFeatureCall) actualReceiver).getFeature();
        ParameterizedTypeReference reference = owner.newParameterizedTypeReference(type);
        return reference;
    } else {
        LightweightTypeReference typeRef = typeResolver.resolveTypes(featureCall).getActualType(actualReceiver);
        if (typeRef != null && typeRef.getType() instanceof JvmDeclaredType)
            return typeRef;
    }
    return null;
}
Also used : LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) ParameterizedTypeReference(org.eclipse.xtext.xbase.typesystem.references.ParameterizedTypeReference) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) XExpression(org.eclipse.xtext.xbase.XExpression) JvmType(org.eclipse.xtext.common.types.JvmType) ITypeReferenceOwner(org.eclipse.xtext.xbase.typesystem.references.ITypeReferenceOwner) StandardTypeReferenceOwner(org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall)

Example 63 with XAbstractFeatureCall

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

the class XtendHoverGenericsResolverTest method testGenerics_1.

@Test
public void testGenerics_1() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package testPackage");
        _builder.newLine();
        _builder.append("class Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def bar(){");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("newArrayList(\"sd\").something");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def <T> T something(Iterable<T> iterable)");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet());
        final Iterable<XtendClass> clazz = Iterables.<XtendClass>filter(xtendFile.getXtendTypes(), XtendClass.class);
        XtendMember _get = IterableExtensions.<XtendClass>head(clazz).getMembers().get(0);
        final XtendFunction function = ((XtendFunction) _get);
        XExpression _expression = function.getExpression();
        final XBlockExpression expression = ((XBlockExpression) _expression);
        XExpression _get_1 = expression.getExpressions().get(0);
        final XAbstractFeatureCall call = ((XAbstractFeatureCall) _get_1);
        final String resolvedSignature = this.signatureProvider.getSignature(call);
        Assert.assertEquals("<String> String Foo.something(Iterable<String> iterable)", resolvedSignature);
    } 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) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XExpression(org.eclipse.xtext.xbase.XExpression) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) Test(org.junit.Test)

Example 64 with XAbstractFeatureCall

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

the class Oven method fireproof.

public void fireproof(final String input) throws Exception {
    try {
        final EObject file = this._parseHelper.parse(input);
        final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(file);
        Assert.assertNotNull(resolvedTypes);
        if ((file != null)) {
            Iterable<EObject> _iterable = IteratorExtensions.<EObject>toIterable(file.eAllContents());
            for (final EObject content : _iterable) {
                boolean _matched = false;
                if (content instanceof XAbstractFeatureCall) {
                    _matched = true;
                    this.assertExpressionTypeIsResolved(((XExpression) content), resolvedTypes);
                    XExpression _implicitReceiver = ((XAbstractFeatureCall) content).getImplicitReceiver();
                    boolean _tripleNotEquals = (_implicitReceiver != null);
                    if (_tripleNotEquals) {
                        this.assertExpressionTypeIsResolved(((XAbstractFeatureCall) content).getImplicitReceiver(), resolvedTypes);
                    }
                    XExpression _implicitFirstArgument = ((XAbstractFeatureCall) content).getImplicitFirstArgument();
                    boolean _tripleNotEquals_1 = (_implicitFirstArgument != null);
                    if (_tripleNotEquals_1) {
                        this.assertExpressionTypeIsResolved(((XAbstractFeatureCall) content).getImplicitFirstArgument(), resolvedTypes);
                    }
                }
                if (!_matched) {
                    if (content instanceof XClosure) {
                        _matched = true;
                        this.assertExpressionTypeIsResolved(((XExpression) content), resolvedTypes);
                        final Consumer<JvmFormalParameter> _function = (JvmFormalParameter it) -> {
                            this.assertIdentifiableTypeIsResolved(it, resolvedTypes);
                        };
                        ((XClosure) content).getImplicitFormalParameters().forEach(_function);
                    }
                }
                if (!_matched) {
                    if (content instanceof XExpression) {
                        _matched = true;
                        this.assertExpressionTypeIsResolved(((XExpression) content), resolvedTypes);
                    }
                }
                if (!_matched) {
                    if (content instanceof JvmIdentifiableElement) {
                        _matched = true;
                        this.assertIdentifiableTypeIsResolved(((JvmIdentifiableElement) content), resolvedTypes);
                    }
                }
            }
        }
    } catch (final Throwable _t) {
        if (_t instanceof Throwable) {
            final Throwable e = (Throwable) _t;
            String _message = e.getMessage();
            final ComparisonFailure error = new ComparisonFailure(_message, input, "");
            error.setStackTrace(e.getStackTrace());
            throw error;
        } else {
            throw Exceptions.sneakyThrow(_t);
        }
    }
}
Also used : JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) IResolvedTypes(org.eclipse.xtext.xbase.typesystem.IResolvedTypes) XClosure(org.eclipse.xtext.xbase.XClosure) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) ComparisonFailure(org.junit.ComparisonFailure) EObject(org.eclipse.emf.ecore.EObject) XExpression(org.eclipse.xtext.xbase.XExpression)

Example 65 with XAbstractFeatureCall

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

the class Oven method assertExpressionTypeIsResolved.

public void assertExpressionTypeIsResolved(final XExpression expression, final IResolvedTypes types) {
    try {
        final Object internalTypes = this._reflectExtensions.invoke(types, "delegate");
        TypeData _switchResult = null;
        boolean _matched = false;
        if (internalTypes instanceof CompoundReentrantTypeResolver) {
            _matched = true;
            TypeData _xblockexpression = null;
            {
                final Method method = CompoundReentrantTypeResolver.class.getDeclaredMethod("getDelegate", XExpression.class);
                method.setAccessible(true);
                final Object delegate = method.invoke(internalTypes, expression);
                TypeData _xifexpression = null;
                if ((delegate instanceof RootResolvedTypes)) {
                    Object _invoke = this._reflectExtensions.invoke(delegate, "getTypeData", expression, Boolean.FALSE);
                    _xifexpression = ((TypeData) _invoke);
                }
                _xblockexpression = _xifexpression;
            }
            _switchResult = _xblockexpression;
        }
        if (!_matched) {
            Object _invoke = this._reflectExtensions.invoke(internalTypes, "getTypeData", expression, Boolean.FALSE);
            _switchResult = ((TypeData) _invoke);
        }
        final TypeData type = _switchResult;
        String _string = expression.toString();
        String _plus = ("Type is not resolved. Expression: " + _string);
        boolean _xifexpression = false;
        if ((expression instanceof XAbstractFeatureCall)) {
            _xifexpression = (((XAbstractFeatureCall) expression).isPackageFragment() || (type != null));
        } else {
            _xifexpression = (type != null);
        }
        Assert.assertTrue(_plus, _xifexpression);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : RootResolvedTypes(org.eclipse.xtext.xbase.typesystem.internal.RootResolvedTypes) TypeData(org.eclipse.xtext.xbase.typesystem.internal.TypeData) CompoundReentrantTypeResolver(org.eclipse.xtext.xbase.typesystem.internal.CompoundReentrantTypeResolver) EObject(org.eclipse.emf.ecore.EObject) XExpression(org.eclipse.xtext.xbase.XExpression) Method(java.lang.reflect.Method) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall)

Aggregations

XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)122 Test (org.junit.Test)105 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)104 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)42 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)23 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)21 XExpression (org.eclipse.xtext.xbase.XExpression)17 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)11 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)9 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)8 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)6 EObject (org.eclipse.emf.ecore.EObject)5 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)5 XMemberFeatureCall (org.eclipse.xtext.xbase.XMemberFeatureCall)4 IFeatureLinkingCandidate (org.eclipse.xtext.xbase.typesystem.computation.IFeatureLinkingCandidate)4 Resource (org.eclipse.emf.ecore.resource.Resource)3 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)3 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)3 AbstractDiagnostic (org.eclipse.xtext.diagnostics.AbstractDiagnostic)3 XClosure (org.eclipse.xtext.xbase.XClosure)3