@@ -23,17 +23,36 @@ import 'package:meta/meta.dart';
2323///
2424/// If a [resourceProvider] is given, it will be used to access the file system.
2525///
26- /// Note that if more than one file is going to be parsed then this function is
27- /// inefficient. Clients should instead use [AnalysisContextCollection] to
28- /// create one or more contexts and use those contexts to parse the files.
26+ /// [featureSet] determines what set of features will be assumed by the parser.
27+ /// This parameter is required because the analyzer does not yet have a
28+ /// performant way of computing the correct feature set for a single file to be
29+ /// parsed. Callers that need the feature set to be strictly correct must
30+ /// create an [AnalysisContextCollection] , query it to get an [AnalysisContext] ,
31+ /// query it to get an [AnalysisSession] , and then call `getParsedUnit` .
2932///
30- /// Deprecated: please use [parseFile2] instead.
31- @Deprecated ('Use parseFile2' )
32- ParsedUnitResult parseFile (
33- {@required String path, ResourceProvider resourceProvider}) {
34- AnalysisContext context =
35- _createAnalysisContext (path: path, resourceProvider: resourceProvider);
36- return context.currentSession.getParsedUnit (path);
33+ /// Callers that don't need the feature set to be strictly correct can pass in
34+ /// `FeatureSet.fromEnableFlags([])` to enable the default set of features; this
35+ /// is much more performant than using an analysis session, because it doesn't
36+ /// require the analyzer to process the SDK.
37+ ///
38+ /// If [throwIfDiagnostics] is `true` (the default), then if any diagnostics are
39+ /// produced because of syntactic errors in the [content] an `ArgumentError`
40+ /// will be thrown. If the parameter is `false` , then the caller can check the
41+ /// result to see whether there are any errors.
42+ ParseStringResult parseFile (
43+ {@required String path,
44+ ResourceProvider resourceProvider,
45+ @required FeatureSet featureSet,
46+ bool throwIfDiagnostics: true }) {
47+ if (featureSet == null ) {
48+ throw ArgumentError ('A non-null feature set must be provided.' );
49+ }
50+ resourceProvider ?? = PhysicalResourceProvider .INSTANCE ;
51+ var content = (resourceProvider.getResource (path) as File ).readAsStringSync ();
52+ return parseString (
53+ content: content,
54+ featureSet: featureSet,
55+ throwIfDiagnostics: throwIfDiagnostics);
3756}
3857
3958/// Return the result of parsing the file at the given [path] .
@@ -56,18 +75,15 @@ ParsedUnitResult parseFile(
5675/// produced because of syntactic errors in the [content] an `ArgumentError`
5776/// will be thrown. If the parameter is `false` , then the caller can check the
5877/// result to see whether there are any errors.
78+ @Deprecated ('Use parseFile' )
5979ParseStringResult parseFile2 (
6080 {@required String path,
6181 ResourceProvider resourceProvider,
6282 @required FeatureSet featureSet,
6383 bool throwIfDiagnostics: true }) {
64- if (featureSet == null ) {
65- throw ArgumentError ('A non-null feature set must be provided.' );
66- }
67- resourceProvider ?? = PhysicalResourceProvider .INSTANCE ;
68- var content = (resourceProvider.getResource (path) as File ).readAsStringSync ();
69- return parseString (
70- content: content,
84+ return parseFile (
85+ path: path,
86+ resourceProvider: resourceProvider,
7187 featureSet: featureSet,
7288 throwIfDiagnostics: throwIfDiagnostics);
7389}
0 commit comments