ClassNode omr = oldMethod.getReturnType();
boolean equalReturnType = mr.equals(omr);
ClassNode testmr = correctToGenericsSpec(genericsSpec, omr);
if (!isAssignable(mr, testmr)) {
throw new RuntimeParserException(
"The return type of " +
overridingMethod.getTypeDescriptor() +
" in " + overridingMethod.getDeclaringClass().getName() +
" is incompatible with " + testmr.getName() +
" in " + oldMethod.getDeclaringClass().getName(),
overridingMethod);
}
if (equalReturnType && normalEqualParameters) return null;
if ((oldMethod.getModifiers() & ACC_FINAL) != 0) {
throw new RuntimeParserException(
"Cannot override final method " +
oldMethod.getTypeDescriptor() +
" in " + oldMethod.getDeclaringClass().getName(),
overridingMethod);
}
if (oldMethod.isStatic() != overridingMethod.isStatic()) {
throw new RuntimeParserException(
"Cannot override method " +
oldMethod.getTypeDescriptor() +
" in " + oldMethod.getDeclaringClass().getName() +
" with disparate static modifier",
overridingMethod);
}
if (!equalReturnType) {
boolean oldM = ClassHelper.isPrimitiveType(oldMethod.getReturnType());
boolean newM = ClassHelper.isPrimitiveType(overridingMethod.getReturnType());
if (oldM || newM) {
String message="";
if (oldM && newM) {
message = " with old and new method having different primitive return types";
} else if (newM) {
message = " with new method having a primitive return type and old method not";
} else /* oldM */ {
message = " with old method having a primitive return type and new method not";
}
throw new RuntimeParserException(
"Cannot override method " +
oldMethod.getTypeDescriptor() +
" in " + oldMethod.getDeclaringClass().getName() +
message,
overridingMethod);