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);
}
}
}
}
}
Aggregations