| 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 library test.src.serialization.elements_test; | 5 library test.src.serialization.elements_test; |
| 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 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 } else { | 229 } else { |
| 230 fail('$desc Incompatible item types: ' | 230 fail('$desc Incompatible item types: ' |
| 231 '${rItem.runtimeType} vs. ${oItem.runtimeType}'); | 231 '${rItem.runtimeType} vs. ${oItem.runtimeType}'); |
| 232 } | 232 } |
| 233 } | 233 } |
| 234 } | 234 } |
| 235 if (o == null) { | 235 if (o == null) { |
| 236 expect(r, isNull, reason: desc); | 236 expect(r, isNull, reason: desc); |
| 237 } else { | 237 } else { |
| 238 expect(r, isNotNull, reason: desc); | 238 expect(r, isNotNull, reason: desc); |
| 239 compareTypes(r.staticType, o.staticType, desc); | 239 // ConstantAstCloner does not copy static types, and constant values |
| 240 // computer does not use static types. So, we don't set them during |
| 241 // resynthesis and should not check them here. |
| 240 if (o is ParenthesizedExpression) { | 242 if (o is ParenthesizedExpression) { |
| 241 // We don't resynthesize parenthesis, so just ignore it. | 243 // We don't resynthesize parenthesis, so just ignore it. |
| 242 compareConstantExpressions(r, o.expression, desc); | 244 compareConstantExpressions(r, o.expression, desc); |
| 243 } else if (o is SimpleIdentifier && r is SimpleIdentifier) { | 245 } else if (o is SimpleIdentifier && r is SimpleIdentifier) { |
| 244 expect(r.name, o.name); | 246 expect(r.name, o.name); |
| 245 compareElements(r.staticElement, o.staticElement, desc); | 247 compareElements(r.staticElement, o.staticElement, desc); |
| 246 // ConstantAstCloner does not copy static types, and constant values | |
| 247 // computer does not use static types. So, we don't set them during | |
| 248 // resynthesis and should not check them. | |
| 249 } else if (o is PrefixedIdentifier && r is SimpleIdentifier) { | 248 } else if (o is PrefixedIdentifier && r is SimpleIdentifier) { |
| 250 // We don't resynthesize prefixed identifiers. | 249 // We don't resynthesize prefixed identifiers. |
| 251 // We use simple identifiers with correct elements. | 250 // We use simple identifiers with correct elements. |
| 252 compareConstantExpressions(r, o.identifier, desc); | 251 compareConstantExpressions(r, o.identifier, desc); |
| 253 } else if (o is PropertyAccess && r is SimpleIdentifier) { | 252 } else if (o is PropertyAccess && r is SimpleIdentifier) { |
| 254 // We don't resynthesize property access. | 253 // We don't resynthesize property access. |
| 255 // We use simple identifiers with correct elements. | 254 // We use simple identifiers with correct elements. |
| 256 compareConstantExpressions(r, o.propertyName, desc); | 255 compareConstantExpressions(r, o.propertyName, desc); |
| 257 } else if (o is NullLiteral) { | 256 } else if (o is NullLiteral) { |
| 258 expect(r, new isInstanceOf<NullLiteral>(), reason: desc); | 257 expect(r, new isInstanceOf<NullLiteral>(), reason: desc); |
| (...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1047 class C { | 1046 class C { |
| 1048 static const int F = 42; | 1047 static const int F = 42; |
| 1049 } | 1048 } |
| 1050 '''); | 1049 '''); |
| 1051 checkLibrary(r''' | 1050 checkLibrary(r''' |
| 1052 import 'a.dart' as p; | 1051 import 'a.dart' as p; |
| 1053 const V = p.C.F; | 1052 const V = p.C.F; |
| 1054 '''); | 1053 '''); |
| 1055 } | 1054 } |
| 1056 | 1055 |
| 1056 test_const_reference_staticMethod() { |
| 1057 shouldCompareConstValues = true; |
| 1058 checkLibrary(r''' |
| 1059 class C { |
| 1060 static int m(int a, String b) => 42; |
| 1061 } |
| 1062 const V = C.m; |
| 1063 '''); |
| 1064 } |
| 1065 |
| 1066 test_const_reference_staticMethod_imported() { |
| 1067 shouldCompareConstValues = true; |
| 1068 addLibrarySource( |
| 1069 '/a.dart', |
| 1070 r''' |
| 1071 class C { |
| 1072 static int m(int a, String b) => 42; |
| 1073 } |
| 1074 '''); |
| 1075 checkLibrary(r''' |
| 1076 import 'a.dart'; |
| 1077 const V = C.m; |
| 1078 '''); |
| 1079 } |
| 1080 |
| 1081 test_const_reference_staticMethod_imported_withPrefix() { |
| 1082 shouldCompareConstValues = true; |
| 1083 addLibrarySource( |
| 1084 '/a.dart', |
| 1085 r''' |
| 1086 class C { |
| 1087 static int m(int a, String b) => 42; |
| 1088 } |
| 1089 '''); |
| 1090 checkLibrary(r''' |
| 1091 import 'a.dart' as p; |
| 1092 const V = p.C.m; |
| 1093 '''); |
| 1094 } |
| 1095 |
| 1057 test_const_reference_topLevelVariable() { | 1096 test_const_reference_topLevelVariable() { |
| 1058 shouldCompareConstValues = true; | 1097 shouldCompareConstValues = true; |
| 1059 checkLibrary(r''' | 1098 checkLibrary(r''' |
| 1060 const A = 1; | 1099 const A = 1; |
| 1061 const B = A + 2; | 1100 const B = A + 2; |
| 1062 '''); | 1101 '''); |
| 1063 } | 1102 } |
| 1064 | 1103 |
| 1065 test_const_reference_topLevelVariable_imported() { | 1104 test_const_reference_topLevelVariable_imported() { |
| 1066 shouldCompareConstValues = true; | 1105 shouldCompareConstValues = true; |
| (...skipping 1144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2211 fail('Unexpectedly tried to get unlinked summary for $uri'); | 2250 fail('Unexpectedly tried to get unlinked summary for $uri'); |
| 2212 } | 2251 } |
| 2213 return serializedUnit; | 2252 return serializedUnit; |
| 2214 } | 2253 } |
| 2215 | 2254 |
| 2216 @override | 2255 @override |
| 2217 bool hasLibrarySummary(String uri) { | 2256 bool hasLibrarySummary(String uri) { |
| 2218 return true; | 2257 return true; |
| 2219 } | 2258 } |
| 2220 } | 2259 } |
| OLD | NEW |