| 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 analyzer.src.generated.incremental_resolution_validator; | 5 library analyzer.src.generated.incremental_resolution_validator; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
| 8 import 'package:analyzer/dart/element/element.dart'; | 8 import 'package:analyzer/dart/element/element.dart'; |
| 9 import 'package:analyzer/dart/element/type.dart'; | 9 import 'package:analyzer/dart/element/type.dart'; |
| 10 import 'package:analyzer/src/dart/element/element.dart'; | 10 import 'package:analyzer/src/dart/element/element.dart'; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 final String message; | 29 final String message; |
| 30 IncrementalResolutionMismatch(this.message); | 30 IncrementalResolutionMismatch(this.message); |
| 31 | 31 |
| 32 @override | 32 @override |
| 33 String toString() => "IncrementalResolutionMismatch: $message"; | 33 String toString() => "IncrementalResolutionMismatch: $message"; |
| 34 } | 34 } |
| 35 | 35 |
| 36 class _SameResolutionValidator implements AstVisitor { | 36 class _SameResolutionValidator implements AstVisitor { |
| 37 final bool validateTypes; | 37 final bool validateTypes; |
| 38 | 38 |
| 39 /// The expected node to compare with the visted node. | 39 /// The expected node to compare with the visited node. |
| 40 AstNode other; | 40 AstNode other; |
| 41 | 41 |
| 42 _SameResolutionValidator(this.validateTypes, this.other); | 42 _SameResolutionValidator(this.validateTypes, this.other); |
| 43 | 43 |
| 44 @override | 44 @override |
| 45 visitAdjacentStrings(AdjacentStrings node) {} | 45 visitAdjacentStrings(AdjacentStrings node) {} |
| 46 | 46 |
| 47 @override | 47 @override |
| 48 visitAnnotation(Annotation node) { | 48 visitAnnotation(Annotation node) { |
| 49 Annotation other = this.other; | 49 Annotation other = this.other; |
| (...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 841 } | 841 } |
| 842 String locationA = _getElementLocationWithoutUri(a); | 842 String locationA = _getElementLocationWithoutUri(a); |
| 843 String locationB = _getElementLocationWithoutUri(b); | 843 String locationB = _getElementLocationWithoutUri(b); |
| 844 if (locationA != locationB) { | 844 if (locationA != locationB) { |
| 845 int offset = other.offset; | 845 int offset = other.offset; |
| 846 _fail('[$offset]\nExpected: $b ($locationB)\n Actual: $a ($locationA)'); | 846 _fail('[$offset]\nExpected: $b ($locationB)\n Actual: $a ($locationA)'); |
| 847 } | 847 } |
| 848 if (a == null && b == null) { | 848 if (a == null && b == null) { |
| 849 return; | 849 return; |
| 850 } | 850 } |
| 851 if (a.nameOffset != b.nameOffset) { | 851 _verifyEqual('nameOffset', a.nameOffset, b.nameOffset); |
| 852 _fail('Expected: ${b.nameOffset}\n Actual: ${a.nameOffset}'); | 852 if (a is ElementImpl && b is ElementImpl) { |
| 853 _verifyEqual('codeOffset', a.codeOffset, b.codeOffset); |
| 854 _verifyEqual('codeLength', a.codeLength, b.codeLength); |
| 853 } | 855 } |
| 854 if (a is LocalElement && b is LocalElement) { | 856 if (a is LocalElement && b is LocalElement) { |
| 855 if (a.visibleRange != b.visibleRange) { | 857 _verifyEqual('visibleRange', a.visibleRange, b.visibleRange); |
| 856 _fail('Expected: ${b.visibleRange}\nActual: ${a.visibleRange}'); | |
| 857 } | |
| 858 } | 858 } |
| 859 } | 859 } |
| 860 | 860 |
| 861 void _verifyEqual(String name, actual, expected) { |
| 862 if (actual != expected) { |
| 863 _fail('$name\nExpected: $expected\n Actual: $actual'); |
| 864 } |
| 865 } |
| 866 |
| 861 void _verifyType(DartType a, DartType b) { | 867 void _verifyType(DartType a, DartType b) { |
| 862 if (!validateTypes) { | 868 if (!validateTypes) { |
| 863 return; | 869 return; |
| 864 } | 870 } |
| 865 if (a != b) { | 871 if (a != b) { |
| 866 int offset = other.offset; | 872 int offset = other.offset; |
| 867 _fail('[$offset]\nExpected: $b\n Actual: $a'); | 873 _fail('[$offset]\nExpected: $b\n Actual: $a'); |
| 868 } | 874 } |
| 869 } | 875 } |
| 870 | 876 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 957 * package:project/my_lib.dart -> my_lib.dart | 963 * package:project/my_lib.dart -> my_lib.dart |
| 958 */ | 964 */ |
| 959 static String _getShortElementLocationUri(String uri) { | 965 static String _getShortElementLocationUri(String uri) { |
| 960 int index = uri.lastIndexOf('/'); | 966 int index = uri.lastIndexOf('/'); |
| 961 if (index == -1) { | 967 if (index == -1) { |
| 962 return uri; | 968 return uri; |
| 963 } | 969 } |
| 964 return uri.substring(index + 1); | 970 return uri.substring(index + 1); |
| 965 } | 971 } |
| 966 } | 972 } |
| OLD | NEW |