Wow. I didn't realize how old that code was.
The analyzer package has never had a really clean interface, nor a clear separation between the public API and internal details. With the move to Dart 2 and the common front end, we're planning on correcting both of those.
We have started working on a new API for getting analysis information. The information itself - the AST and element models - might need to change a bit to better reflect Dart 2 syntax and semantics, but will probably remain largely unchanged. The first draft of the new API is available and functional, but I can't promise that it's stable at this point. Still, if you're comfortable with bleeding edge code, we'd love to get feedback based on actual experience.
If not, then you could use something like the code above, but with the caveat that it will soon become unsupported (where soon probably means in the next 3 - 6 months).
The example you pointed to consists of roughly two parts: checking the arguments (lines 23 - 33) and analyzing files (35 - 62). The new API would replace the second part without changing the visitor. As part of testing the implementation, I wrote a toy replacement for `dartanalyzer`, and here's what the analysis portion of it looks like:
1 Future<List<ErrorsResult>> analyzeFiles(ArgResults arguments) async {
2 ContextLocator locator =
3 new ContextLocator(resourceProvider: resourceProvider);
4 List<AnalysisContext> contexts = locator.locateContexts(arguments.rest);
5 List<ErrorsResult> results = <ErrorsResult>[];
6 for (AnalysisContext context in contexts) {
7 AnalysisSession session = context.currentSession;
8 for (String path in context.includedFiles()) {
9 results.add(await session.getErrors(path));
A translation of the example code would be a bit simpler because it only looks at one file, but for your first use case you'd want something closer to the code above.
What it does is take a list of files and directories (`arguments.rest`) and figure out the right way to split up analysis so that everything gets the right package resolution and the right analysis options (lines 2 - 4). It then iterates over all of the contexts (6), gets a session from each (7), and then iterates over all of the non-excluded files in that context (8). For each file it gets the errors associated with the file from the `session` (9). For your first use case you'd want to ask for the resolution results (`session.getResolvedAst(path)`) instead, and probably use a visitor to gather information from the returned result object's AST (`unit`).
The `ContextLocator` class is defined in `package:analyzer/dart/analysis/context_locator.dart`. The method `locateContexts` is probably going to be replaced by `locateRoots` and some way to create an `AnalysisContext` from a `ContextRoot`, but the general style is likely to remain.
Both methods should work fine with Flutter packages. In the new API you'd probably need to pass the path to the Flutter SDK to `locateContexts`, but that should be the only thing you need to do. (I'm hoping we can remove the need for that and have the right SDK automatically found.)