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

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

Issue 526823002: Use ResourceProvider instead of specialized setRealRoot/setFakeRoot. (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/bin/analyzer2dart.dart ('k') | pkg/analyzer2dart/test/driver_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library analyzer2dart.driver; 5 library analyzer2dart.driver;
6 6
7 import 'package:analyzer/file_system/file_system.dart';
7 import 'package:analyzer/src/generated/element.dart'; 8 import 'package:analyzer/src/generated/element.dart';
8 import 'package:analyzer/src/generated/engine.dart'; 9 import 'package:analyzer/src/generated/engine.dart';
9 import 'package:analyzer/src/generated/java_io.dart';
10 import 'package:analyzer/src/generated/sdk.dart'; 10 import 'package:analyzer/src/generated/sdk.dart';
11 import 'package:analyzer/src/generated/source_io.dart'; 11 import 'package:analyzer/src/generated/source_io.dart';
12 12
13 import 'closed_world.dart'; 13 import 'closed_world.dart';
14 import 'tree_shaker.dart'; 14 import 'tree_shaker.dart';
15 15
16 /** 16 /**
17 * Top level driver for Analyzer2Dart. 17 * Top level driver for Analyzer2Dart.
18 */ 18 */
19 class Driver { 19 class Driver {
20 AnalysisContext context; 20 final ResourceProvider resourceProvider;
21 final AnalysisContext context;
21 22
22 Driver(DartSdk sdk) : context = AnalysisEngine.instance.createAnalysisContext( ) { 23 Driver(this.resourceProvider, DartSdk sdk)
24 : context = AnalysisEngine.instance.createAnalysisContext() {
23 // Set up the source factory. 25 // Set up the source factory.
24 // TODO(paulberry): do we want to use ExplicitPackageUriResolver? 26 // TODO(paulberry): do we want to use ExplicitPackageUriResolver?
25 List<UriResolver> uriResolvers = [ 27 List<UriResolver> uriResolvers = [
26 new FileUriResolver(), 28 new FileUriResolver(),
27 new DartUriResolver(sdk) /* , 29 new DartUriResolver(sdk) /* ,
28 new PackageUriResolver(packagesDirectories) */ 30 new PackageUriResolver(packagesDirectories) */
29 ]; 31 ];
30 context.sourceFactory = new SourceFactory(uriResolvers); 32 context.sourceFactory = new SourceFactory(uriResolvers);
31 } 33 }
32 34
(...skipping 18 matching lines...) Expand all
51 if (entryPointElement == null) { 53 if (entryPointElement == null) {
52 throw new Exception('No main()!'); 54 throw new Exception('No main()!');
53 } 55 }
54 return entryPointElement; 56 return entryPointElement;
55 } 57 }
56 58
57 /** 59 /**
58 * Add the given file as the root of analysis, and return the corresponding 60 * Add the given file as the root of analysis, and return the corresponding
59 * source. 61 * source.
60 */ 62 */
61 Source setRealRoot(String path) { 63 Source setRoot(String path) {
62 // Tell the analysis server about the root 64 File file = resourceProvider.getResource(path);
65 Source source = file.createSource();
66 // add the Source
63 ChangeSet changeSet = new ChangeSet(); 67 ChangeSet changeSet = new ChangeSet();
64 JavaFile javaFile = new JavaFile(path);
65 Source source = new FileBasedSource.con1(javaFile);
66 changeSet.addedSource(source); 68 changeSet.addedSource(source);
67 context.applyChanges(changeSet); 69 context.applyChanges(changeSet);
68 return source; 70 // return the Source
69 }
70
71 /**
72 * Add the given file contents as the root of analysis. For unit testing.
73 */
74 Source setFakeRoot(String contents) {
75 String path = 'root.dart';
76 // Tell the analysis server about the root
77 ChangeSet changeSet = new ChangeSet();
78 JavaFile javaFile = new JavaFile(path);
79 Source source = new FileBasedSource.con1(javaFile);
80 changeSet.addedSource(source);
81 changeSet.changedContent(source, contents);
82 context.applyChanges(changeSet);
83 return source; 71 return source;
84 } 72 }
85 } 73 }
86
OLDNEW
« no previous file with comments | « pkg/analyzer2dart/bin/analyzer2dart.dart ('k') | pkg/analyzer2dart/test/driver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698