| 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 |
| 11 ImportDirective, | 11 ImportDirective, |
| 12 ExportDirective, | 12 ExportDirective, |
| 13 PartDirective, | 13 PartDirective, |
| 14 CompilationUnit, | 14 CompilationUnit, |
| 15 Identifier, | 15 Identifier, |
| 16 AnnotatedNode, | 16 AnnotatedNode, |
| 17 AstNode, | 17 AstNode, |
| 18 Expression, | 18 Expression, |
| 19 SimpleIdentifier, | 19 SimpleIdentifier, |
| 20 MethodInvocation; | 20 MethodInvocation; |
| 21 import 'package:analyzer/dart/element/element.dart'; | 21 import 'package:analyzer/dart/element/element.dart'; |
| 22 import 'package:analyzer/dart/element/type.dart'; | 22 import 'package:analyzer/dart/element/type.dart'; |
| 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; | |
| 29 import 'package:analyzer/src/task/dart.dart' show ParseDartTask; | 28 import 'package:analyzer/src/task/dart.dart' show ParseDartTask; |
| 30 import 'package:analyzer/src/generated/resolver.dart' show TypeProvider; | 29 import 'package:analyzer/src/generated/resolver.dart' show TypeProvider; |
| 31 import 'package:analyzer/src/generated/source.dart' show LineInfo, Source; | 30 import 'package:analyzer/src/generated/source.dart' show LineInfo, Source; |
| 32 import 'package:analyzer/analyzer.dart' show parseDirectives; | 31 import 'package:analyzer/analyzer.dart' show parseDirectives; |
| 33 import 'package:source_span/source_span.dart'; | 32 import 'package:source_span/source_span.dart'; |
| 34 | 33 |
| 35 import 'codegen/js_names.dart' show invalidVariableName; | 34 import 'codegen/js_names.dart' show invalidVariableName; |
| 36 | 35 |
| 37 bool isDartPrivateLibrary(LibraryElement library) { | 36 bool isDartPrivateLibrary(LibraryElement library) { |
| 38 var uri = library.source.uri; | 37 var uri = library.source.uri; |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 int lineEnd = endLoc.offset; | 394 int lineEnd = endLoc.offset; |
| 396 int lineNum = lineInfo.getLocation(lineEnd).lineNumber; | 395 int lineNum = lineInfo.getLocation(lineEnd).lineNumber; |
| 397 while (lineEnd < content.length && | 396 while (lineEnd < content.length && |
| 398 lineInfo.getLocation(++lineEnd).lineNumber == lineNum); | 397 lineInfo.getLocation(++lineEnd).lineNumber == lineNum); |
| 399 | 398 |
| 400 var text = content.substring(start, end); | 399 var text = content.substring(start, end); |
| 401 var lineText = content.substring(lineStart, lineEnd); | 400 var lineText = content.substring(lineStart, lineEnd); |
| 402 return new SourceSpanWithContext(startLoc, endLoc, text, lineText); | 401 return new SourceSpanWithContext(startLoc, endLoc, text, lineText); |
| 403 } | 402 } |
| 404 | 403 |
| 405 String _strongModeErrorPrefix = 'STRONG_MODE'; | |
| 406 | |
| 407 bool isStrongModeError(ErrorCode errorCode) { | |
| 408 return errorCode.name.startsWith(_strongModeErrorPrefix); | |
| 409 } | |
| 410 | |
| 411 String errorCodeName(ErrorCode errorCode) { | |
| 412 if (isStrongModeError(errorCode)) { | |
| 413 return errorCode.name.substring(_strongModeErrorPrefix.length + 1); | |
| 414 } else { | |
| 415 // TODO(jmesserly): this is for backwards compat, but not sure it's very | |
| 416 // useful to log this. | |
| 417 return 'AnalyzerMessage'; | |
| 418 } | |
| 419 } | |
| 420 | |
| 421 bool isInlineJS(Element e) => | 404 bool isInlineJS(Element e) => |
| 422 e is FunctionElement && | 405 e is FunctionElement && |
| 423 e.library.source.uri.toString() == 'dart:_foreign_helper' && | 406 e.library.source.uri.toString() == 'dart:_foreign_helper' && |
| 424 e.name == 'JS'; | 407 e.name == 'JS'; |
| 425 | 408 |
| 426 bool isDartMathMinMax(Element e) => | 409 bool isDartMathMinMax(Element e) => |
| 427 e is FunctionElement && | 410 e is FunctionElement && |
| 428 e.library.source.uri.toString() == 'dart:math' && | 411 e.library.source.uri.toString() == 'dart:math' && |
| 429 (e.name == 'min' || e.name == 'max'); | 412 (e.name == 'min' || e.name == 'max'); |
| 430 | 413 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 // ASTs. This may be a vestigial workaround. | 451 // ASTs. This may be a vestigial workaround. |
| 469 DartType getStaticType(Expression e) => | 452 DartType getStaticType(Expression e) => |
| 470 e.staticType ?? DynamicTypeImpl.instance; | 453 e.staticType ?? DynamicTypeImpl.instance; |
| 471 | 454 |
| 472 // TODO(leafp) Factor this out or use an existing library | 455 // TODO(leafp) Factor this out or use an existing library |
| 473 class Tuple2<T0, T1> { | 456 class Tuple2<T0, T1> { |
| 474 final T0 e0; | 457 final T0 e0; |
| 475 final T1 e1; | 458 final T1 e1; |
| 476 Tuple2(this.e0, this.e1); | 459 Tuple2(this.e0, this.e1); |
| 477 } | 460 } |
| OLD | NEW |