Search in sources :

Example 1 with BottomResolvedOperation

use of org.eclipse.xtext.xbase.typesystem.override.BottomResolvedOperation in project xtext-xtend by eclipse.

the class XtendReentrantTypeResolver method getReturnTypeOfOverriddenOperation.

@Override
protected LightweightTypeReference getReturnTypeOfOverriddenOperation(JvmOperation operation, ResolvedTypes resolvedTypes, IFeatureScopeSession session) {
    if (operation.getVisibility() == JvmVisibility.PRIVATE)
        return null;
    if (InferredTypeIndicator.isInferred(operation.getReturnType())) {
        LightweightTypeReference declaringType = resolvedTypes.getActualType(operation.getDeclaringType());
        if (declaringType == null) {
            throw new IllegalStateException("Cannot determine declaring type of operation: " + operation);
        }
        BottomResolvedOperation resolvedOperation = new BottomResolvedOperation(operation, declaringType, overrideTester);
        List<IResolvedOperation> overriddenMethods = resolvedOperation.getOverriddenAndImplementedMethods();
        if (overriddenMethods.isEmpty())
            return null;
        IResolvedOperation overriddenMethod = overriddenMethods.get(0);
        JvmOperation declaration = overriddenMethod.getDeclaration();
        XExpression inferredFrom = getInferredFrom(declaration.getReturnType());
        // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=439535
        if (inferredFrom != null && (inferredFrom == getInferredFrom(operation.getReturnType()) || isHandled(inferredFrom))) {
            return null;
        }
        LightweightTypeReference result = overriddenMethod.getResolvedReturnType();
        return result;
    }
    return null;
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) XExpression(org.eclipse.xtext.xbase.XExpression) BottomResolvedOperation(org.eclipse.xtext.xbase.typesystem.override.BottomResolvedOperation) IResolvedOperation(org.eclipse.xtext.xbase.typesystem.override.IResolvedOperation)

Example 2 with BottomResolvedOperation

use of org.eclipse.xtext.xbase.typesystem.override.BottomResolvedOperation in project xtext-xtend by eclipse.

the class SuperMemberImplementorTest method checkOverrideMethodCode.

protected void checkOverrideMethodCode(String operationName, String overrideCode) {
    StringBuilderBasedAppendable appendable = new StringBuilderBasedAppendable();
    LightweightTypeReference contextType = getContextType();
    IResolvedOperation resolvedOperation = new BottomResolvedOperation((JvmOperation) findExecutable(implementedInterface, operationName), contextType, new OverrideTester());
    implementor.appendOverrideFunction(xtendClass, resolvedOperation, appendable);
    String code = appendable.toString();
    if (!equalsIgnoreWhitespace(overrideCode, code))
        assertEquals(overrideCode, code);
}
Also used : LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) StringBuilderBasedAppendable(org.eclipse.xtext.xbase.compiler.StringBuilderBasedAppendable) OverrideTester(org.eclipse.xtext.xbase.typesystem.override.OverrideTester) IResolvedOperation(org.eclipse.xtext.xbase.typesystem.override.IResolvedOperation) BottomResolvedOperation(org.eclipse.xtext.xbase.typesystem.override.BottomResolvedOperation)

Example 3 with BottomResolvedOperation

use of org.eclipse.xtext.xbase.typesystem.override.BottomResolvedOperation in project xtext-xtend by eclipse.

the class AbstractOverloadedInstanceMethodTest method linksTo.

