Search in sources :

Example 11 with XExpression

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

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

the class XtendValidator method checkDefaultSuperConstructor.

@Check
public void checkDefaultSuperConstructor(XtendClass xtendClass) {
    JvmGenericType inferredType = associations.getInferredType(xtendClass);
    if (inferredType == null)
        return;
    Iterable<JvmConstructor> constructors = filter(inferredType.getMembers(), JvmConstructor.class);
    if (inferredType.getExtendedClass() != null) {
        JvmType superType = inferredType.getExtendedClass().getType();
        if (superType instanceof JvmGenericType) {
            Iterable<JvmConstructor> superConstructors = ((JvmGenericType) superType).getDeclaredConstructors();
            for (JvmConstructor superConstructor : superConstructors) {
                if (superConstructor.getParameters().isEmpty())
                    // there is a default super constructor. nothing more to check
                    return;
            }
            if (size(constructors) == 1 && typeExtensions.isSingleSyntheticDefaultConstructor(constructors.iterator().next())) {
                List<String> issueData = newArrayList();
                for (JvmConstructor superConstructor : superConstructors) {
                    issueData.add(EcoreUtil.getURI(superConstructor).toString());
                    issueData.add(doGetReadableSignature(xtendClass.getName(), superConstructor.getParameters()));
                }
                error("No default constructor in super type " + superType.getSimpleName() + "." + xtendClass.getName() + " must define an explicit constructor.", xtendClass, XTEND_TYPE_DECLARATION__NAME, MISSING_CONSTRUCTOR, toArray(issueData, String.class));
            } else {
                for (JvmConstructor constructor : constructors) {
                    XExpression expression = containerProvider.getAssociatedExpression(constructor);
                    if (expression instanceof XBlockExpression) {
                        List<XExpression> expressions = ((XBlockExpression) expression).getExpressions();
                        if (expressions.isEmpty() || !isDelegateConstructorCall(expressions.get(0))) {
                            EObject source = associations.getPrimarySourceElement(constructor);
                            error("No default constructor in super type " + superType.getSimpleName() + ". Another constructor must be invoked explicitly.", source, null, MUST_INVOKE_SUPER_CONSTRUCTOR);
                        }
                    }
                }
            }
        }
    }
}
Also used : XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) EObject(org.eclipse.emf.ecore.EObject) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) XExpression(org.eclipse.xtext.xbase.XExpression) JvmType(org.eclipse.xtext.common.types.JvmType) RichString(org.eclipse.xtend.core.xtend.RichString) Check(org.eclipse.xtext.validation.Check)

Example 13 with XExpression

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

the class XtendValidator method checkImplicitReturn.

@Check
protected void checkImplicitReturn(final XtendFunction method) {
    if (isIgnored(IMPLICIT_RETURN))
        return;
    JvmOperation jvmOperation = associations.getDirectlyInferredOperation(method);
    IResolvedTypes types = batchTypeResolver.resolveTypes(method);
    if (jvmOperation != null && types.getActualType(jvmOperation).isPrimitiveVoid())
        return;
    implicitReturnFinder.findImplicitReturns(method.getExpression(), new Acceptor() {

        @Override
        public void accept(XExpression implicitReturn) {
            if (method.getExpression() == implicitReturn)
                return;
            addIssue("Implicit return", implicitReturn, IMPLICIT_RETURN);
        }
    });
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) ValidationMessageAcceptor(org.eclipse.xtext.validation.ValidationMessageAcceptor) Acceptor(org.eclipse.xtext.xbase.validation.ImplicitReturnFinder.Acceptor) IResolvedTypes(org.eclipse.xtext.xbase.typesystem.IResolvedTypes) XExpression(org.eclipse.xtext.xbase.XExpression) Check(org.eclipse.xtext.validation.Check)

Example 14 with XExpression

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

the class XtendHighlightingCalculator method highlightElement.

protected void highlightElement(XtendFunction function, IHighlightedPositionAcceptor acceptor, CancelIndicator cancelIndicator) {
    highlightFeature(acceptor, function, XtendPackage.Literals.XTEND_FUNCTION__NAME, METHOD);
    XExpression rootExpression = function.getExpression();
    highlightRichStrings(rootExpression, acceptor);
    CreateExtensionInfo createExtensionInfo = function.getCreateExtensionInfo();
    if (createExtensionInfo != null) {
        highlightRichStrings(createExtensionInfo.getCreateExpression(), acceptor);
    }
}
Also used : XExpression(org.eclipse.xtext.xbase.XExpression) CreateExtensionInfo(org.eclipse.xtend.core.xtend.CreateExtensionInfo)

Example 15 with XExpression

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

the class XtendHighlightingCalculator method highlightElement.

protected void highlightElement(XtendField field, IHighlightedPositionAcceptor acceptor, CancelIndicator cancelIndicator) {
    highlightFeature(acceptor, field, XtendPackage.Literals.XTEND_FIELD__NAME, FIELD);
    if (field.isStatic()) {
        highlightFeature(acceptor, field, XtendPackage.Literals.XTEND_FIELD__NAME, STATIC_FIELD);
        if (field.isFinal()) {
            highlightFeature(acceptor, field, XtendPackage.Literals.XTEND_FIELD__NAME, STATIC_FINAL_FIELD);
        }
    }
    XExpression initializer = field.getInitialValue();
    highlightRichStrings(initializer, acceptor);
}
Also used : XExpression(org.eclipse.xtext.xbase.XExpression)

Aggregations

XExpression (org.eclipse.xtext.xbase.XExpression)215 Test (org.junit.Test)133 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)96 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)84 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)82 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)82 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)80 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)63 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)36 EObject (org.eclipse.emf.ecore.EObject)28 IFeatureCallArguments (org.eclipse.xtext.xbase.typesystem.arguments.IFeatureCallArguments)28 XtendField (org.eclipse.xtend.core.xtend.XtendField)23 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)23 XNumberLiteral (org.eclipse.xtext.xbase.XNumberLiteral)21 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)20 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)18 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)17 XStringLiteral (org.eclipse.xtext.xbase.XStringLiteral)17 XClosure (org.eclipse.xtext.xbase.XClosure)16 IFeatureCallArgumentSlot (org.eclipse.xtext.xbase.typesystem.arguments.IFeatureCallArgumentSlot)16