Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Side by Side Diff: pkg/analyzer2dart/lib/src/driver.dart

Issue 511193002: Split analyzer2dart code into multiple source files (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/analyzer2dart/lib/src/closed_world.dart ('k') | pkg/analyzer2dart/lib/src/tree_shaker.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 library analyzer2dart.driver;
6
7 import 'package:analyzer/src/generated/element.dart';
8 import 'package:analyzer/src/generated/engine.dart';
9 import 'package:analyzer/src/generated/java_io.dart';
10 import 'package:analyzer/src/generated/sdk_io.dart';
11 import 'package:analyzer/src/generated/source_io.dart';
12
13 import 'closed_world.dart';
14 import 'tree_shaker.dart';
15
16 /**
17 * Top level driver for Analyzer2Dart.
18 */
19 class Driver {
20 AnalysisContext context;
21
22 Driver() : context = AnalysisEngine.instance.createAnalysisContext() {
23 // Set up the source factory.
24 // TODO(paulberry): do we want to use ExplicitPackageUriResolver?
25 List<UriResolver> uriResolvers = [
26 new FileUriResolver(),
27 new DartUriResolver(DirectoryBasedDartSdk.defaultSdk) /* ,
28 new PackageUriResolver(packagesDirectories) */
29 ];
30 context.sourceFactory = new SourceFactory(uriResolvers);
31 }
32
33 /**
34 * Compute the closed world that is reachable from an entry point.
35 */
36 ClosedWorld computeWorld(FunctionElement entryPointElement) {
37 TreeShaker treeShaker = new TreeShaker();
38 treeShaker.add(entryPointElement);
39 return treeShaker.shake(entryPointElement.context);
40 }
41
42 /**
43 * Given a source, resolve it and return its entry point.
44 */
45 FunctionElement resolveEntryPoint(Source source) {
46 // Get the library element associated with the source.
47 LibraryElement libraryElement = context.computeLibraryElement(source);
48
49 // Get the resolved AST for main
50 FunctionElement entryPointElement = libraryElement.entryPoint;
51 if (entryPointElement == null) {
52 throw new Exception('No main()!');
53 }
54 return entryPointElement;
55 }
56
57 /**
58 * Add the given file as the root of analysis, and return the corresponding
59 * source.
60 */
61 Source setRealRoot(String path) {
62 // Tell the analysis server about the root
63 ChangeSet changeSet = new ChangeSet();
64 JavaFile javaFile = new JavaFile(path);
65 Source source = new FileBasedSource.con1(javaFile);
66 changeSet.addedSources.add(source);
67 context.applyChanges(changeSet);
68 return source;
69 }
70 }
71
OLDNEW
« no previous file with comments | « pkg/analyzer2dart/lib/src/closed_world.dart ('k') | pkg/analyzer2dart/lib/src/tree_shaker.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698