protected void linksTo(final String invocation, final String method) {
    try {
        final XtendFile file = this.file(this.inMethodBody(invocation), false);
        XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
        final XtendClass c = ((XtendClass) _head);
        XtendMember _head_1 = IterableExtensions.<XtendMember>head(c.getMembers());
        final XtendFunction m = ((XtendFunction) _head_1);
        XExpression _expression = m.getExpression();
        final XBlockExpression body = ((XBlockExpression) _expression);
        XExpression _last = IterableExtensions.<XExpression>last(body.getExpressions());
        final XAbstractFeatureCall featureCall = ((XAbstractFeatureCall) _last);
        JvmIdentifiableElement _feature = featureCall.getFeature();
        final JvmOperation operation = ((JvmOperation) _feature);
        final StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(this.services, file);
        final ParameterizedTypeReference declaration = owner.newParameterizedTypeReference(operation.getDeclaringType());
        final BottomResolvedOperation resolved = new BottomResolvedOperation(operation, declaration, this.overrideTester);
        Assert.assertEquals(method, resolved.getSimpleSignature());
        Assert.assertTrue(IterableExtensions.join(file.eResource().getErrors(), "\n"), file.eResource().getErrors().isEmpty());
        Assert.assertNotNull(featureCall.getImplicitReceiver());
        Assert.assertNull(featureCall.getImplicitFirstArgument());
    } 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) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) ParameterizedTypeReference(org.eclipse.xtext.xbase.typesystem.references.ParameterizedTypeReference) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XExpression(org.eclipse.xtext.xbase.XExpression) BottomResolvedOperation(org.eclipse.xtext.xbase.typesystem.override.BottomResolvedOperation) StandardTypeReferenceOwner(org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner)

Example 4 with BottomResolvedOperation

use of org.eclipse.xtext.xbase.typesystem.override.BottomResolvedOperation in project xtext-xtend by eclipse.

the class AbstractOverloadedStaticMethodTest method linksTo.

protected void linksTo(final String invocation, final String method) {
    try {
        final XtendFile file = this.file(this.inMethodBody(invocation), false);
        XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
        final XtendClass c = ((XtendClass) _head);
        XtendMember _head_1 = IterableExtensions.<XtendMember>head(c.getMembers());
        final XtendFunction m = ((XtendFunction) _head_1);
        XExpression _expression = m.getExpression();
        final XBlockExpression body = ((XBlockExpression) _expression);
        XExpression _last = IterableExtensions.<XExpression>last(body.getExpressions());
        final XAbstractFeatureCall featureCall = ((XAbstractFeatureCall) _last);
        JvmIdentifiableElement _feature = featureCall.getFeature();
        final JvmOperation operation = ((JvmOperation) _feature);
        final StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(this.services, file);
        final ParameterizedTypeReference declaration = owner.newParameterizedTypeReference(operation.getDeclaringType());
        final BottomResolvedOperation resolved = new BottomResolvedOperation(operation, declaration, this.overrideTester);
        Assert.assertEquals(method, resolved.getSimpleSignature());
        Assert.assertTrue(IterableExtensions.join(file.eResource().getErrors(), "\n"), file.eResource().getErrors().isEmpty());
        Assert.assertNull(featureCall.getImplicitReceiver());
        Assert.assertNull(featureCall.getImplicitFirstArgument());
    } 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) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) ParameterizedTypeReference(org.eclipse.xtext.xbase.typesystem.references.ParameterizedTypeReference) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XExpression(org.eclipse.xtext.xbase.XExpression) BottomResolvedOperation(org.eclipse.xtext.xbase.typesystem.override.BottomResolvedOperation) StandardTypeReferenceOwner(org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner)

Aggregations

BottomResolvedOperation (org.eclipse.xtext.xbase.typesystem.override.BottomResolvedOperation)4 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)3 XExpression (org.eclipse.xtext.xbase.XExpression)3 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)2 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)2 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)2 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)2 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)2 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)2 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)2 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)2 IResolvedOperation (org.eclipse.xtext.xbase.typesystem.override.IResolvedOperation)2 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)2 ParameterizedTypeReference (org.eclipse.xtext.xbase.typesystem.references.ParameterizedTypeReference)2 StandardTypeReferenceOwner (org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner)2 StringBuilderBasedAppendable (org.eclipse.xtext.xbase.compiler.StringBuilderBasedAppendable)1 OverrideTester (org.eclipse.xtext.xbase.typesystem.override.OverrideTester)1