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

Unified 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, 4 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer2dart/lib/src/driver.dart
diff --git a/pkg/analyzer2dart/lib/src/driver.dart b/pkg/analyzer2dart/lib/src/driver.dart
new file mode 100644
index 0000000000000000000000000000000000000000..001c4cab5078440b36520ee8a4e637d2e20f28db
--- /dev/null
+++ b/pkg/analyzer2dart/lib/src/driver.dart
@@ -0,0 +1,71 @@
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library analyzer2dart.driver;
+
+import 'package:analyzer/src/generated/element.dart';
+import 'package:analyzer/src/generated/engine.dart';
+import 'package:analyzer/src/generated/java_io.dart';
+import 'package:analyzer/src/generated/sdk_io.dart';
+import 'package:analyzer/src/generated/source_io.dart';
+
+import 'closed_world.dart';
+import 'tree_shaker.dart';
+
+/**
+ * Top level driver for Analyzer2Dart.
+ */
+class Driver {
+ AnalysisContext context;
+
+ Driver() : context = AnalysisEngine.instance.createAnalysisContext() {
+ // Set up the source factory.
+ // TODO(paulberry): do we want to use ExplicitPackageUriResolver?
+ List<UriResolver> uriResolvers = [
+ new FileUriResolver(),
+ new DartUriResolver(DirectoryBasedDartSdk.defaultSdk) /* ,
+ new PackageUriResolver(packagesDirectories) */
+ ];
+ context.sourceFactory = new SourceFactory(uriResolvers);
+ }
+
+ /**
+ * Compute the closed world that is reachable from an entry point.
+ */
+ ClosedWorld computeWorld(FunctionElement entryPointElement) {
+ TreeShaker treeShaker = new TreeShaker();
+ treeShaker.add(entryPointElement);
+ return treeShaker.shake(entryPointElement.context);
+ }
+
+ /**
+ * Given a source, resolve it and return its entry point.
+ */
+ FunctionElement resolveEntryPoint(Source source) {
+ // Get the library element associated with the source.
+ LibraryElement libraryElement = context.computeLibraryElement(source);
+
+ // Get the resolved AST for main
+ FunctionElement entryPointElement = libraryElement.entryPoint;
+ if (entryPointElement == null) {
+ throw new Exception('No main()!');
+ }
+ return entryPointElement;
+ }
+
+ /**
+ * Add the given file as the root of analysis, and return the corresponding
+ * source.
+ */
+ Source setRealRoot(String path) {
+ // Tell the analysis server about the root
+ ChangeSet changeSet = new ChangeSet();
+ JavaFile javaFile = new JavaFile(path);
+ Source source = new FileBasedSource.con1(javaFile);
+ changeSet.addedSources.add(source);
+ context.applyChanges(changeSet);
+ return source;
+ }
+}
+
« 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