OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 mirrors_dart2js; | 5 library mirrors_dart2js; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:collection' show LinkedHashMap; | 8 import 'dart:collection' show LinkedHashMap; |
9 import 'dart:io'; | 9 import 'dart:io'; |
10 import 'dart:uri'; | 10 import 'dart:uri'; |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
209 {Path packageRoot, | 209 {Path packageRoot, |
210 List<String> options: const <String>[], | 210 List<String> options: const <String>[], |
211 api.DiagnosticHandler diagnosticHandler}) { | 211 api.DiagnosticHandler diagnosticHandler}) { |
212 Uri cwd = getCurrentDirectory(); | 212 Uri cwd = getCurrentDirectory(); |
213 SourceFileProvider provider = new SourceFileProvider(); | 213 SourceFileProvider provider = new SourceFileProvider(); |
214 if (diagnosticHandler == null) { | 214 if (diagnosticHandler == null) { |
215 diagnosticHandler = | 215 diagnosticHandler = |
216 new FormattingDiagnosticHandler(provider).diagnosticHandler; | 216 new FormattingDiagnosticHandler(provider).diagnosticHandler; |
217 } | 217 } |
218 Uri scriptUri = cwd.resolve(script.toString()); | 218 Uri scriptUri = cwd.resolve(script.toString()); |
219 Uri libraryUri = cwd.resolve('${libraryRoot}/'); | 219 Uri libraryUri = cwd.resolve(appendSlash(libraryRoot.toString())); |
Johnni Winther
2013/03/07 14:51:57
This appends a slash only if needed.
| |
220 Uri packageUri = null; | 220 Uri packageUri = null; |
221 if (packageRoot != null) { | 221 if (packageRoot != null) { |
222 packageUri = cwd.resolve('${packageRoot}/'); | 222 packageUri = cwd.resolve(appendSlash(packageRoot.toString())); |
223 } | 223 } |
224 return api.compile(scriptUri, libraryUri, packageUri, | 224 return api.compile(scriptUri, libraryUri, packageUri, |
225 provider.readStringFromUri, diagnosticHandler, options); | 225 provider.readStringFromUri, diagnosticHandler, options); |
226 } | 226 } |
227 | 227 |
228 /** | 228 /** |
229 * Analyzes set of libraries and provides a mirror system which can be used for | 229 * Analyzes set of libraries and provides a mirror system which can be used for |
230 * static inspection of the source code. | 230 * static inspection of the source code. |
231 */ | 231 */ |
232 Future<MirrorSystem> analyze(List<Path> libraries, | 232 Future<MirrorSystem> analyze(List<Path> libraries, |
233 Path libraryRoot, | 233 Path libraryRoot, |
234 {Path packageRoot, | 234 {Path packageRoot, |
235 List<String> options: const <String>[], | 235 List<String> options: const <String>[], |
236 api.DiagnosticHandler diagnosticHandler}) { | 236 api.DiagnosticHandler diagnosticHandler}) { |
237 Uri cwd = getCurrentDirectory(); | 237 Uri cwd = getCurrentDirectory(); |
238 SourceFileProvider provider = new SourceFileProvider(); | 238 SourceFileProvider provider = new SourceFileProvider(); |
239 if (diagnosticHandler == null) { | 239 if (diagnosticHandler == null) { |
240 diagnosticHandler = | 240 diagnosticHandler = |
241 new FormattingDiagnosticHandler(provider).diagnosticHandler; | 241 new FormattingDiagnosticHandler(provider).diagnosticHandler; |
242 } | 242 } |
243 Uri libraryUri = cwd.resolve('${libraryRoot}/'); | 243 Uri libraryUri = cwd.resolve(appendSlash(libraryRoot.toString())); |
244 Uri packageUri = null; | 244 Uri packageUri = null; |
245 if (packageRoot != null) { | 245 if (packageRoot != null) { |
246 packageUri = cwd.resolve('${packageRoot}/'); | 246 packageUri = cwd.resolve(appendSlash(packageRoot.toString())); |
247 } | 247 } |
248 options = new List<String>.from(options); | 248 options = new List<String>.from(options); |
249 options.add('--analyze-only'); | 249 options.add('--analyze-only'); |
250 options.add('--analyze-signatures-only'); | 250 options.add('--analyze-signatures-only'); |
251 options.add('--analyze-all'); | 251 options.add('--analyze-all'); |
252 | 252 |
253 bool compilationFailed = false; | 253 bool compilationFailed = false; |
254 void internalDiagnosticHandler(Uri uri, int begin, int end, | 254 void internalDiagnosticHandler(Uri uri, int begin, int end, |
255 String message, api.Diagnostic kind) { | 255 String message, api.Diagnostic kind) { |
256 if (kind == api.Diagnostic.ERROR || | 256 if (kind == api.Diagnostic.ERROR || |
(...skipping 1456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1713 return new Future.immediate( | 1713 return new Future.immediate( |
1714 new Dart2JsStringConstantMirror.fromString(mirrors, text)); | 1714 new Dart2JsStringConstantMirror.fromString(mirrors, text)); |
1715 } else if (fieldName == 'trimmedText') { | 1715 } else if (fieldName == 'trimmedText') { |
1716 return new Future.immediate( | 1716 return new Future.immediate( |
1717 new Dart2JsStringConstantMirror.fromString(mirrors, trimmedText)); | 1717 new Dart2JsStringConstantMirror.fromString(mirrors, trimmedText)); |
1718 } | 1718 } |
1719 // TODO(johnniwinther): Which exception/error should be thrown here? | 1719 // TODO(johnniwinther): Which exception/error should be thrown here? |
1720 throw new UnsupportedError('InstanceMirror does not have a reflectee'); | 1720 throw new UnsupportedError('InstanceMirror does not have a reflectee'); |
1721 } | 1721 } |
1722 } | 1722 } |
OLD | NEW |