OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 | 2 |
3 // for details. All rights reserved. Use of this source code is governed by a | 3 // for details. All rights reserved. Use of this source code is governed by a |
4 // BSD-style license that can be found in the LICENSE file. | 4 // BSD-style license that can be found in the LICENSE file. |
5 | 5 |
6 import 'package:args/args.dart' show ArgParser, ArgResults; | 6 import 'package:args/args.dart' show ArgParser, ArgResults; |
| 7 import 'package:analyzer/src/context/context.dart' show AnalysisContextImpl; |
7 import 'package:analyzer/src/generated/engine.dart' | 8 import 'package:analyzer/src/generated/engine.dart' |
8 show AnalysisContext, AnalysisEngine, AnalysisOptionsImpl; | 9 show AnalysisContext, AnalysisEngine, AnalysisOptionsImpl; |
9 import 'package:analyzer/src/generated/java_io.dart' show JavaFile; | 10 import 'package:analyzer/src/generated/java_io.dart' show JavaFile; |
10 import 'package:analyzer/src/generated/sdk_io.dart' show DirectoryBasedDartSdk; | 11 import 'package:analyzer/src/generated/sdk_io.dart' show DirectoryBasedDartSdk; |
11 import 'package:analyzer/src/generated/source_io.dart' | 12 import 'package:analyzer/src/generated/source_io.dart' |
12 show | 13 show |
13 CustomUriResolver, | 14 CustomUriResolver, |
14 DartUriResolver, | 15 DartUriResolver, |
15 FileUriResolver, | 16 FileUriResolver, |
16 PackageUriResolver, | 17 PackageUriResolver, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 {this.summaryPaths: const [], | 58 {this.summaryPaths: const [], |
58 this.useMockSdk: false, | 59 this.useMockSdk: false, |
59 String dartSdkPath, | 60 String dartSdkPath, |
60 this.dartSdkSummaryPath, | 61 this.dartSdkSummaryPath, |
61 this.customUrlMappings: const {}, | 62 this.customUrlMappings: const {}, |
62 this.packageRoot: 'packages/', | 63 this.packageRoot: 'packages/', |
63 this.packagePaths: const []}) | 64 this.packagePaths: const []}) |
64 : dartSdkPath = dartSdkPath ?? getSdkDir().path; | 65 : dartSdkPath = dartSdkPath ?? getSdkDir().path; |
65 | 66 |
66 AnalyzerOptions.fromArguments(ArgResults args) | 67 AnalyzerOptions.fromArguments(ArgResults args) |
67 : summaryPaths = args['summary'], | 68 : summaryPaths = args['summary'] as List<String>, |
68 useMockSdk = false, | 69 useMockSdk = false, |
69 dartSdkPath = args['dart-sdk'] ?? getSdkDir().path, | 70 dartSdkPath = args['dart-sdk'] ?? getSdkDir().path, |
70 dartSdkSummaryPath = args['dart-sdk-summary'], | 71 dartSdkSummaryPath = args['dart-sdk-summary'], |
71 customUrlMappings = _parseUrlMappings(args['url-mapping']), | 72 customUrlMappings = _parseUrlMappings(args['url-mapping']), |
72 packageRoot = args['package-root'], | 73 packageRoot = args['package-root'], |
73 packagePaths = args['package-paths']?.split(',') ?? []; | 74 packagePaths = (args['package-paths'] as String)?.split(',') ?? []; |
74 | 75 |
75 /// Whether to resolve 'package:' uris using the multi-package resolver. | 76 /// Whether to resolve 'package:' uris using the multi-package resolver. |
76 bool get useMultiPackage => packagePaths.isNotEmpty; | 77 bool get useMultiPackage => packagePaths.isNotEmpty; |
77 | 78 |
78 static ArgParser addArguments(ArgParser parser) { | 79 static ArgParser addArguments(ArgParser parser) { |
79 return parser | 80 return parser |
80 ..addOption('summary', | 81 ..addOption('summary', |
81 abbr: 's', help: 'summary file(s) to include', allowMultiple: true) | 82 abbr: 's', help: 'summary file(s) to include', allowMultiple: true) |
82 ..addOption('dart-sdk', help: 'Dart SDK Path', defaultsTo: null) | 83 ..addOption('dart-sdk', help: 'Dart SDK Path', defaultsTo: null) |
83 ..addOption('dart-sdk-summary', | 84 ..addOption('dart-sdk-summary', |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 context.sourceFactory = srcFactory; | 133 context.sourceFactory = srcFactory; |
133 if (summaryData != null) { | 134 if (summaryData != null) { |
134 context.typeProvider = sdkResolver.dartSdk.context.typeProvider; | 135 context.typeProvider = sdkResolver.dartSdk.context.typeProvider; |
135 context.resultProvider = | 136 context.resultProvider = |
136 new InputPackagesResultProvider(context, summaryData); | 137 new InputPackagesResultProvider(context, summaryData); |
137 } | 138 } |
138 return context; | 139 return context; |
139 } | 140 } |
140 | 141 |
141 /// Creates an analysis context that contains our restricted typing rules. | 142 /// Creates an analysis context that contains our restricted typing rules. |
142 AnalysisContext createAnalysisContext() { | 143 AnalysisContextImpl createAnalysisContext() { |
143 var res = AnalysisEngine.instance.createAnalysisContext(); | 144 var res = AnalysisEngine.instance.createAnalysisContext(); |
144 res.analysisOptions = new AnalysisOptionsImpl()..strongMode = true; | 145 res.analysisOptions = new AnalysisOptionsImpl()..strongMode = true; |
145 return res; | 146 return res; |
146 } | 147 } |
147 | 148 |
148 /// Creates a SourceFactory configured by the [options]. | 149 /// Creates a SourceFactory configured by the [options]. |
149 /// | 150 /// |
150 /// Use [options.useMockSdk] to specify the SDK mode, or use [sdkResolver] | 151 /// Use [options.useMockSdk] to specify the SDK mode, or use [sdkResolver] |
151 /// to entirely override the DartUriResolver. | 152 /// to entirely override the DartUriResolver. |
152 /// | 153 /// |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 return sdk; | 192 return sdk; |
192 } | 193 } |
193 | 194 |
194 /// Creates a [DartUriResolver] that uses the SDK at the given [sdkPath]. | 195 /// Creates a [DartUriResolver] that uses the SDK at the given [sdkPath]. |
195 DartUriResolver createSdkPathResolver(String sdkSummaryPath, String sdkPath) { | 196 DartUriResolver createSdkPathResolver(String sdkSummaryPath, String sdkPath) { |
196 var sdk = (sdkSummaryPath != null) | 197 var sdk = (sdkSummaryPath != null) |
197 ? new SummaryBasedDartSdk(sdkSummaryPath, true) | 198 ? new SummaryBasedDartSdk(sdkSummaryPath, true) |
198 : _createDirectoryBasedDartSdk(sdkPath); | 199 : _createDirectoryBasedDartSdk(sdkPath); |
199 return new DartUriResolver(sdk); | 200 return new DartUriResolver(sdk); |
200 } | 201 } |
OLD | NEW |