Search in sources :

Example 1 with OverrideCheckDetails

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

the class XtendValidator method doCheckFunctionOverrides.

protected void doCheckFunctionOverrides(EObject sourceElement, IResolvedOperation resolved, List<IResolvedOperation> allInherited) {
    boolean overrideProblems = false;
    List<IResolvedOperation> exceptionMismatch = null;
    for (IResolvedOperation inherited : allInherited) {
        if (inherited.getOverrideCheckResult().hasProblems()) {
            overrideProblems = true;
            EnumSet<OverrideCheckDetails> details = inherited.getOverrideCheckResult().getDetails();
            if (details.contains(OverrideCheckDetails.IS_FINAL)) {
                error("Attempt to override final method " + inherited.getSimpleSignature(), sourceElement, nameFeature(sourceElement), OVERRIDDEN_FINAL);
            } else if (details.contains(OverrideCheckDetails.REDUCED_VISIBILITY)) {
                error("Cannot reduce the visibility of the overridden method " + inherited.getSimpleSignature(), sourceElement, nameFeature(sourceElement), OVERRIDE_REDUCES_VISIBILITY);
            } else if (details.contains(OverrideCheckDetails.EXCEPTION_MISMATCH)) {
                if (exceptionMismatch == null)
                    exceptionMismatch = Lists.newArrayListWithCapacity(allInherited.size());
                exceptionMismatch.add(inherited);
            } else if (details.contains(OverrideCheckDetails.RETURN_MISMATCH)) {
                error("The return type is incompatible with " + inherited.getSimpleSignature(), sourceElement, returnTypeFeature(sourceElement), INCOMPATIBLE_RETURN_TYPE);
            } else if (details.contains(OverrideCheckDetails.SYNCHRONIZED_MISMATCH)) {
                warning("The overridden method is synchronized, the current one is not synchronized.", sourceElement, nameFeature(sourceElement), MISSING_SYNCHRONIZED);
            }
        }
    }
    if (exceptionMismatch != null) {
        createExceptionMismatchError(resolved, sourceElement, exceptionMismatch);
    }
    if (sourceElement instanceof XtendFunction) {
        XtendFunction function = (XtendFunction) sourceElement;
        if (!overrideProblems && !function.isOverride() && !function.isStatic()) {
            error("The method " + resolved.getSimpleSignature() + " of type " + getDeclaratorName(resolved) + " must use override keyword since it actually overrides a supertype method.", function, XTEND_FUNCTION__NAME, MISSING_OVERRIDE);
        }
        if (!overrideProblems && function.isOverride() && function.isStatic()) {
            for (IResolvedOperation inherited : allInherited) {
                error("The method " + resolved.getSimpleSignature() + " of type " + getDeclaratorName(resolved) + " shadows the method " + resolved.getSimpleSignature() + " of type " + getDeclaratorName(inherited) + ", but does not override it.", function, XTEND_FUNCTION__NAME, function.getModifiers().indexOf("override"), OBSOLETE_OVERRIDE);
            }
        }
        if (function.isOverride()) {
            for (XAnnotation anno : function.getAnnotations()) {
                if (anno != null && anno.getAnnotationType() != null && Override.class.getName().equals(anno.getAnnotationType().getIdentifier())) {
                    warning("Superfluous @Override annotation", anno, null, OBSOLETE_ANNOTATION_OVERRIDE);
                }
            }
        }
    }
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XAnnotation(org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation) IResolvedOperation(org.eclipse.xtext.xbase.typesystem.override.IResolvedOperation) OverrideCheckDetails(org.eclipse.xtext.xbase.typesystem.override.IOverrideCheckResult.OverrideCheckDetails)

Aggregations

XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)1 XAnnotation (org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation)1 OverrideCheckDetails (org.eclipse.xtext.xbase.typesystem.override.IOverrideCheckResult.OverrideCheckDetails)1 IResolvedOperation (org.eclipse.xtext.xbase.typesystem.override.IResolvedOperation)1