BJ is correct. Here is a tutorial on writing an annotation processor:
Typically, you write an annotation processor that processes elements tagged with a certain annotation. The annotation processor's config will specify which annotations it is interested in, and the compiler framework will invoke your processor whenever it comes across an annotation that matches.
If you want to access all of the source, from memory you can specify a wildcard in your annotation processor's config so that it will be invoked for any annotated element. You can also get access to any AST element by walking the hierarchy. It might be a little bit clunky if your purpose is not directly to handle annotated elements, but rather more general source-code parsing - however, I think you should still be able to achieve what you want.
Another alternative is to use Eclipse's AST parsing library, which might be useful in an Eclipse context (if you're not in an Eclipse context, it may pull in a few too many extra dependencies for your liking). The main entry point is org.eclipse.jdt.core.dom.ASTParser. There is an example of its use in one of the Bnd tests:
https://github.com/bndtools/bnd/blob/master/bndtools.core/test/org/bndtools/core/editors/ImportPackageQuickFixProcessorTest.java (see the setupAST() method). From memory, the Eclipse AST is read-write too, which might be useful for you if you want to programmaticly edit the source (Eclipse uses this library internally for all of its code quick-fixes).
Hope this helps.
Blessings,
Fr Jeremy Krieg