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 // 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 /// Holds a couple utility functions used at various places in the system. | 5 /// Holds a couple utility functions used at various places in the system. |
6 | 6 |
7 import 'dart:io'; | 7 import 'dart:io'; |
8 import 'package:path/path.dart' as path; | 8 import 'package:path/path.dart' as path; |
9 import 'package:analyzer/dart/ast/ast.dart' | 9 import 'package:analyzer/dart/ast/ast.dart' |
10 show | 10 show |
(...skipping 12 matching lines...) Expand all Loading... |
23 import 'package:analyzer/src/generated/constant.dart' show DartObject; | 23 import 'package:analyzer/src/generated/constant.dart' show DartObject; |
24 //TODO(leafp): Remove deprecated dependency | 24 //TODO(leafp): Remove deprecated dependency |
25 //ignore: DEPRECATED_MEMBER_USE | 25 //ignore: DEPRECATED_MEMBER_USE |
26 import 'package:analyzer/src/generated/element.dart' show DynamicTypeImpl; | 26 import 'package:analyzer/src/generated/element.dart' show DynamicTypeImpl; |
27 import 'package:analyzer/src/generated/engine.dart' show AnalysisContext; | 27 import 'package:analyzer/src/generated/engine.dart' show AnalysisContext; |
28 import 'package:analyzer/src/generated/error.dart' show ErrorCode; | 28 import 'package:analyzer/src/generated/error.dart' show ErrorCode; |
29 import 'package:analyzer/src/task/dart.dart' show ParseDartTask; | 29 import 'package:analyzer/src/task/dart.dart' show ParseDartTask; |
30 import 'package:analyzer/src/generated/resolver.dart' show TypeProvider; | 30 import 'package:analyzer/src/generated/resolver.dart' show TypeProvider; |
31 import 'package:analyzer/src/generated/source.dart' show LineInfo, Source; | 31 import 'package:analyzer/src/generated/source.dart' show LineInfo, Source; |
32 import 'package:analyzer/analyzer.dart' show parseDirectives; | 32 import 'package:analyzer/analyzer.dart' show parseDirectives; |
33 import 'package:crypto/crypto.dart' show CryptoUtils, MD5; | |
34 import 'package:source_span/source_span.dart'; | 33 import 'package:source_span/source_span.dart'; |
35 | 34 |
36 import 'codegen/js_names.dart' show invalidVariableName; | 35 import 'codegen/js_names.dart' show invalidVariableName; |
37 | 36 |
38 bool isDartPrivateLibrary(LibraryElement library) { | 37 bool isDartPrivateLibrary(LibraryElement library) { |
39 var uri = library.source.uri; | 38 var uri = library.source.uri; |
40 if (uri.scheme != "dart") return false; | 39 if (uri.scheme != "dart") return false; |
41 return Identifier.isPrivateName(uri.path); | 40 return Identifier.isPrivateName(uri.path); |
42 } | 41 } |
43 | 42 |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 new File(_path).writeAsStringSync('$_sb'); | 292 new File(_path).writeAsStringSync('$_sb'); |
294 } | 293 } |
295 } | 294 } |
296 | 295 |
297 SourceLocation locationForOffset(LineInfo lineInfo, Uri uri, int offset) { | 296 SourceLocation locationForOffset(LineInfo lineInfo, Uri uri, int offset) { |
298 var loc = lineInfo.getLocation(offset); | 297 var loc = lineInfo.getLocation(offset); |
299 return new SourceLocation(offset, | 298 return new SourceLocation(offset, |
300 sourceUrl: uri, line: loc.lineNumber - 1, column: loc.columnNumber - 1); | 299 sourceUrl: uri, line: loc.lineNumber - 1, column: loc.columnNumber - 1); |
301 } | 300 } |
302 | 301 |
303 /// Computes a hash for the given contents. | |
304 String computeHash(String contents) { | |
305 if (contents == null || contents == '') return null; | |
306 return CryptoUtils.bytesToHex((new MD5()..add(contents.codeUnits)).close()); | |
307 } | |
308 | |
309 /// Computes a hash for the given file path (reads the contents in binary form). | |
310 String computeHashFromFile(String filepath) { | |
311 var bytes = new File(filepath).readAsBytesSync(); | |
312 return CryptoUtils.bytesToHex((new MD5()..add(bytes)).close()); | |
313 } | |
314 | |
315 String resourceOutputPath(Uri resourceUri, Uri entryUri, String runtimeDir) { | 302 String resourceOutputPath(Uri resourceUri, Uri entryUri, String runtimeDir) { |
316 if (resourceUri.scheme == 'package') return resourceUri.path; | 303 if (resourceUri.scheme == 'package') return resourceUri.path; |
317 | 304 |
318 if (resourceUri.scheme != 'file') return null; | 305 if (resourceUri.scheme != 'file') return null; |
319 | 306 |
320 var entryPath = entryUri.path; | 307 var entryPath = entryUri.path; |
321 // The entry uri is either a directory or a dart/html file. If the latter, | 308 // The entry uri is either a directory or a dart/html file. If the latter, |
322 // trim the file. | 309 // trim the file. |
323 var entryDir = entryPath.endsWith('.dart') || entryPath.endsWith('.html') | 310 var entryDir = entryPath.endsWith('.dart') || entryPath.endsWith('.html') |
324 ? path.dirname(entryPath) | 311 ? path.dirname(entryPath) |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 // ASTs. This may be a vestigial workaround. | 468 // ASTs. This may be a vestigial workaround. |
482 DartType getStaticType(Expression e) => | 469 DartType getStaticType(Expression e) => |
483 e.staticType ?? DynamicTypeImpl.instance; | 470 e.staticType ?? DynamicTypeImpl.instance; |
484 | 471 |
485 // TODO(leafp) Factor this out or use an existing library | 472 // TODO(leafp) Factor this out or use an existing library |
486 class Tuple2<T0, T1> { | 473 class Tuple2<T0, T1> { |
487 final T0 e0; | 474 final T0 e0; |
488 final T1 e1; | 475 final T1 e1; |
489 Tuple2(this.e0, this.e1); | 476 Tuple2(this.e0, this.e1); |
490 } | 477 } |
OLD | NEW |