// Create an AST containing an annotation. Document doc = new Document("class X {\n@Anno()\npublic void action() {}\n"); ASTParser parser = ASTParser.newParser(AST.JLS3); parser.setSource(doc.get().toCharArray()); CompilationUnit cu = (CompilationUnit) parser.createAST(null); cu.recordModifications(); AST ast = cu.getAST(); // Create a member value pair to add to the annotation. MemberValuePair pair = ast.newMemberValuePair(); pair.setName(ast.newSimpleName("value")); StringLiteral value = ast.newStringLiteral(); value.setLiteralValue("string"); pair.setValue(value); // Add the member value pair to the annotation. TypeDeclaration type = (TypeDeclaration) cu.types().get(0); MethodDeclaration method = type.getMethods()[0]; NormalAnnotation anno = (NormalAnnotation) method.modifiers().get(0); anno.values().add(pair); // Fails with a CoreException regarding end of file cu.rewrite(doc, null);