// Create the AnnotationExpr; it varies depending on how many
// member-value pairs we need to present
AnnotationExpr annotationExpression = null;
if (memberValuePairs.isEmpty()) {
annotationExpression = new MarkerAnnotationExpr(nameToUse);
}
else if (memberValuePairs.size() == 1
&& (memberValuePairs.get(0).getName() == null || "value"
.equals(memberValuePairs.get(0).getName()))) {
final Expression toUse = JavaParserUtils
.importExpressionIfRequired(
compilationUnitServices.getEnclosingTypeName(),
compilationUnitServices.getImports(),
memberValuePairs.get(0).getValue());
annotationExpression = new SingleMemberAnnotationExpr(nameToUse,
toUse);
}
else {
// We have a number of pairs being presented
annotationExpression = new NormalAnnotationExpr(nameToUse,
new ArrayList<MemberValuePair>());
}
// Add our AnnotationExpr to the actual annotations that will eventually
// be flushed through to the compilation unit
annotations.add(annotationExpression);
// Add member-value pairs to our AnnotationExpr
if (!memberValuePairs.isEmpty()) {
// Have to check here for cases where we need to change an existing
// MarkerAnnotationExpr to a NormalAnnotationExpr or
// SingleMemberAnnotationExpr
if (annotationExpression instanceof MarkerAnnotationExpr) {
final MarkerAnnotationExpr mae = (MarkerAnnotationExpr) annotationExpression;
annotations.remove(mae);
if (memberValuePairs.size() == 1
&& (memberValuePairs.get(0).getName() == null || "value"