### Question:
AnnotationUtils { @SuppressWarnings("unchecked") public static String addXmlRootAnnotation(final String source, final String name) { final CompilationUnit unit = JavaSourceUtils.getCompilationUnit(source); final AST ast = unit.getAST(); final TypeDeclaration classType = (TypeDeclaration) unit.types().get(0); final NormalAnnotation xmlRootAnnotation = ast.newNormalAnnotation(); xmlRootAnnotation.setTypeName(ast.newName(XmlRootElement.class.getSimpleName())); final MemberValuePair generatedMemberValue = ast.newMemberValuePair(); generatedMemberValue.setName(ast.newSimpleName("name")); final StringLiteral internalNameLiteral = ast.newStringLiteral(); internalNameLiteral.setLiteralValue(name); generatedMemberValue.setValue(internalNameLiteral); xmlRootAnnotation.values().add(generatedMemberValue); JavaSourceUtils.addAnnotation(classType, xmlRootAnnotation); JavaSourceUtils.addImport(unit, XmlRootElement.class.getName()); return JavaSourceUtils.rewrite(unit, ast); } private  AnnotationUtils(); @SuppressWarnings("unchecked") static String addXmlRootAnnotation(final String source, final String name); static String addXmlAdaptorAnnotation(final String source, final String returnType, final AdapterWrapper wrapper); static String addXmlElementAnnotation(final String source); static String addXmlAccessNoneAnnotation(final String source); static T getClassAnnotation(final Class<?> clazz, final Class<T> annotationClass); static Collection<Field> getAnnotatedFields(final Class<?> clazz, final Class<? extends Annotation> annotationClass); @SuppressWarnings({"unchecked"}) static Class<T> findClass(final String name); static Collection<Field> getClassFields(Class<?> clazz); static Collection<Method> getMethods(Class<?> clazz); static String addKnownAdapters(final String source); static final Set<String> KNOWN_XML_TYPES; }### Answer:
@Test public void testXmlRootAnnotation() throws Exception { final String javaFile = GlobalUtils.readStreamAsText(getClass().getResourceAsStream("/AnnotationTestClass.txt")); assertNotNull("Expected to find /AnnotationTestClass.txt file", javaFile); String annotated = AnnotationUtils.addXmlRootAnnotation(javaFile, "testdocument"); int nrOfItems = StringUtils.countMatches(annotated, XmlRootElement.class.getName()); assertEquals(1, nrOfItems); annotated = AnnotationUtils.addXmlRootAnnotation(javaFile, "testdocument"); nrOfItems = StringUtils.countMatches(annotated, XmlRootElement.class.getName()); assertEquals(1, nrOfItems); nrOfItems = StringUtils.countMatches(annotated, "XmlRootElement"); assertEquals(2, nrOfItems); }