5
5
import 'dart:async' ;
6
6
import 'dart:io' ;
7
7
8
- import 'package:analyzer/dart/element/element.dart' ;
9
8
import 'package:analyzer/file_system/file_system.dart' hide File;
10
9
import 'package:analyzer/file_system/physical_file_system.dart' ;
11
10
import 'package:analyzer/source/package_map_resolver.dart' ;
12
11
import 'package:analyzer/source/pub_package_map_provider.dart' ;
13
12
import 'package:analyzer/src/dart/sdk/sdk.dart' show FolderBasedDartSdk;
14
13
import 'package:analyzer/src/generated/engine.dart' ;
15
- import 'package:analyzer/src/generated/java_io.dart' ;
16
14
import 'package:analyzer/src/generated/source.dart' ;
17
15
import 'package:analyzer/src/generated/source_io.dart' ;
18
- import 'package:cli_util/cli_util.dart' as cli;
19
16
import 'package:path/path.dart' as p;
20
17
21
- /// [foundFiles] is the list of files to consider for the context.
22
18
Future <AnalysisContext > getAnalysisContextForProjectPath (
23
- String projectPath, List < String > foundFiles ) async {
19
+ String projectPath) async {
24
20
// TODO: fail more clearly if this...fails
25
- var sdkPath = cli. getSdkPath ();
21
+ var sdkPath = _getSdkPath ();
26
22
27
23
var resourceProvider = PhysicalResourceProvider .INSTANCE ;
28
24
var sdk = new FolderBasedDartSdk (
@@ -44,9 +40,6 @@ Future<AnalysisContext> getAnalysisContextForProjectPath(
44
40
..analysisOptions = options
45
41
..sourceFactory = new SourceFactory (resolvers);
46
42
47
- // ensures all libraries defined by the set of files are resolved
48
- _getLibraryElements (foundFiles, context).toList ();
49
-
50
43
return context;
51
44
}
52
45
@@ -71,43 +64,5 @@ UriResolver _getPackageResolver(String projectPath, FolderBasedDartSdk sdk) {
71
64
PhysicalResourceProvider .INSTANCE , packageMap);
72
65
}
73
66
74
- LibraryElement getLibraryElementForSourceFile (
75
- AnalysisContext context, String sourcePath) {
76
- Source source = new FileBasedSource (new JavaFile (sourcePath));
77
-
78
- var libs = context.getLibrariesContaining (source);
79
-
80
- if (libs.length > 1 ) {
81
- throw new Exception ("We don't support multiple libraries for a source." );
82
- }
83
-
84
- if (libs.isEmpty) {
85
- return null ;
86
- }
87
-
88
- var libSource = libs.single;
89
-
90
- // using `getLibraryElement` because the library should already be computed
91
- // If not, it's a bug in usage
92
- return context.getLibraryElement (libSource);
93
- }
94
-
95
- // may return `null` if [path] doesn't refer to a library.
96
- /// [dartFiles] is a [Stream] of paths to [.dart] files.
97
- Iterable <LibraryElement > _getLibraryElements (
98
- List <String > dartFiles, AnalysisContext context) =>
99
- dartFiles
100
- .map ((path) => _getLibraryElement (path, context))
101
- .where ((lib) => lib != null );
102
-
103
- LibraryElement _getLibraryElement (String path, AnalysisContext context) {
104
- Source source = new FileBasedSource (new JavaFile (path));
105
- if (context.computeKindOf (source) == SourceKind .LIBRARY ) {
106
- return context.computeLibraryElement (source);
107
- }
108
- return null ;
109
- }
110
-
111
- String getFileBasedSourcePath (FileBasedSource source) {
112
- return p.fromUri (source.uri);
113
- }
67
+ /// Return the path to the current Dart SDK.
68
+ String _getSdkPath () => p.dirname (p.dirname (Platform .resolvedExecutable));
0 commit comments