if (DEBUG) {
System.out.println("addDefaultAnnotation: target=" + target + ", c=" + c + ", n=" + n);
}
ClassDescriptor classDesc = DescriptorFactory.instance().getClassDescriptorForDottedClassName(c);
ClassInfo xclass;
// Get the XClass (really a ClassInfo object)
try {
xclass = (ClassInfo) Global.getAnalysisCache().getClassAnalysis(XClass.class, classDesc);
} catch (MissingClassException e) {
// AnalysisContext.currentAnalysisContext().getLookupFailureCallback().reportMissingClass(e.getClassDescriptor());
return;
} catch (CheckedAnalysisException e) {
// AnalysisContext.logError("Error adding built-in nullness annotation",
// e);
return;
}
if (n == NullnessAnnotation.NONNULL && target == AnnotationDatabase.Target.PARAMETER) {
xclass.addAnnotation(new AnnotationValue(PARAMETERS_ARE_NONNULL_BY_DEFAULT));
return;
} else if (n == NullnessAnnotation.NONNULL && target == AnnotationDatabase.Target.METHOD) {
xclass.addAnnotation(new AnnotationValue(RETURN_VALUES_ARE_NONNULL_BY_DEFAULT));
return;
}
// Get the default annotation type
ClassDescriptor defaultAnnotationType;
if (target == AnnotationDatabase.Target.ANY) {
defaultAnnotationType = FindBugsDefaultAnnotations.DEFAULT_ANNOTATION;
} else if (target == AnnotationDatabase.Target.FIELD) {
defaultAnnotationType = FindBugsDefaultAnnotations.DEFAULT_ANNOTATION_FOR_FIELDS;
} else if (target == AnnotationDatabase.Target.METHOD) {
defaultAnnotationType = FindBugsDefaultAnnotations.DEFAULT_ANNOTATION_FOR_METHODS;
} else if (target == AnnotationDatabase.Target.PARAMETER) {
defaultAnnotationType = FindBugsDefaultAnnotations.DEFAULT_ANNOTATION_FOR_PARAMETERS;
} else {
throw new IllegalArgumentException("Unknown target for default annotation: " + target);
}
// Get the JSR-305 nullness annotation type
ClassDescriptor nullnessAnnotationType = getNullnessAnnotationClassDescriptor(n);
// Construct an AnnotationValue containing the default annotation
AnnotationValue annotationValue = new AnnotationValue(defaultAnnotationType);
AnnotationVisitor v = annotationValue.getAnnotationVisitor();
v.visit("value", Type.getObjectType(nullnessAnnotationType.getClassName()));
v.visitEnd();
if (DEBUG) {
System.out.println("Adding AnnotationValue " + annotationValue + " to class " + xclass);
}
// Destructively add the annotation to the ClassInfo object
xclass.addAnnotation(annotationValue);
}