private void tryAddOverrideAnnotation(final MethodDeclaration node) {
boolean foundOverride = false;
for (final Annotation annotation : node.getAnnotations()) {
final TypeReference annotationType = annotation.getType().getUserData(Keys.TYPE_REFERENCE);
if (StringUtilities.equals(annotationType.getInternalName(), OVERRIDE_ANNOTATION_NAME)) {
foundOverride = true;
break;
}
}
if (foundOverride) {
return;
}
final MethodDefinition method = node.getUserData(Keys.METHOD_DEFINITION);
if (method.isStatic() || method.isConstructor() || method.isTypeInitializer()) {
return;
}
final TypeDefinition declaringType = method.getDeclaringType();
if (declaringType.getCompilerMajorVersion() < CompilerTarget.JDK1_6.majorVersion) {
return;
}
final TypeReference annotationType = new MetadataParser(declaringType).parseTypeDescriptor(OVERRIDE_ANNOTATION_NAME);
final List<MethodReference> candidates = MetadataHelper.findMethods(
declaringType,
new Predicate<MethodReference>() {
@Override
public boolean test(final MethodReference reference) {
return StringUtilities.equals(reference.getName(), method.getName());
}
},
false,
true
);
for (final MethodReference candidate : candidates) {
if (MetadataHelper.isOverride(method, candidate)) {
final Annotation annotation = new Annotation();
if (_astBuilder != null) {
annotation.setType(_astBuilder.convertType(annotationType));
}
else {
annotation.setType(new SimpleType(annotationType.getSimpleName()));
}
node.getAnnotations().add(annotation);
break;
}