OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 engine.resolver; | 5 library engine.resolver; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 import "dart:math" as math; | 8 import "dart:math" as math; |
9 | 9 |
10 import 'java_core.dart'; | 10 import 'java_core.dart'; |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 // publishAs | 374 // publishAs |
375 String name = null; | 375 String name = null; |
376 int nameOffset = -1; | 376 int nameOffset = -1; |
377 if (_hasStringArgument(_PUBLISH_AS)) { | 377 if (_hasStringArgument(_PUBLISH_AS)) { |
378 name = _getStringArgument(_PUBLISH_AS); | 378 name = _getStringArgument(_PUBLISH_AS); |
379 nameOffset = _getStringArgumentOffset(_PUBLISH_AS); | 379 nameOffset = _getStringArgumentOffset(_PUBLISH_AS); |
380 } | 380 } |
381 // selector | 381 // selector |
382 AngularSelectorElement selector = null; | 382 AngularSelectorElement selector = null; |
383 if (!_hasStringArgument(_SELECTOR)) { | 383 if (!_hasStringArgument(_SELECTOR)) { |
384 _reportErrorForAnnotation(AngularCode.MISSING_SELECTOR, []); | 384 _reportErrorForAnnotation(AngularCode.MISSING_SELECTOR); |
385 isValid = false; | 385 isValid = false; |
386 } else { | 386 } else { |
387 SimpleStringLiteral selectorLiteral = _getStringLiteral(_SELECTOR); | 387 SimpleStringLiteral selectorLiteral = _getStringLiteral(_SELECTOR); |
388 selector = _parseSelectorFromString(selectorLiteral); | 388 selector = _parseSelectorFromString(selectorLiteral); |
389 if (selector == null) { | 389 if (selector == null) { |
390 _reportErrorForArgument(_SELECTOR, AngularCode.CANNOT_PARSE_SELECTOR, [s
electorLiteral]); | 390 _reportErrorForArgument(_SELECTOR, AngularCode.CANNOT_PARSE_SELECTOR, [s
electorLiteral]); |
391 isValid = false; | 391 isValid = false; |
392 } | 392 } |
393 } | 393 } |
394 // templateUrl | 394 // templateUrl |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 * Parses [AngularPropertyElement]s from [annotation]. | 471 * Parses [AngularPropertyElement]s from [annotation]. |
472 */ | 472 */ |
473 void _parseComponentProperties_fromMap(List<AngularPropertyElement> properties
) { | 473 void _parseComponentProperties_fromMap(List<AngularPropertyElement> properties
) { |
474 Expression mapExpression = _getArgument("map"); | 474 Expression mapExpression = _getArgument("map"); |
475 // may be not properties | 475 // may be not properties |
476 if (mapExpression == null) { | 476 if (mapExpression == null) { |
477 return; | 477 return; |
478 } | 478 } |
479 // prepare map literal | 479 // prepare map literal |
480 if (mapExpression is! MapLiteral) { | 480 if (mapExpression is! MapLiteral) { |
481 _reportErrorForNode(AngularCode.INVALID_PROPERTY_MAP, mapExpression, []); | 481 _reportErrorForNode(AngularCode.INVALID_PROPERTY_MAP, mapExpression); |
482 return; | 482 return; |
483 } | 483 } |
484 MapLiteral mapLiteral = mapExpression as MapLiteral; | 484 MapLiteral mapLiteral = mapExpression as MapLiteral; |
485 // analyze map entries | 485 // analyze map entries |
486 for (MapLiteralEntry entry in mapLiteral.entries) { | 486 for (MapLiteralEntry entry in mapLiteral.entries) { |
487 // prepare property name | 487 // prepare property name |
488 Expression nameExpression = entry.key; | 488 Expression nameExpression = entry.key; |
489 if (nameExpression is! SimpleStringLiteral) { | 489 if (nameExpression is! SimpleStringLiteral) { |
490 _reportErrorForNode(AngularCode.INVALID_PROPERTY_NAME, nameExpression, [
]); | 490 _reportErrorForNode(AngularCode.INVALID_PROPERTY_NAME, nameExpression); |
491 continue; | 491 continue; |
492 } | 492 } |
493 SimpleStringLiteral nameLiteral = nameExpression as SimpleStringLiteral; | 493 SimpleStringLiteral nameLiteral = nameExpression as SimpleStringLiteral; |
494 String name = nameLiteral.value; | 494 String name = nameLiteral.value; |
495 int nameOffset = nameLiteral.contentsOffset; | 495 int nameOffset = nameLiteral.contentsOffset; |
496 // prepare field specification | 496 // prepare field specification |
497 Expression specExpression = entry.value; | 497 Expression specExpression = entry.value; |
498 if (specExpression is! SimpleStringLiteral) { | 498 if (specExpression is! SimpleStringLiteral) { |
499 _reportErrorForNode(AngularCode.INVALID_PROPERTY_SPEC, specExpression, [
]); | 499 _reportErrorForNode(AngularCode.INVALID_PROPERTY_SPEC, specExpression); |
500 continue; | 500 continue; |
501 } | 501 } |
502 SimpleStringLiteral specLiteral = specExpression as SimpleStringLiteral; | 502 SimpleStringLiteral specLiteral = specExpression as SimpleStringLiteral; |
503 String spec = specLiteral.value; | 503 String spec = specLiteral.value; |
504 // parse binding kind and field name | 504 // parse binding kind and field name |
505 AngularPropertyKind kind; | 505 AngularPropertyKind kind; |
506 int fieldNameOffset; | 506 int fieldNameOffset; |
507 if (StringUtilities.startsWithChar(spec, 0x40)) { | 507 if (StringUtilities.startsWithChar(spec, 0x40)) { |
508 kind = AngularPropertyKind.ATTR; | 508 kind = AngularPropertyKind.ATTR; |
509 fieldNameOffset = 1; | 509 fieldNameOffset = 1; |
(...skipping 28 matching lines...) Expand all Loading... |
538 property.propertyKind = kind; | 538 property.propertyKind = kind; |
539 property.fieldNameOffset = fieldNameOffset; | 539 property.fieldNameOffset = fieldNameOffset; |
540 properties.add(property); | 540 properties.add(property); |
541 } | 541 } |
542 } | 542 } |
543 | 543 |
544 void _parseController() { | 544 void _parseController() { |
545 bool isValid = true; | 545 bool isValid = true; |
546 // publishAs | 546 // publishAs |
547 if (!_hasStringArgument(_PUBLISH_AS)) { | 547 if (!_hasStringArgument(_PUBLISH_AS)) { |
548 _reportErrorForAnnotation(AngularCode.MISSING_PUBLISH_AS, []); | 548 _reportErrorForAnnotation(AngularCode.MISSING_PUBLISH_AS); |
549 isValid = false; | 549 isValid = false; |
550 } | 550 } |
551 // selector | 551 // selector |
552 AngularSelectorElement selector = null; | 552 AngularSelectorElement selector = null; |
553 if (!_hasStringArgument(_SELECTOR)) { | 553 if (!_hasStringArgument(_SELECTOR)) { |
554 _reportErrorForAnnotation(AngularCode.MISSING_SELECTOR, []); | 554 _reportErrorForAnnotation(AngularCode.MISSING_SELECTOR); |
555 isValid = false; | 555 isValid = false; |
556 } else { | 556 } else { |
557 SimpleStringLiteral selectorLiteral = _getStringLiteral(_SELECTOR); | 557 SimpleStringLiteral selectorLiteral = _getStringLiteral(_SELECTOR); |
558 selector = _parseSelectorFromString(selectorLiteral); | 558 selector = _parseSelectorFromString(selectorLiteral); |
559 if (selector == null) { | 559 if (selector == null) { |
560 _reportErrorForArgument(_SELECTOR, AngularCode.CANNOT_PARSE_SELECTOR, [s
electorLiteral]); | 560 _reportErrorForArgument(_SELECTOR, AngularCode.CANNOT_PARSE_SELECTOR, [s
electorLiteral]); |
561 isValid = false; | 561 isValid = false; |
562 } | 562 } |
563 } | 563 } |
564 // create | 564 // create |
565 if (isValid) { | 565 if (isValid) { |
566 String name = _getStringArgument(_PUBLISH_AS); | 566 String name = _getStringArgument(_PUBLISH_AS); |
567 int nameOffset = _getStringArgumentOffset(_PUBLISH_AS); | 567 int nameOffset = _getStringArgumentOffset(_PUBLISH_AS); |
568 AngularControllerElementImpl element = new AngularControllerElementImpl(na
me, nameOffset); | 568 AngularControllerElementImpl element = new AngularControllerElementImpl(na
me, nameOffset); |
569 element.selector = selector; | 569 element.selector = selector; |
570 _classElement.addToolkitObjects(element); | 570 _classElement.addToolkitObjects(element); |
571 } | 571 } |
572 } | 572 } |
573 | 573 |
574 void _parseDecorator() { | 574 void _parseDecorator() { |
575 bool isValid = true; | 575 bool isValid = true; |
576 // selector | 576 // selector |
577 AngularSelectorElement selector = null; | 577 AngularSelectorElement selector = null; |
578 if (!_hasStringArgument(_SELECTOR)) { | 578 if (!_hasStringArgument(_SELECTOR)) { |
579 _reportErrorForAnnotation(AngularCode.MISSING_SELECTOR, []); | 579 _reportErrorForAnnotation(AngularCode.MISSING_SELECTOR); |
580 isValid = false; | 580 isValid = false; |
581 } else { | 581 } else { |
582 SimpleStringLiteral selectorLiteral = _getStringLiteral(_SELECTOR); | 582 SimpleStringLiteral selectorLiteral = _getStringLiteral(_SELECTOR); |
583 selector = _parseSelectorFromString(selectorLiteral); | 583 selector = _parseSelectorFromString(selectorLiteral); |
584 if (selector == null) { | 584 if (selector == null) { |
585 _reportErrorForArgument(_SELECTOR, AngularCode.CANNOT_PARSE_SELECTOR, [s
electorLiteral]); | 585 _reportErrorForArgument(_SELECTOR, AngularCode.CANNOT_PARSE_SELECTOR, [s
electorLiteral]); |
586 isValid = false; | 586 isValid = false; |
587 } | 587 } |
588 } | 588 } |
589 // create | 589 // create |
590 if (isValid) { | 590 if (isValid) { |
591 int offset = _annotation.offset; | 591 int offset = _annotation.offset; |
592 AngularDecoratorElementImpl element = new AngularDecoratorElementImpl(offs
et); | 592 AngularDecoratorElementImpl element = new AngularDecoratorElementImpl(offs
et); |
593 element.selector = selector; | 593 element.selector = selector; |
594 element.properties = _parseComponentProperties(); | 594 element.properties = _parseComponentProperties(); |
595 _classElement.addToolkitObjects(element); | 595 _classElement.addToolkitObjects(element); |
596 } | 596 } |
597 } | 597 } |
598 | 598 |
599 void _parseFormatter() { | 599 void _parseFormatter() { |
600 bool isValid = true; | 600 bool isValid = true; |
601 // name | 601 // name |
602 if (!_hasStringArgument(_NAME)) { | 602 if (!_hasStringArgument(_NAME)) { |
603 _reportErrorForAnnotation(AngularCode.MISSING_NAME, []); | 603 _reportErrorForAnnotation(AngularCode.MISSING_NAME); |
604 isValid = false; | 604 isValid = false; |
605 } | 605 } |
606 // create | 606 // create |
607 if (isValid) { | 607 if (isValid) { |
608 String name = _getStringArgument(_NAME); | 608 String name = _getStringArgument(_NAME); |
609 int nameOffset = _getStringArgumentOffset(_NAME); | 609 int nameOffset = _getStringArgumentOffset(_NAME); |
610 _classElement.addToolkitObjects(new AngularFormatterElementImpl(name, name
Offset)); | 610 _classElement.addToolkitObjects(new AngularFormatterElementImpl(name, name
Offset)); |
611 } | 611 } |
612 } | 612 } |
613 | 613 |
614 List<AngularScopePropertyElement> _parseScopeProperties() { | 614 List<AngularScopePropertyElement> _parseScopeProperties() { |
615 List<AngularScopePropertyElement> properties = <AngularScopePropertyElement>
[]; | 615 List<AngularScopePropertyElement> properties = <AngularScopePropertyElement>
[]; |
616 _classDeclaration.accept(new RecursiveAstVisitor_AngularCompilationUnitBuild
er_parseScopeProperties(properties)); | 616 _classDeclaration.accept(new RecursiveAstVisitor_AngularCompilationUnitBuild
er_parseScopeProperties(properties)); |
617 return properties; | 617 return properties; |
618 } | 618 } |
619 | 619 |
620 /** | 620 /** |
621 * Create [AngularViewElement] for each valid <code>view('template.html')</cod
e> invocation, | 621 * Create [AngularViewElement] for each valid <code>view('template.html')</cod
e> invocation, |
622 * where <code>view</code> is <code>ViewFactory</code>. | 622 * where <code>view</code> is <code>ViewFactory</code>. |
623 */ | 623 */ |
624 void _parseViews() { | 624 void _parseViews() { |
625 List<AngularViewElement> views = <AngularViewElement>[]; | 625 List<AngularViewElement> views = <AngularViewElement>[]; |
626 _unit.accept(new RecursiveAstVisitor_AngularCompilationUnitBuilder_parseView
s(views)); | 626 _unit.accept(new RecursiveAstVisitor_AngularCompilationUnitBuilder_parseView
s(views)); |
627 if (!views.isEmpty) { | 627 if (!views.isEmpty) { |
628 List<AngularViewElement> viewArray = views; | 628 List<AngularViewElement> viewArray = views; |
629 (_unit.element as CompilationUnitElementImpl).angularViews = viewArray; | 629 (_unit.element as CompilationUnitElementImpl).angularViews = viewArray; |
630 } | 630 } |
631 } | 631 } |
632 | 632 |
633 void _reportErrorForAnnotation(ErrorCode errorCode, List<Object> arguments) { | 633 void _reportErrorForAnnotation(ErrorCode errorCode, [List<Object> arguments])
{ |
634 _reportErrorForNode(errorCode, _annotation, arguments); | 634 _reportErrorForNode(errorCode, _annotation, arguments); |
635 } | 635 } |
636 | 636 |
637 void _reportErrorForArgument(String argumentName, ErrorCode errorCode, List<Ob
ject> arguments) { | 637 void _reportErrorForArgument(String argumentName, ErrorCode errorCode, [List<O
bject> arguments]) { |
638 Expression argument = _getArgument(argumentName); | 638 Expression argument = _getArgument(argumentName); |
639 _reportErrorForNode(errorCode, argument, arguments); | 639 _reportErrorForNode(errorCode, argument, arguments); |
640 } | 640 } |
641 | 641 |
642 void _reportErrorForNode(ErrorCode errorCode, AstNode node, List<Object> argum
ents) { | 642 void _reportErrorForNode(ErrorCode errorCode, AstNode node, [List<Object> argu
ments]) { |
643 int offset = node.offset; | 643 int offset = node.offset; |
644 int length = node.length; | 644 int length = node.length; |
645 _reportErrorForOffset(errorCode, offset, length, arguments); | 645 _reportErrorForOffset(errorCode, offset, length, arguments); |
646 } | 646 } |
647 | 647 |
648 void _reportErrorForOffset(ErrorCode errorCode, int offset, int length, List<O
bject> arguments) { | 648 void _reportErrorForOffset(ErrorCode errorCode, int offset, int length, [List<
Object> arguments]) { |
649 _errorListener.onError(new AnalysisError.con2(_source, offset, length, error
Code, arguments)); | 649 _errorListener.onError(new AnalysisError.con2(_source, offset, length, error
Code, arguments)); |
650 } | 650 } |
651 } | 651 } |
652 | 652 |
653 /** | 653 /** |
654 * Instances of the class `BestPracticesVerifier` traverse an AST structure look
ing for | 654 * Instances of the class `BestPracticesVerifier` traverse an AST structure look
ing for |
655 * violations of Dart best practices. | 655 * violations of Dart best practices. |
656 */ | 656 */ |
657 class BestPracticesVerifier extends RecursiveAstVisitor<Object> { | 657 class BestPracticesVerifier extends RecursiveAstVisitor<Object> { |
658 static String _HASHCODE_GETTER_NAME = "hashCode"; | 658 static String _HASHCODE_GETTER_NAME = "hashCode"; |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
844 DartType lhsType = expression.staticType; | 844 DartType lhsType = expression.staticType; |
845 DartType rhsType = typeName.type; | 845 DartType rhsType = typeName.type; |
846 if (lhsType == null || rhsType == null) { | 846 if (lhsType == null || rhsType == null) { |
847 return false; | 847 return false; |
848 } | 848 } |
849 String rhsNameStr = typeName.name.name; | 849 String rhsNameStr = typeName.name.name; |
850 // if x is dynamic | 850 // if x is dynamic |
851 if (rhsType.isDynamic && rhsNameStr == sc.Keyword.DYNAMIC.syntax) { | 851 if (rhsType.isDynamic && rhsNameStr == sc.Keyword.DYNAMIC.syntax) { |
852 if (node.notOperator == null) { | 852 if (node.notOperator == null) { |
853 // the is case | 853 // the is case |
854 _errorReporter.reportErrorForNode(HintCode.UNNECESSARY_TYPE_CHECK_TRUE,
node, []); | 854 _errorReporter.reportErrorForNode(HintCode.UNNECESSARY_TYPE_CHECK_TRUE,
node); |
855 } else { | 855 } else { |
856 // the is not case | 856 // the is not case |
857 _errorReporter.reportErrorForNode(HintCode.UNNECESSARY_TYPE_CHECK_FALSE,
node, []); | 857 _errorReporter.reportErrorForNode(HintCode.UNNECESSARY_TYPE_CHECK_FALSE,
node); |
858 } | 858 } |
859 return true; | 859 return true; |
860 } | 860 } |
861 Element rhsElement = rhsType.element; | 861 Element rhsElement = rhsType.element; |
862 LibraryElement libraryElement = rhsElement != null ? rhsElement.library : nu
ll; | 862 LibraryElement libraryElement = rhsElement != null ? rhsElement.library : nu
ll; |
863 if (libraryElement != null && libraryElement.isDartCore) { | 863 if (libraryElement != null && libraryElement.isDartCore) { |
864 // if x is Object or null is Null | 864 // if x is Object or null is Null |
865 if (rhsType.isObject || (expression is NullLiteral && rhsNameStr == _NULL_
TYPE_NAME)) { | 865 if (rhsType.isObject || (expression is NullLiteral && rhsNameStr == _NULL_
TYPE_NAME)) { |
866 if (node.notOperator == null) { | 866 if (node.notOperator == null) { |
867 // the is case | 867 // the is case |
868 _errorReporter.reportErrorForNode(HintCode.UNNECESSARY_TYPE_CHECK_TRUE
, node, []); | 868 _errorReporter.reportErrorForNode(HintCode.UNNECESSARY_TYPE_CHECK_TRUE
, node); |
869 } else { | 869 } else { |
870 // the is not case | 870 // the is not case |
871 _errorReporter.reportErrorForNode(HintCode.UNNECESSARY_TYPE_CHECK_FALS
E, node, []); | 871 _errorReporter.reportErrorForNode(HintCode.UNNECESSARY_TYPE_CHECK_FALS
E, node); |
872 } | 872 } |
873 return true; | 873 return true; |
874 } else if (rhsNameStr == _NULL_TYPE_NAME) { | 874 } else if (rhsNameStr == _NULL_TYPE_NAME) { |
875 if (node.notOperator == null) { | 875 if (node.notOperator == null) { |
876 // the is case | 876 // the is case |
877 _errorReporter.reportErrorForNode(HintCode.TYPE_CHECK_IS_NULL, node, [
]); | 877 _errorReporter.reportErrorForNode(HintCode.TYPE_CHECK_IS_NULL, node); |
878 } else { | 878 } else { |
879 // the is not case | 879 // the is not case |
880 _errorReporter.reportErrorForNode(HintCode.TYPE_CHECK_IS_NOT_NULL, nod
e, []); | 880 _errorReporter.reportErrorForNode(HintCode.TYPE_CHECK_IS_NOT_NULL, nod
e); |
881 } | 881 } |
882 return true; | 882 return true; |
883 } | 883 } |
884 } | 884 } |
885 return false; | 885 return false; |
886 } | 886 } |
887 | 887 |
888 /** | 888 /** |
889 * This verifies that the passed expression can be assigned to its correspondi
ng parameters. | 889 * This verifies that the passed expression can be assigned to its correspondi
ng parameters. |
890 * | 890 * |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1055 LibraryElement libraryElement = methodElement.library; | 1055 LibraryElement libraryElement = methodElement.library; |
1056 if (libraryElement != null && !libraryElement.isDartCore) { | 1056 if (libraryElement != null && !libraryElement.isDartCore) { |
1057 return false; | 1057 return false; |
1058 } | 1058 } |
1059 // Report error if the (x/y) has toInt() invoked on it | 1059 // Report error if the (x/y) has toInt() invoked on it |
1060 if (node.parent is ParenthesizedExpression) { | 1060 if (node.parent is ParenthesizedExpression) { |
1061 ParenthesizedExpression parenthesizedExpression = _wrapParenthesizedExpres
sion(node.parent as ParenthesizedExpression); | 1061 ParenthesizedExpression parenthesizedExpression = _wrapParenthesizedExpres
sion(node.parent as ParenthesizedExpression); |
1062 if (parenthesizedExpression.parent is MethodInvocation) { | 1062 if (parenthesizedExpression.parent is MethodInvocation) { |
1063 MethodInvocation methodInvocation = parenthesizedExpression.parent as Me
thodInvocation; | 1063 MethodInvocation methodInvocation = parenthesizedExpression.parent as Me
thodInvocation; |
1064 if (_TO_INT_METHOD_NAME == methodInvocation.methodName.name && methodInv
ocation.argumentList.arguments.isEmpty) { | 1064 if (_TO_INT_METHOD_NAME == methodInvocation.methodName.name && methodInv
ocation.argumentList.arguments.isEmpty) { |
1065 _errorReporter.reportErrorForNode(HintCode.DIVISION_OPTIMIZATION, meth
odInvocation, []); | 1065 _errorReporter.reportErrorForNode(HintCode.DIVISION_OPTIMIZATION, meth
odInvocation); |
1066 return true; | 1066 return true; |
1067 } | 1067 } |
1068 } | 1068 } |
1069 } | 1069 } |
1070 return false; | 1070 return false; |
1071 } | 1071 } |
1072 | 1072 |
1073 /** | 1073 /** |
1074 * This verifies that the passed left hand side and right hand side represent
a valid assignment. | 1074 * This verifies that the passed left hand side and right hand side represent
a valid assignment. |
1075 * | 1075 * |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1188 * See [HintCode.UNNECESSARY_CAST]. | 1188 * See [HintCode.UNNECESSARY_CAST]. |
1189 */ | 1189 */ |
1190 bool _checkForUnnecessaryCast(AsExpression node) { | 1190 bool _checkForUnnecessaryCast(AsExpression node) { |
1191 Expression expression = node.expression; | 1191 Expression expression = node.expression; |
1192 TypeName typeName = node.type; | 1192 TypeName typeName = node.type; |
1193 DartType lhsType = expression.staticType; | 1193 DartType lhsType = expression.staticType; |
1194 DartType rhsType = typeName.type; | 1194 DartType rhsType = typeName.type; |
1195 // TODO(jwren) After dartbug.com/13732, revisit this, we should be able to r
emove the | 1195 // TODO(jwren) After dartbug.com/13732, revisit this, we should be able to r
emove the |
1196 // !(x instanceof TypeParameterType) checks. | 1196 // !(x instanceof TypeParameterType) checks. |
1197 if (lhsType != null && rhsType != null && !lhsType.isDynamic && !rhsType.isD
ynamic && lhsType is! TypeParameterType && rhsType is! TypeParameterType && lhsT
ype.isMoreSpecificThan(rhsType)) { | 1197 if (lhsType != null && rhsType != null && !lhsType.isDynamic && !rhsType.isD
ynamic && lhsType is! TypeParameterType && rhsType is! TypeParameterType && lhsT
ype.isMoreSpecificThan(rhsType)) { |
1198 _errorReporter.reportErrorForNode(HintCode.UNNECESSARY_CAST, node, []); | 1198 _errorReporter.reportErrorForNode(HintCode.UNNECESSARY_CAST, node); |
1199 return true; | 1199 return true; |
1200 } | 1200 } |
1201 return false; | 1201 return false; |
1202 } | 1202 } |
1203 | 1203 |
1204 /** | 1204 /** |
1205 * Check for situations where the result of a method or function is used, when
it returns 'void'. | 1205 * Check for situations where the result of a method or function is used, when
it returns 'void'. |
1206 * | 1206 * |
1207 * TODO(jwren) Many other situations of use could be covered. We currently cov
er the cases var x = | 1207 * TODO(jwren) Many other situations of use could be covered. We currently cov
er the cases var x = |
1208 * m() and x = m(), but we could also cover cases such as m().x, m()[k], a + m
(), f(m()), return | 1208 * m() and x = m(), but we could also cover cases such as m().x, m()[k], a + m
(), f(m()), return |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1361 | 1361 |
1362 @override | 1362 @override |
1363 Object visitAnnotation(Annotation node) { | 1363 Object visitAnnotation(Annotation node) { |
1364 super.visitAnnotation(node); | 1364 super.visitAnnotation(node); |
1365 // check annotation creation | 1365 // check annotation creation |
1366 Element element = node.element; | 1366 Element element = node.element; |
1367 if (element is ConstructorElement) { | 1367 if (element is ConstructorElement) { |
1368 ConstructorElement constructorElement = element; | 1368 ConstructorElement constructorElement = element; |
1369 // should 'const' constructor | 1369 // should 'const' constructor |
1370 if (!constructorElement.isConst) { | 1370 if (!constructorElement.isConst) { |
1371 _errorReporter.reportErrorForNode(CompileTimeErrorCode.NON_CONSTANT_ANNO
TATION_CONSTRUCTOR, node, []); | 1371 _errorReporter.reportErrorForNode(CompileTimeErrorCode.NON_CONSTANT_ANNO
TATION_CONSTRUCTOR, node); |
1372 return null; | 1372 return null; |
1373 } | 1373 } |
1374 // should have arguments | 1374 // should have arguments |
1375 ArgumentList argumentList = node.arguments; | 1375 ArgumentList argumentList = node.arguments; |
1376 if (argumentList == null) { | 1376 if (argumentList == null) { |
1377 _errorReporter.reportErrorForNode(CompileTimeErrorCode.NO_ANNOTATION_CON
STRUCTOR_ARGUMENTS, node, []); | 1377 _errorReporter.reportErrorForNode(CompileTimeErrorCode.NO_ANNOTATION_CON
STRUCTOR_ARGUMENTS, node); |
1378 return null; | 1378 return null; |
1379 } | 1379 } |
1380 // arguments should be constants | 1380 // arguments should be constants |
1381 _validateConstantArguments(argumentList); | 1381 _validateConstantArguments(argumentList); |
1382 } | 1382 } |
1383 return null; | 1383 return null; |
1384 } | 1384 } |
1385 | 1385 |
1386 @override | 1386 @override |
1387 Object visitConstructorDeclaration(ConstructorDeclaration node) { | 1387 Object visitConstructorDeclaration(ConstructorDeclaration node) { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1467 } else { | 1467 } else { |
1468 keys.add(result); | 1468 keys.add(result); |
1469 } | 1469 } |
1470 } else { | 1470 } else { |
1471 reportEqualKeys = false; | 1471 reportEqualKeys = false; |
1472 } | 1472 } |
1473 } | 1473 } |
1474 } | 1474 } |
1475 if (reportEqualKeys) { | 1475 if (reportEqualKeys) { |
1476 for (Expression key in invalidKeys) { | 1476 for (Expression key in invalidKeys) { |
1477 _errorReporter.reportErrorForNode(StaticWarningCode.EQUAL_KEYS_IN_MAP, k
ey, []); | 1477 _errorReporter.reportErrorForNode(StaticWarningCode.EQUAL_KEYS_IN_MAP, k
ey); |
1478 } | 1478 } |
1479 } | 1479 } |
1480 return null; | 1480 return null; |
1481 } | 1481 } |
1482 | 1482 |
1483 @override | 1483 @override |
1484 Object visitMethodDeclaration(MethodDeclaration node) { | 1484 Object visitMethodDeclaration(MethodDeclaration node) { |
1485 super.visitMethodDeclaration(node); | 1485 super.visitMethodDeclaration(node); |
1486 _validateDefaultValues(node.parameters); | 1486 _validateDefaultValues(node.parameters); |
1487 return null; | 1487 return null; |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1593 * the node if its' value consists of information from a deferred library. | 1593 * the node if its' value consists of information from a deferred library. |
1594 * | 1594 * |
1595 * @param expression the expression to be tested for a deferred library refere
nce | 1595 * @param expression the expression to be tested for a deferred library refere
nce |
1596 * @param errorCode the error code to be used if the expression is or consists
of a reference to a | 1596 * @param errorCode the error code to be used if the expression is or consists
of a reference to a |
1597 * deferred library | 1597 * deferred library |
1598 */ | 1598 */ |
1599 void _reportErrorIfFromDeferredLibrary(Expression expression, ErrorCode errorC
ode) { | 1599 void _reportErrorIfFromDeferredLibrary(Expression expression, ErrorCode errorC
ode) { |
1600 DeferredLibraryReferenceDetector referenceDetector = new DeferredLibraryRefe
renceDetector(); | 1600 DeferredLibraryReferenceDetector referenceDetector = new DeferredLibraryRefe
renceDetector(); |
1601 expression.accept(referenceDetector); | 1601 expression.accept(referenceDetector); |
1602 if (referenceDetector.result) { | 1602 if (referenceDetector.result) { |
1603 _errorReporter.reportErrorForNode(errorCode, expression, []); | 1603 _errorReporter.reportErrorForNode(errorCode, expression); |
1604 } | 1604 } |
1605 } | 1605 } |
1606 | 1606 |
1607 /** | 1607 /** |
1608 * Report any errors in the given list. Except for special cases, use the give
n error code rather | 1608 * Report any errors in the given list. Except for special cases, use the give
n error code rather |
1609 * than the one reported in the error. | 1609 * than the one reported in the error. |
1610 * | 1610 * |
1611 * @param errors the errors that need to be reported | 1611 * @param errors the errors that need to be reported |
1612 * @param errorCode the error code to be used | 1612 * @param errorCode the error code to be used |
1613 */ | 1613 */ |
1614 void _reportErrors(List<AnalysisError> errors, ErrorCode errorCode) { | 1614 void _reportErrors(List<AnalysisError> errors, ErrorCode errorCode) { |
1615 for (AnalysisError data in errors) { | 1615 for (AnalysisError data in errors) { |
1616 ErrorCode dataErrorCode = data.errorCode; | 1616 ErrorCode dataErrorCode = data.errorCode; |
1617 if (identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPT
ION) || | 1617 if (identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPT
ION) || |
1618 identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_THROWS_IDBZE)
|| | 1618 identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_THROWS_IDBZE)
|| |
1619 identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM
_STRING) || | 1619 identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM
_STRING) || |
1620 identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL) || | 1620 identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL) || |
1621 identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_INT) || | 1621 identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_INT) || |
1622 identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM) || | 1622 identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM) || |
1623 identical(dataErrorCode, CheckedModeCompileTimeErrorCode.CONST_CONSTRU
CTOR_FIELD_TYPE_MISMATCH) || | 1623 identical(dataErrorCode, CheckedModeCompileTimeErrorCode.CONST_CONSTRU
CTOR_FIELD_TYPE_MISMATCH) || |
1624 identical(dataErrorCode, CheckedModeCompileTimeErrorCode.CONST_CONSTRU
CTOR_PARAM_TYPE_MISMATCH) || | 1624 identical(dataErrorCode, CheckedModeCompileTimeErrorCode.CONST_CONSTRU
CTOR_PARAM_TYPE_MISMATCH) || |
1625 identical(dataErrorCode, CheckedModeCompileTimeErrorCode.VARIABLE_TYPE
_MISMATCH)) { | 1625 identical(dataErrorCode, CheckedModeCompileTimeErrorCode.VARIABLE_TYPE
_MISMATCH)) { |
1626 _errorReporter.reportError(data); | 1626 _errorReporter.reportError(data); |
1627 } else if (errorCode != null) { | 1627 } else if (errorCode != null) { |
1628 _errorReporter.reportError(new AnalysisError.con2(data.source, data.offs
et, data.length, errorCode, [])); | 1628 _errorReporter.reportError(new AnalysisError.con2(data.source, data.offs
et, data.length, errorCode)); |
1629 } | 1629 } |
1630 } | 1630 } |
1631 } | 1631 } |
1632 | 1632 |
1633 /** | 1633 /** |
1634 * Validate that the given expression is a compile time constant. Return the v
alue of the compile | 1634 * Validate that the given expression is a compile time constant. Return the v
alue of the compile |
1635 * time constant, or `null` if the expression is not a compile time constant. | 1635 * time constant, or `null` if the expression is not a compile time constant. |
1636 * | 1636 * |
1637 * @param expression the expression to be validated | 1637 * @param expression the expression to be validated |
1638 * @param errorCode the error code to be used if the expression is not a compi
le time constant | 1638 * @param errorCode the error code to be used if the expression is not a compi
le time constant |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1890 // && libraryElement.isDartCore()) { | 1890 // && libraryElement.isDartCore()) { |
1891 // if (node.getNotOperator() == null) { | 1891 // if (node.getNotOperator() == null) { |
1892 // errorReporter.reportError(HintCode.IS_INT, node); | 1892 // errorReporter.reportError(HintCode.IS_INT, node); |
1893 // } else { | 1893 // } else { |
1894 // errorReporter.reportError(HintCode.IS_NOT_INT, node); | 1894 // errorReporter.reportError(HintCode.IS_NOT_INT, node); |
1895 // } | 1895 // } |
1896 // return true; | 1896 // return true; |
1897 // } else | 1897 // } else |
1898 if (typeNameStr == _DOUBLE_TYPE_NAME && libraryElement != null && libraryE
lement.isDartCore) { | 1898 if (typeNameStr == _DOUBLE_TYPE_NAME && libraryElement != null && libraryE
lement.isDartCore) { |
1899 if (node.notOperator == null) { | 1899 if (node.notOperator == null) { |
1900 _errorReporter.reportErrorForNode(HintCode.IS_DOUBLE, node, []); | 1900 _errorReporter.reportErrorForNode(HintCode.IS_DOUBLE, node); |
1901 } else { | 1901 } else { |
1902 _errorReporter.reportErrorForNode(HintCode.IS_NOT_DOUBLE, node, []); | 1902 _errorReporter.reportErrorForNode(HintCode.IS_NOT_DOUBLE, node); |
1903 } | 1903 } |
1904 return true; | 1904 return true; |
1905 } | 1905 } |
1906 } | 1906 } |
1907 return false; | 1907 return false; |
1908 } | 1908 } |
1909 } | 1909 } |
1910 | 1910 |
1911 /** | 1911 /** |
1912 * Instances of the class [UnusedLocalVariableVerifier] traverse an element | 1912 * Instances of the class [UnusedLocalVariableVerifier] traverse an element |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1956 sc.Token operator = node.operator; | 1956 sc.Token operator = node.operator; |
1957 bool isAmpAmp = operator.type == sc.TokenType.AMPERSAND_AMPERSAND; | 1957 bool isAmpAmp = operator.type == sc.TokenType.AMPERSAND_AMPERSAND; |
1958 bool isBarBar = operator.type == sc.TokenType.BAR_BAR; | 1958 bool isBarBar = operator.type == sc.TokenType.BAR_BAR; |
1959 if (isAmpAmp || isBarBar) { | 1959 if (isAmpAmp || isBarBar) { |
1960 Expression lhsCondition = node.leftOperand; | 1960 Expression lhsCondition = node.leftOperand; |
1961 if (!_isDebugConstant(lhsCondition)) { | 1961 if (!_isDebugConstant(lhsCondition)) { |
1962 EvaluationResultImpl lhsResult = _getConstantBooleanValue(lhsCondition); | 1962 EvaluationResultImpl lhsResult = _getConstantBooleanValue(lhsCondition); |
1963 if (lhsResult != null) { | 1963 if (lhsResult != null) { |
1964 if (lhsResult.value.isTrue && isBarBar) { | 1964 if (lhsResult.value.isTrue && isBarBar) { |
1965 // report error on else block: true || !e! | 1965 // report error on else block: true || !e! |
1966 _errorReporter.reportErrorForNode(HintCode.DEAD_CODE, node.rightOper
and, []); | 1966 _errorReporter.reportErrorForNode(HintCode.DEAD_CODE, node.rightOper
and); |
1967 // only visit the LHS: | 1967 // only visit the LHS: |
1968 _safelyVisit(lhsCondition); | 1968 _safelyVisit(lhsCondition); |
1969 return null; | 1969 return null; |
1970 } else if (lhsResult.value.isFalse && isAmpAmp) { | 1970 } else if (lhsResult.value.isFalse && isAmpAmp) { |
1971 // report error on if block: false && !e! | 1971 // report error on if block: false && !e! |
1972 _errorReporter.reportErrorForNode(HintCode.DEAD_CODE, node.rightOper
and, []); | 1972 _errorReporter.reportErrorForNode(HintCode.DEAD_CODE, node.rightOper
and); |
1973 // only visit the LHS: | 1973 // only visit the LHS: |
1974 _safelyVisit(lhsCondition); | 1974 _safelyVisit(lhsCondition); |
1975 return null; | 1975 return null; |
1976 } | 1976 } |
1977 } | 1977 } |
1978 } | 1978 } |
1979 // How do we want to handle the RHS? It isn't dead code, but "pointless" o
r "obscure"... | 1979 // How do we want to handle the RHS? It isn't dead code, but "pointless" o
r "obscure"... |
1980 // Expression rhsCondition = node.getRightOperand(); | 1980 // Expression rhsCondition = node.getRightOperand(); |
1981 // ValidResult rhsResult = getConstantBooleanValue(rhsCondition); | 1981 // ValidResult rhsResult = getConstantBooleanValue(rhsCondition); |
1982 // if (rhsResult != null) { | 1982 // if (rhsResult != null) { |
(...skipping 30 matching lines...) Expand all Loading... |
2013 | 2013 |
2014 @override | 2014 @override |
2015 Object visitConditionalExpression(ConditionalExpression node) { | 2015 Object visitConditionalExpression(ConditionalExpression node) { |
2016 Expression conditionExpression = node.condition; | 2016 Expression conditionExpression = node.condition; |
2017 _safelyVisit(conditionExpression); | 2017 _safelyVisit(conditionExpression); |
2018 if (!_isDebugConstant(conditionExpression)) { | 2018 if (!_isDebugConstant(conditionExpression)) { |
2019 EvaluationResultImpl result = _getConstantBooleanValue(conditionExpression
); | 2019 EvaluationResultImpl result = _getConstantBooleanValue(conditionExpression
); |
2020 if (result != null) { | 2020 if (result != null) { |
2021 if (result.value.isTrue) { | 2021 if (result.value.isTrue) { |
2022 // report error on else block: true ? 1 : !2! | 2022 // report error on else block: true ? 1 : !2! |
2023 _errorReporter.reportErrorForNode(HintCode.DEAD_CODE, node.elseExpress
ion, []); | 2023 _errorReporter.reportErrorForNode(HintCode.DEAD_CODE, node.elseExpress
ion); |
2024 _safelyVisit(node.thenExpression); | 2024 _safelyVisit(node.thenExpression); |
2025 return null; | 2025 return null; |
2026 } else { | 2026 } else { |
2027 // report error on if block: false ? !1! : 2 | 2027 // report error on if block: false ? !1! : 2 |
2028 _errorReporter.reportErrorForNode(HintCode.DEAD_CODE, node.thenExpress
ion, []); | 2028 _errorReporter.reportErrorForNode(HintCode.DEAD_CODE, node.thenExpress
ion); |
2029 _safelyVisit(node.elseExpression); | 2029 _safelyVisit(node.elseExpression); |
2030 return null; | 2030 return null; |
2031 } | 2031 } |
2032 } | 2032 } |
2033 } | 2033 } |
2034 return super.visitConditionalExpression(node); | 2034 return super.visitConditionalExpression(node); |
2035 } | 2035 } |
2036 | 2036 |
2037 @override | 2037 @override |
2038 Object visitIfStatement(IfStatement node) { | 2038 Object visitIfStatement(IfStatement node) { |
2039 Expression conditionExpression = node.condition; | 2039 Expression conditionExpression = node.condition; |
2040 _safelyVisit(conditionExpression); | 2040 _safelyVisit(conditionExpression); |
2041 if (!_isDebugConstant(conditionExpression)) { | 2041 if (!_isDebugConstant(conditionExpression)) { |
2042 EvaluationResultImpl result = _getConstantBooleanValue(conditionExpression
); | 2042 EvaluationResultImpl result = _getConstantBooleanValue(conditionExpression
); |
2043 if (result != null) { | 2043 if (result != null) { |
2044 if (result.value.isTrue) { | 2044 if (result.value.isTrue) { |
2045 // report error on else block: if(true) {} else {!} | 2045 // report error on else block: if(true) {} else {!} |
2046 Statement elseStatement = node.elseStatement; | 2046 Statement elseStatement = node.elseStatement; |
2047 if (elseStatement != null) { | 2047 if (elseStatement != null) { |
2048 _errorReporter.reportErrorForNode(HintCode.DEAD_CODE, elseStatement,
[]); | 2048 _errorReporter.reportErrorForNode(HintCode.DEAD_CODE, elseStatement)
; |
2049 _safelyVisit(node.thenStatement); | 2049 _safelyVisit(node.thenStatement); |
2050 return null; | 2050 return null; |
2051 } | 2051 } |
2052 } else { | 2052 } else { |
2053 // report error on if block: if (false) {!} else {} | 2053 // report error on if block: if (false) {!} else {} |
2054 _errorReporter.reportErrorForNode(HintCode.DEAD_CODE, node.thenStateme
nt, []); | 2054 _errorReporter.reportErrorForNode(HintCode.DEAD_CODE, node.thenStateme
nt); |
2055 _safelyVisit(node.elseStatement); | 2055 _safelyVisit(node.elseStatement); |
2056 return null; | 2056 return null; |
2057 } | 2057 } |
2058 } | 2058 } |
2059 } | 2059 } |
2060 return super.visitIfStatement(node); | 2060 return super.visitIfStatement(node); |
2061 } | 2061 } |
2062 | 2062 |
2063 @override | 2063 @override |
2064 Object visitSwitchCase(SwitchCase node) { | 2064 Object visitSwitchCase(SwitchCase node) { |
(...skipping 26 matching lines...) Expand all Loading... |
2091 // Found catch clause clause that has Object as an exception type, t
his is equivalent to | 2091 // Found catch clause clause that has Object as an exception type, t
his is equivalent to |
2092 // having a catch clause that doesn't have an exception type, visit
the block, but | 2092 // having a catch clause that doesn't have an exception type, visit
the block, but |
2093 // generate an error on any following catch clauses (and don't visi
t them). | 2093 // generate an error on any following catch clauses (and don't visi
t them). |
2094 _safelyVisit(catchClause); | 2094 _safelyVisit(catchClause); |
2095 if (i + 1 != numOfCatchClauses) { | 2095 if (i + 1 != numOfCatchClauses) { |
2096 // this catch clause is not the last in the try statement | 2096 // this catch clause is not the last in the try statement |
2097 CatchClause nextCatchClause = catchClauses[i + 1]; | 2097 CatchClause nextCatchClause = catchClauses[i + 1]; |
2098 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1]; | 2098 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1]; |
2099 int offset = nextCatchClause.offset; | 2099 int offset = nextCatchClause.offset; |
2100 int length = lastCatchClause.end - offset; | 2100 int length = lastCatchClause.end - offset; |
2101 _errorReporter.reportErrorForOffset(HintCode.DEAD_CODE_CATCH_FOLLO
WING_CATCH, offset, length, []); | 2101 _errorReporter.reportErrorForOffset(HintCode.DEAD_CODE_CATCH_FOLLO
WING_CATCH, offset, length); |
2102 return null; | 2102 return null; |
2103 } | 2103 } |
2104 } | 2104 } |
2105 for (DartType type in visitedTypes) { | 2105 for (DartType type in visitedTypes) { |
2106 if (currentType.isSubtypeOf(type)) { | 2106 if (currentType.isSubtypeOf(type)) { |
2107 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1]; | 2107 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1]; |
2108 int offset = catchClause.offset; | 2108 int offset = catchClause.offset; |
2109 int length = lastCatchClause.end - offset; | 2109 int length = lastCatchClause.end - offset; |
2110 _errorReporter.reportErrorForOffset(HintCode.DEAD_CODE_ON_CATCH_SU
BTYPE, offset, length, [currentType.displayName, type.displayName]); | 2110 _errorReporter.reportErrorForOffset(HintCode.DEAD_CODE_ON_CATCH_SU
BTYPE, offset, length, [currentType.displayName, type.displayName]); |
2111 return null; | 2111 return null; |
2112 } | 2112 } |
2113 } | 2113 } |
2114 visitedTypes.add(currentType); | 2114 visitedTypes.add(currentType); |
2115 } | 2115 } |
2116 _safelyVisit(catchClause); | 2116 _safelyVisit(catchClause); |
2117 } else { | 2117 } else { |
2118 // Found catch clause clause that doesn't have an exception type, visit
the block, but | 2118 // Found catch clause clause that doesn't have an exception type, visit
the block, but |
2119 // generate an error on any following catch clauses (and don't visit the
m). | 2119 // generate an error on any following catch clauses (and don't visit the
m). |
2120 _safelyVisit(catchClause); | 2120 _safelyVisit(catchClause); |
2121 if (i + 1 != numOfCatchClauses) { | 2121 if (i + 1 != numOfCatchClauses) { |
2122 // this catch clause is not the last in the try statement | 2122 // this catch clause is not the last in the try statement |
2123 CatchClause nextCatchClause = catchClauses[i + 1]; | 2123 CatchClause nextCatchClause = catchClauses[i + 1]; |
2124 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1]; | 2124 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1]; |
2125 int offset = nextCatchClause.offset; | 2125 int offset = nextCatchClause.offset; |
2126 int length = lastCatchClause.end - offset; | 2126 int length = lastCatchClause.end - offset; |
2127 _errorReporter.reportErrorForOffset(HintCode.DEAD_CODE_CATCH_FOLLOWING
_CATCH, offset, length, []); | 2127 _errorReporter.reportErrorForOffset(HintCode.DEAD_CODE_CATCH_FOLLOWING
_CATCH, offset, length); |
2128 return null; | 2128 return null; |
2129 } | 2129 } |
2130 } | 2130 } |
2131 } | 2131 } |
2132 return null; | 2132 return null; |
2133 } | 2133 } |
2134 | 2134 |
2135 @override | 2135 @override |
2136 Object visitWhileStatement(WhileStatement node) { | 2136 Object visitWhileStatement(WhileStatement node) { |
2137 Expression conditionExpression = node.condition; | 2137 Expression conditionExpression = node.condition; |
2138 _safelyVisit(conditionExpression); | 2138 _safelyVisit(conditionExpression); |
2139 if (!_isDebugConstant(conditionExpression)) { | 2139 if (!_isDebugConstant(conditionExpression)) { |
2140 EvaluationResultImpl result = _getConstantBooleanValue(conditionExpression
); | 2140 EvaluationResultImpl result = _getConstantBooleanValue(conditionExpression
); |
2141 if (result != null) { | 2141 if (result != null) { |
2142 if (result.value.isFalse) { | 2142 if (result.value.isFalse) { |
2143 // report error on if block: while (false) {!} | 2143 // report error on if block: while (false) {!} |
2144 _errorReporter.reportErrorForNode(HintCode.DEAD_CODE, node.body, []); | 2144 _errorReporter.reportErrorForNode(HintCode.DEAD_CODE, node.body); |
2145 return null; | 2145 return null; |
2146 } | 2146 } |
2147 } | 2147 } |
2148 } | 2148 } |
2149 _safelyVisit(node.body); | 2149 _safelyVisit(node.body); |
2150 return null; | 2150 return null; |
2151 } | 2151 } |
2152 | 2152 |
2153 /** | 2153 /** |
2154 * Given some [NodeList] of [Statement]s, from either a [Block] or | 2154 * Given some [NodeList] of [Statement]s, from either a [Block] or |
2155 * [SwitchMember], this loops through the list in reverse order searching for
statements | 2155 * [SwitchMember], this loops through the list in reverse order searching for
statements |
2156 * after a return, unlabeled break or unlabeled continue statement to mark the
m as dead code. | 2156 * after a return, unlabeled break or unlabeled continue statement to mark the
m as dead code. |
2157 * | 2157 * |
2158 * @param statements some ordered list of statements in a [Block] or [SwitchMe
mber] | 2158 * @param statements some ordered list of statements in a [Block] or [SwitchMe
mber] |
2159 */ | 2159 */ |
2160 void _checkForDeadStatementsInNodeList(NodeList<Statement> statements) { | 2160 void _checkForDeadStatementsInNodeList(NodeList<Statement> statements) { |
2161 int size = statements.length; | 2161 int size = statements.length; |
2162 for (int i = 0; i < size; i++) { | 2162 for (int i = 0; i < size; i++) { |
2163 Statement currentStatement = statements[i]; | 2163 Statement currentStatement = statements[i]; |
2164 _safelyVisit(currentStatement); | 2164 _safelyVisit(currentStatement); |
2165 bool returnOrBreakingStatement = currentStatement is ReturnStatement || (c
urrentStatement is BreakStatement && currentStatement.label == null) || (current
Statement is ContinueStatement && currentStatement.label == null); | 2165 bool returnOrBreakingStatement = currentStatement is ReturnStatement || (c
urrentStatement is BreakStatement && currentStatement.label == null) || (current
Statement is ContinueStatement && currentStatement.label == null); |
2166 if (returnOrBreakingStatement && i != size - 1) { | 2166 if (returnOrBreakingStatement && i != size - 1) { |
2167 Statement nextStatement = statements[i + 1]; | 2167 Statement nextStatement = statements[i + 1]; |
2168 Statement lastStatement = statements[size - 1]; | 2168 Statement lastStatement = statements[size - 1]; |
2169 int offset = nextStatement.offset; | 2169 int offset = nextStatement.offset; |
2170 int length = lastStatement.end - offset; | 2170 int length = lastStatement.end - offset; |
2171 _errorReporter.reportErrorForOffset(HintCode.DEAD_CODE, offset, length,
[]); | 2171 _errorReporter.reportErrorForOffset(HintCode.DEAD_CODE, offset, length); |
2172 return; | 2172 return; |
2173 } | 2173 } |
2174 } | 2174 } |
2175 } | 2175 } |
2176 | 2176 |
2177 /** | 2177 /** |
2178 * Given some [Expression], this method returns [ValidResult.RESULT_TRUE] if i
t is | 2178 * Given some [Expression], this method returns [ValidResult.RESULT_TRUE] if i
t is |
2179 * `true`, [ValidResult.RESULT_FALSE] if it is `false`, or `null` if the | 2179 * `true`, [ValidResult.RESULT_FALSE] if it is `false`, or `null` if the |
2180 * expression is not a constant boolean value. | 2180 * expression is not a constant boolean value. |
2181 * | 2181 * |
2182 * @param expression the expression to evaluate | 2182 * @param expression the expression to evaluate |
2183 * @return [ValidResult.RESULT_TRUE] if it is `true`, [ValidResult.RESULT_FALS
E] | 2183 * @return [ValidResult.RESULT_TRUE] if it is `true`, [ValidResult.RESULT_FALS
E] |
2184 * if it is `false`, or `null` if the expression is not a constant boo
lean | 2184 * if it is `false`, or `null` if the expression is not a constant boo
lean |
2185 * value | 2185 * value |
2186 */ | 2186 */ |
2187 EvaluationResultImpl _getConstantBooleanValue(Expression expression) { | 2187 EvaluationResultImpl _getConstantBooleanValue(Expression expression) { |
2188 if (expression is BooleanLiteral) { | 2188 if (expression is BooleanLiteral) { |
2189 if (expression.value) { | 2189 if (expression.value) { |
2190 return new EvaluationResultImpl.con1(new DartObjectImpl(null, BoolState.
from(true))); | 2190 return new EvaluationResultImpl.con1(new DartObjectImpl(null, BoolState.
from(true))); |
2191 } else { | 2191 } else { |
2192 return new EvaluationResultImpl.con1(new DartObjectImpl(null, BoolState.
from(false))); | 2192 return new EvaluationResultImpl.con1(new DartObjectImpl(null, BoolState.
from(false))); |
2193 } | 2193 } |
2194 } | 2194 } |
2195 // Don't consider situations where we could evaluate to a constant boolean e
xpression with the | 2195 // Don't consider situations where we could evaluate to a constant boolean |
2196 // ConstantVisitor | 2196 // expression with the ConstantVisitor |
2197 // | |
2198 // else { | 2197 // else { |
2199 // | |
2200 // EvaluationResultImpl result = expression.accept(new ConstantVisitor(
)); | 2198 // EvaluationResultImpl result = expression.accept(new ConstantVisitor(
)); |
2201 // | |
2202 // if (result == ValidResult.RESULT_TRUE) { | 2199 // if (result == ValidResult.RESULT_TRUE) { |
2203 // | |
2204 // return ValidResult.RESULT_TRUE; | 2200 // return ValidResult.RESULT_TRUE; |
2205 // | |
2206 // } else if (result == ValidResult.RESULT_FALSE) { | 2201 // } else if (result == ValidResult.RESULT_FALSE) { |
2207 // | |
2208 // return ValidResult.RESULT_FALSE; | 2202 // return ValidResult.RESULT_FALSE; |
2209 // | |
2210 // } | 2203 // } |
2211 // | |
2212 // return null; | 2204 // return null; |
2213 // | |
2214 // } | 2205 // } |
2215 return null; | 2206 return null; |
2216 } | 2207 } |
2217 | 2208 |
2218 /** | 2209 /** |
2219 * Return `true` if and only if the passed expression is resolved to a constan
t variable. | 2210 * Return `true` if and only if the passed expression is resolved to a constan
t variable. |
2220 * | 2211 * |
2221 * @param expression some conditional expression | 2212 * @param expression some conditional expression |
2222 * @return `true` if and only if the passed expression is resolved to a consta
nt variable | 2213 * @return `true` if and only if the passed expression is resolved to a consta
nt variable |
2223 */ | 2214 */ |
(...skipping 3701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5925 /** | 5916 /** |
5926 * Any time after the defining compilation unit has been visited by this visit
or, this method can | 5917 * Any time after the defining compilation unit has been visited by this visit
or, this method can |
5927 * be called to report an [HintCode.DUPLICATE_IMPORT] hint for each of the imp
ort directives | 5918 * be called to report an [HintCode.DUPLICATE_IMPORT] hint for each of the imp
ort directives |
5928 * in the [duplicateImports] list. | 5919 * in the [duplicateImports] list. |
5929 * | 5920 * |
5930 * @param errorReporter the error reporter to report the set of [HintCode.DUPL
ICATE_IMPORT] | 5921 * @param errorReporter the error reporter to report the set of [HintCode.DUPL
ICATE_IMPORT] |
5931 * hints to | 5922 * hints to |
5932 */ | 5923 */ |
5933 void generateDuplicateImportHints(ErrorReporter errorReporter) { | 5924 void generateDuplicateImportHints(ErrorReporter errorReporter) { |
5934 for (ImportDirective duplicateImport in _duplicateImports) { | 5925 for (ImportDirective duplicateImport in _duplicateImports) { |
5935 errorReporter.reportErrorForNode(HintCode.DUPLICATE_IMPORT, duplicateImpor
t.uri, []); | 5926 errorReporter.reportErrorForNode(HintCode.DUPLICATE_IMPORT, duplicateImpor
t.uri); |
5936 } | 5927 } |
5937 } | 5928 } |
5938 | 5929 |
5939 /** | 5930 /** |
5940 * After all of the compilation units have been visited by this visitor, this
method can be called | 5931 * After all of the compilation units have been visited by this visitor, this
method can be called |
5941 * to report an [HintCode.UNUSED_IMPORT] hint for each of the import directive
s in the | 5932 * to report an [HintCode.UNUSED_IMPORT] hint for each of the import directive
s in the |
5942 * [unusedImports] list. | 5933 * [unusedImports] list. |
5943 * | 5934 * |
5944 * @param errorReporter the error reporter to report the set of [HintCode.UNUS
ED_IMPORT] | 5935 * @param errorReporter the error reporter to report the set of [HintCode.UNUS
ED_IMPORT] |
5945 * hints to | 5936 * hints to |
5946 */ | 5937 */ |
5947 void generateUnusedImportHints(ErrorReporter errorReporter) { | 5938 void generateUnusedImportHints(ErrorReporter errorReporter) { |
5948 for (ImportDirective unusedImport in _unusedImports) { | 5939 for (ImportDirective unusedImport in _unusedImports) { |
5949 // Check that the import isn't dart:core | 5940 // Check that the import isn't dart:core |
5950 ImportElement importElement = unusedImport.element; | 5941 ImportElement importElement = unusedImport.element; |
5951 if (importElement != null) { | 5942 if (importElement != null) { |
5952 LibraryElement libraryElement = importElement.importedLibrary; | 5943 LibraryElement libraryElement = importElement.importedLibrary; |
5953 if (libraryElement != null && libraryElement.isDartCore) { | 5944 if (libraryElement != null && libraryElement.isDartCore) { |
5954 continue; | 5945 continue; |
5955 } | 5946 } |
5956 } | 5947 } |
5957 errorReporter.reportErrorForNode(HintCode.UNUSED_IMPORT, unusedImport.uri,
[]); | 5948 errorReporter.reportErrorForNode(HintCode.UNUSED_IMPORT, unusedImport.uri)
; |
5958 } | 5949 } |
5959 } | 5950 } |
5960 | 5951 |
5961 @override | 5952 @override |
5962 Object visitCompilationUnit(CompilationUnit node) { | 5953 Object visitCompilationUnit(CompilationUnit node) { |
5963 if (_inDefiningCompilationUnit) { | 5954 if (_inDefiningCompilationUnit) { |
5964 NodeList<Directive> directives = node.directives; | 5955 NodeList<Directive> directives = node.directives; |
5965 for (Directive directive in directives) { | 5956 for (Directive directive in directives) { |
5966 if (directive is ImportDirective) { | 5957 if (directive is ImportDirective) { |
5967 ImportDirective importDirective = directive; | 5958 ImportDirective importDirective = directive; |
(...skipping 1579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7547 /** | 7538 /** |
7548 * Return the result of resolving the URI of the given URI-based directive aga
inst the URI of the | 7539 * Return the result of resolving the URI of the given URI-based directive aga
inst the URI of the |
7549 * library, or `null` if the URI is not valid. If the URI is not valid, report
the error. | 7540 * library, or `null` if the URI is not valid. If the URI is not valid, report
the error. |
7550 * | 7541 * |
7551 * @param directive the directive which URI should be resolved | 7542 * @param directive the directive which URI should be resolved |
7552 * @return the result of resolving the URI against the URI of the library | 7543 * @return the result of resolving the URI against the URI of the library |
7553 */ | 7544 */ |
7554 Source getSource(UriBasedDirective directive) { | 7545 Source getSource(UriBasedDirective directive) { |
7555 StringLiteral uriLiteral = directive.uri; | 7546 StringLiteral uriLiteral = directive.uri; |
7556 if (uriLiteral is StringInterpolation) { | 7547 if (uriLiteral is StringInterpolation) { |
7557 _errorListener.onError(new AnalysisError.con2(librarySource, uriLiteral.of
fset, uriLiteral.length, CompileTimeErrorCode.URI_WITH_INTERPOLATION, [])); | 7548 _errorListener.onError(new AnalysisError.con2(librarySource, uriLiteral.of
fset, uriLiteral.length, CompileTimeErrorCode.URI_WITH_INTERPOLATION)); |
7558 return null; | 7549 return null; |
7559 } | 7550 } |
7560 String uriContent = uriLiteral.stringValue.trim(); | 7551 String uriContent = uriLiteral.stringValue.trim(); |
7561 _directiveUris[directive] = uriContent; | 7552 _directiveUris[directive] = uriContent; |
7562 uriContent = Uri.encodeFull(uriContent); | 7553 uriContent = Uri.encodeFull(uriContent); |
7563 if (directive is ImportDirective && uriContent.startsWith(_DART_EXT_SCHEME))
{ | 7554 if (directive is ImportDirective && uriContent.startsWith(_DART_EXT_SCHEME))
{ |
7564 _libraryElement.hasExtUri = true; | 7555 _libraryElement.hasExtUri = true; |
7565 return null; | 7556 return null; |
7566 } | 7557 } |
7567 try { | 7558 try { |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7710 } | 7701 } |
7711 if (entryPoint == null) { | 7702 if (entryPoint == null) { |
7712 entryPoint = _findEntryPoint(part); | 7703 entryPoint = _findEntryPoint(part); |
7713 } | 7704 } |
7714 directive.element = part; | 7705 directive.element = part; |
7715 sourcedCompilationUnits.add(part); | 7706 sourcedCompilationUnits.add(part); |
7716 } | 7707 } |
7717 } | 7708 } |
7718 } | 7709 } |
7719 if (hasPartDirective && libraryNameNode == null) { | 7710 if (hasPartDirective && libraryNameNode == null) { |
7720 _errorListener.onError(new AnalysisError.con1(librarySource, ResolverError
Code.MISSING_LIBRARY_DIRECTIVE_WITH_PART, [])); | 7711 _errorListener.onError(new AnalysisError.con1(librarySource, ResolverError
Code.MISSING_LIBRARY_DIRECTIVE_WITH_PART)); |
7721 } | 7712 } |
7722 // | 7713 // |
7723 // Create and populate the library element. | 7714 // Create and populate the library element. |
7724 // | 7715 // |
7725 LibraryElementImpl libraryElement = new LibraryElementImpl.forNode(_analysis
Context.getContextFor(librarySource), libraryNameNode); | 7716 LibraryElementImpl libraryElement = new LibraryElementImpl.forNode(_analysis
Context.getContextFor(librarySource), libraryNameNode); |
7726 libraryElement.definingCompilationUnit = definingCompilationUnitElement; | 7717 libraryElement.definingCompilationUnit = definingCompilationUnitElement; |
7727 if (entryPoint != null) { | 7718 if (entryPoint != null) { |
7728 libraryElement.entryPoint = entryPoint; | 7719 libraryElement.entryPoint = entryPoint; |
7729 } | 7720 } |
7730 int sourcedUnitCount = sourcedCompilationUnits.length; | 7721 int sourcedUnitCount = sourcedCompilationUnits.length; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7798 if (entryPoint == null) { | 7789 if (entryPoint == null) { |
7799 entryPoint = _findEntryPoint(part); | 7790 entryPoint = _findEntryPoint(part); |
7800 } | 7791 } |
7801 directive.element = part; | 7792 directive.element = part; |
7802 sourcedCompilationUnits.add(part); | 7793 sourcedCompilationUnits.add(part); |
7803 } | 7794 } |
7804 } | 7795 } |
7805 } | 7796 } |
7806 } | 7797 } |
7807 if (hasPartDirective && libraryNameNode == null) { | 7798 if (hasPartDirective && libraryNameNode == null) { |
7808 _errorListener.onError(new AnalysisError.con1(librarySource, ResolverError
Code.MISSING_LIBRARY_DIRECTIVE_WITH_PART, [])); | 7799 _errorListener.onError(new AnalysisError.con1(librarySource, ResolverError
Code.MISSING_LIBRARY_DIRECTIVE_WITH_PART)); |
7809 } | 7800 } |
7810 // | 7801 // |
7811 // Create and populate the library element. | 7802 // Create and populate the library element. |
7812 // | 7803 // |
7813 LibraryElementImpl libraryElement = new LibraryElementImpl.forNode(_analysis
Context.getContextFor(librarySource), libraryNameNode); | 7804 LibraryElementImpl libraryElement = new LibraryElementImpl.forNode(_analysis
Context.getContextFor(librarySource), libraryNameNode); |
7814 libraryElement.definingCompilationUnit = definingCompilationUnitElement; | 7805 libraryElement.definingCompilationUnit = definingCompilationUnitElement; |
7815 if (entryPoint != null) { | 7806 if (entryPoint != null) { |
7816 libraryElement.entryPoint = entryPoint; | 7807 libraryElement.entryPoint = entryPoint; |
7817 } | 7808 } |
7818 int sourcedUnitCount = sourcedCompilationUnits.length; | 7809 int sourcedUnitCount = sourcedCompilationUnits.length; |
(...skipping 2189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10008 * @param errorReporter the error reporter used to report errors | 9999 * @param errorReporter the error reporter used to report errors |
10009 */ | 10000 */ |
10010 OverrideVerifier(this._manager, this._errorReporter); | 10001 OverrideVerifier(this._manager, this._errorReporter); |
10011 | 10002 |
10012 @override | 10003 @override |
10013 Object visitMethodDeclaration(MethodDeclaration node) { | 10004 Object visitMethodDeclaration(MethodDeclaration node) { |
10014 ExecutableElement element = node.element; | 10005 ExecutableElement element = node.element; |
10015 if (_isOverride(element)) { | 10006 if (_isOverride(element)) { |
10016 if (_getOverriddenMember(element) == null) { | 10007 if (_getOverriddenMember(element) == null) { |
10017 if (element is MethodElement) { | 10008 if (element is MethodElement) { |
10018 _errorReporter.reportErrorForNode(HintCode.OVERRIDE_ON_NON_OVERRIDING_
METHOD, node.name, []); | 10009 _errorReporter.reportErrorForNode(HintCode.OVERRIDE_ON_NON_OVERRIDING_
METHOD, node.name); |
10019 } else if (element is PropertyAccessorElement) { | 10010 } else if (element is PropertyAccessorElement) { |
10020 if (element.isGetter) { | 10011 if (element.isGetter) { |
10021 _errorReporter.reportErrorForNode(HintCode.OVERRIDE_ON_NON_OVERRIDIN
G_GETTER, node.name, []); | 10012 _errorReporter.reportErrorForNode(HintCode.OVERRIDE_ON_NON_OVERRIDIN
G_GETTER, node.name); |
10022 } else { | 10013 } else { |
10023 _errorReporter.reportErrorForNode(HintCode.OVERRIDE_ON_NON_OVERRIDIN
G_SETTER, node.name, []); | 10014 _errorReporter.reportErrorForNode(HintCode.OVERRIDE_ON_NON_OVERRIDIN
G_SETTER, node.name); |
10024 } | 10015 } |
10025 } | 10016 } |
10026 } | 10017 } |
10027 } | 10018 } |
10028 return super.visitMethodDeclaration(node); | 10019 return super.visitMethodDeclaration(node); |
10029 } | 10020 } |
10030 | 10021 |
10031 /** | 10022 /** |
10032 * Return the member that overrides the given member. | 10023 * Return the member that overrides the given member. |
10033 * | 10024 * |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10205 fullNameIndex = JavaString.lastIndexOf(fullName, '/', fullNameIndex); | 10196 fullNameIndex = JavaString.lastIndexOf(fullName, '/', fullNameIndex); |
10206 if (fullNameIndex < 4) { | 10197 if (fullNameIndex < 4) { |
10207 return false; | 10198 return false; |
10208 } | 10199 } |
10209 // Check for "/lib" at a specified place in the fullName | 10200 // Check for "/lib" at a specified place in the fullName |
10210 if (StringUtilities.startsWith4(fullName, fullNameIndex - 4, 0x2F, 0x6C,
0x69, 0x62)) { | 10201 if (StringUtilities.startsWith4(fullName, fullNameIndex - 4, 0x2F, 0x6C,
0x69, 0x62)) { |
10211 String relativePubspecPath = path.substring(0, pathIndex + 3) + _PUBSP
EC_YAML; | 10202 String relativePubspecPath = path.substring(0, pathIndex + 3) + _PUBSP
EC_YAML; |
10212 Source pubspecSource = _context.sourceFactory.resolveUri(source, relat
ivePubspecPath); | 10203 Source pubspecSource = _context.sourceFactory.resolveUri(source, relat
ivePubspecPath); |
10213 if (_context.exists(pubspecSource)) { | 10204 if (_context.exists(pubspecSource)) { |
10214 // Files inside the lib directory hierarchy should not reference fil
es outside | 10205 // Files inside the lib directory hierarchy should not reference fil
es outside |
10215 _errorReporter.reportErrorForNode(HintCode.FILE_IMPORT_INSIDE_LIB_RE
FERENCES_FILE_OUTSIDE, uriLiteral, []); | 10206 _errorReporter.reportErrorForNode(HintCode.FILE_IMPORT_INSIDE_LIB_RE
FERENCES_FILE_OUTSIDE, uriLiteral); |
10216 } | 10207 } |
10217 return true; | 10208 return true; |
10218 } | 10209 } |
10219 pathIndex += 3; | 10210 pathIndex += 3; |
10220 } | 10211 } |
10221 } | 10212 } |
10222 return false; | 10213 return false; |
10223 } | 10214 } |
10224 | 10215 |
10225 /** | 10216 /** |
(...skipping 27 matching lines...) Expand all Loading... |
10253 String relativePubspecPath = path.substring(0, pathIndex) + _PUBSPEC_YAML; | 10244 String relativePubspecPath = path.substring(0, pathIndex) + _PUBSPEC_YAML; |
10254 Source pubspecSource = _context.sourceFactory.resolveUri(source, relativePub
specPath); | 10245 Source pubspecSource = _context.sourceFactory.resolveUri(source, relativePub
specPath); |
10255 if (!_context.exists(pubspecSource)) { | 10246 if (!_context.exists(pubspecSource)) { |
10256 return false; | 10247 return false; |
10257 } | 10248 } |
10258 String fullName = _getSourceFullName(source); | 10249 String fullName = _getSourceFullName(source); |
10259 if (fullName != null) { | 10250 if (fullName != null) { |
10260 if (StringUtilities.indexOf5(fullName, 0, 0x2F, 0x6C, 0x69, 0x62, 0x2F) <
0) { | 10251 if (StringUtilities.indexOf5(fullName, 0, 0x2F, 0x6C, 0x69, 0x62, 0x2F) <
0) { |
10261 // Files outside the lib directory hierarchy should not reference files
inside | 10252 // Files outside the lib directory hierarchy should not reference files
inside |
10262 // ... use package: url instead | 10253 // ... use package: url instead |
10263 _errorReporter.reportErrorForNode(HintCode.FILE_IMPORT_OUTSIDE_LIB_REFER
ENCES_FILE_INSIDE, uriLiteral, []); | 10254 _errorReporter.reportErrorForNode(HintCode.FILE_IMPORT_OUTSIDE_LIB_REFER
ENCES_FILE_INSIDE, uriLiteral); |
10264 return true; | 10255 return true; |
10265 } | 10256 } |
10266 } | 10257 } |
10267 return false; | 10258 return false; |
10268 } | 10259 } |
10269 | 10260 |
10270 /** | 10261 /** |
10271 * This verifies that the passed package import directive does not contain "..
" | 10262 * This verifies that the passed package import directive does not contain "..
" |
10272 * | 10263 * |
10273 * @param uriLiteral the import URL (not `null`) | 10264 * @param uriLiteral the import URL (not `null`) |
10274 * @param path the path to be validated (not `null`) | 10265 * @param path the path to be validated (not `null`) |
10275 * @return `true` if and only if an error code is generated on the passed node | 10266 * @return `true` if and only if an error code is generated on the passed node |
10276 * See [PubSuggestionCode.PACKAGE_IMPORT_CONTAINS_DOT_DOT]. | 10267 * See [PubSuggestionCode.PACKAGE_IMPORT_CONTAINS_DOT_DOT]. |
10277 */ | 10268 */ |
10278 bool _checkForPackageImportContainsDotDot(StringLiteral uriLiteral, String pat
h) { | 10269 bool _checkForPackageImportContainsDotDot(StringLiteral uriLiteral, String pat
h) { |
10279 if (StringUtilities.startsWith3(path, 0, 0x2E, 0x2E, 0x2F) || StringUtilitie
s.indexOf4(path, 0, 0x2F, 0x2E, 0x2E, 0x2F) >= 0) { | 10270 if (StringUtilities.startsWith3(path, 0, 0x2E, 0x2E, 0x2F) || StringUtilitie
s.indexOf4(path, 0, 0x2F, 0x2E, 0x2E, 0x2F) >= 0) { |
10280 // Package import should not to contain ".." | 10271 // Package import should not to contain ".." |
10281 _errorReporter.reportErrorForNode(HintCode.PACKAGE_IMPORT_CONTAINS_DOT_DOT
, uriLiteral, []); | 10272 _errorReporter.reportErrorForNode(HintCode.PACKAGE_IMPORT_CONTAINS_DOT_DOT
, uriLiteral); |
10282 return true; | 10273 return true; |
10283 } | 10274 } |
10284 return false; | 10275 return false; |
10285 } | 10276 } |
10286 | 10277 |
10287 /** | 10278 /** |
10288 * Answer the source associated with the compilation unit containing the given
AST node. | 10279 * Answer the source associated with the compilation unit containing the given
AST node. |
10289 * | 10280 * |
10290 * @param node the node (not `null`) | 10281 * @param node the node (not `null`) |
10291 * @return the source or `null` if it could not be determined | 10282 * @return the source or `null` if it could not be determined |
(...skipping 2638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12930 */ | 12921 */ |
12931 Scope get nameScope => _nameScope; | 12922 Scope get nameScope => _nameScope; |
12932 | 12923 |
12933 /** | 12924 /** |
12934 * Report an error with the given error code and arguments. | 12925 * Report an error with the given error code and arguments. |
12935 * | 12926 * |
12936 * @param errorCode the error code of the error to be reported | 12927 * @param errorCode the error code of the error to be reported |
12937 * @param node the node specifying the location of the error | 12928 * @param node the node specifying the location of the error |
12938 * @param arguments the arguments to the error, used to compose the error mess
age | 12929 * @param arguments the arguments to the error, used to compose the error mess
age |
12939 */ | 12930 */ |
12940 void reportErrorForNode(ErrorCode errorCode, AstNode node, List<Object> argume
nts) { | 12931 void reportErrorForNode(ErrorCode errorCode, AstNode node, [List<Object> argum
ents]) { |
12941 _errorListener.onError(new AnalysisError.con2(source, node.offset, node.leng
th, errorCode, arguments)); | 12932 _errorListener.onError(new AnalysisError.con2(source, node.offset, node.leng
th, errorCode, arguments)); |
12942 } | 12933 } |
12943 | 12934 |
12944 /** | 12935 /** |
12945 * Report an error with the given error code and arguments. | 12936 * Report an error with the given error code and arguments. |
12946 * | 12937 * |
12947 * @param errorCode the error code of the error to be reported | 12938 * @param errorCode the error code of the error to be reported |
12948 * @param offset the offset of the location of the error | 12939 * @param offset the offset of the location of the error |
12949 * @param length the length of the location of the error | 12940 * @param length the length of the location of the error |
12950 * @param arguments the arguments to the error, used to compose the error mess
age | 12941 * @param arguments the arguments to the error, used to compose the error mess
age |
12951 */ | 12942 */ |
12952 void reportErrorForOffset(ErrorCode errorCode, int offset, int length, List<Ob
ject> arguments) { | 12943 void reportErrorForOffset(ErrorCode errorCode, int offset, int length, [List<O
bject> arguments]) { |
12953 _errorListener.onError(new AnalysisError.con2(source, offset, length, errorC
ode, arguments)); | 12944 _errorListener.onError(new AnalysisError.con2(source, offset, length, errorC
ode, arguments)); |
12954 } | 12945 } |
12955 | 12946 |
12956 /** | 12947 /** |
12957 * Report an error with the given error code and arguments. | 12948 * Report an error with the given error code and arguments. |
12958 * | 12949 * |
12959 * @param errorCode the error code of the error to be reported | 12950 * @param errorCode the error code of the error to be reported |
12960 * @param token the token specifying the location of the error | 12951 * @param token the token specifying the location of the error |
12961 * @param arguments the arguments to the error, used to compose the error mess
age | 12952 * @param arguments the arguments to the error, used to compose the error mess
age |
12962 */ | 12953 */ |
12963 void reportErrorForToken(ErrorCode errorCode, sc.Token token, List<Object> arg
uments) { | 12954 void reportErrorForToken(ErrorCode errorCode, sc.Token token, [List<Object> ar
guments]) { |
12964 _errorListener.onError(new AnalysisError.con2(source, token.offset, token.le
ngth, errorCode, arguments)); | 12955 _errorListener.onError(new AnalysisError.con2(source, token.offset, token.le
ngth, errorCode, arguments)); |
12965 } | 12956 } |
12966 | 12957 |
12967 /** | 12958 /** |
12968 * Visit the given AST node if it is not null. | 12959 * Visit the given AST node if it is not null. |
12969 * | 12960 * |
12970 * @param node the node to be visited | 12961 * @param node the node to be visited |
12971 */ | 12962 */ |
12972 void safelyVisit(AstNode node) { | 12963 void safelyVisit(AstNode node) { |
12973 if (node != null) { | 12964 if (node != null) { |
(...skipping 2073 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15047 * a type | 15038 * a type |
15048 * @param enumTypeError the error to produce if the type name is defined to be
an enum | 15039 * @param enumTypeError the error to produce if the type name is defined to be
an enum |
15049 * @param dynamicTypeError the error to produce if the type name is "dynamic" | 15040 * @param dynamicTypeError the error to produce if the type name is "dynamic" |
15050 * @return the type specified by the type name | 15041 * @return the type specified by the type name |
15051 */ | 15042 */ |
15052 InterfaceType _resolveType(TypeName typeName, ErrorCode nonTypeError, ErrorCod
e enumTypeError, ErrorCode dynamicTypeError) { | 15043 InterfaceType _resolveType(TypeName typeName, ErrorCode nonTypeError, ErrorCod
e enumTypeError, ErrorCode dynamicTypeError) { |
15053 DartType type = typeName.type; | 15044 DartType type = typeName.type; |
15054 if (type is InterfaceType) { | 15045 if (type is InterfaceType) { |
15055 ClassElement element = type.element; | 15046 ClassElement element = type.element; |
15056 if (element != null && element.isEnum) { | 15047 if (element != null && element.isEnum) { |
15057 reportErrorForNode(enumTypeError, typeName, []); | 15048 reportErrorForNode(enumTypeError, typeName); |
15058 return null; | 15049 return null; |
15059 } | 15050 } |
15060 return type; | 15051 return type; |
15061 } | 15052 } |
15062 // If the type is not an InterfaceType, then visitTypeName() sets the type t
o be a DynamicTypeImpl | 15053 // If the type is not an InterfaceType, then visitTypeName() sets the type t
o be a DynamicTypeImpl |
15063 Identifier name = typeName.name; | 15054 Identifier name = typeName.name; |
15064 if (name.name == sc.Keyword.DYNAMIC.syntax) { | 15055 if (name.name == sc.Keyword.DYNAMIC.syntax) { |
15065 reportErrorForNode(dynamicTypeError, name, [name.name]); | 15056 reportErrorForNode(dynamicTypeError, name, [name.name]); |
15066 } else { | 15057 } else { |
15067 reportErrorForNode(nonTypeError, name, [name.name]); | 15058 reportErrorForNode(nonTypeError, name, [name.name]); |
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15531 /** | 15522 /** |
15532 * Return the tag that has the given identifier, or {@code null} if there is n
o such tag (the | 15523 * Return the tag that has the given identifier, or {@code null} if there is n
o such tag (the |
15533 * identifier is not defined). | 15524 * identifier is not defined). |
15534 * | 15525 * |
15535 * @return the tag that has the given identifier | 15526 * @return the tag that has the given identifier |
15536 */ | 15527 */ |
15537 String getTagWithId(String identifier) { | 15528 String getTagWithId(String identifier) { |
15538 return idToTagMap[identifier]; | 15529 return idToTagMap[identifier]; |
15539 } | 15530 } |
15540 } | 15531 } |
OLD | NEW |