}
}
public static void recordClassAnnotations(Class<?> clazz, AnnotationsAttribute annotations) {
// no annotations
ChangedClassImpl changedClass = CurrentChangedClasses.get(clazz);
if (annotations == null) {
Annotation[] ans = new Annotation[0];
classAnnotations.put(clazz, ans);
classAnnotationsByType.put(clazz, Collections.EMPTY_MAP);
for(Annotation annotation : clazz.getDeclaredAnnotations()) {
changedClass.changeClassAnnotation(new ChangedAnnotationImpl(null, annotation, ChangeType.REMOVE, changedClass, annotation.annotationType()));
}
} else {
final Class<?> pclass = createAnnotationsProxy(clazz.getClassLoader(), annotations);
classAnnotations.put(clazz, pclass.getAnnotations());
Map<Class<? extends Annotation>, Annotation> anVals = new HashMap<Class<? extends Annotation>, Annotation>();
classAnnotationsByType.put(clazz, anVals);
int count = 0;
for (Annotation a : pclass.getAnnotations()) {
anVals.put(a.annotationType(), a);
count++;
}
final Set<Class<? extends Annotation>> newAnnotations = new HashSet<Class<? extends Annotation>>(anVals.keySet());
for(Annotation annotation : clazz.getDeclaredAnnotations()) {
final Annotation newAnnotation = anVals.get(annotation.annotationType());
if(newAnnotation == null) {
//the annotation was removed
changedClass.changeClassAnnotation(new ChangedAnnotationImpl(null, annotation, ChangeType.REMOVE, changedClass, annotation.annotationType()));
} else if(!newAnnotation.equals(annotation)) {
//same annotation, but it has been modified
changedClass.changeClassAnnotation(new ChangedAnnotationImpl(newAnnotation, annotation, ChangeType.MODIFY, changedClass, annotation.annotationType()));
}
newAnnotations.remove(annotation.annotationType());
}
for(final Class<? extends Annotation> newAnnotationType : newAnnotations) {
final Annotation newAnnotation = anVals.get(newAnnotationType);
changedClass.changeClassAnnotation(new ChangedAnnotationImpl(newAnnotation, null, ChangeType.ADD, changedClass, newAnnotationType));
}
}
}