| 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 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 expect(r, isNull, reason: desc); | 261 expect(r, isNull, reason: desc); |
| 262 } else { | 262 } else { |
| 263 expect(r, isNotNull, reason: desc); | 263 expect(r, isNotNull, reason: desc); |
| 264 // ConstantAstCloner does not copy static types, and constant values | 264 // ConstantAstCloner does not copy static types, and constant values |
| 265 // computer does not use static types. So, we don't set them during | 265 // computer does not use static types. So, we don't set them during |
| 266 // resynthesis and should not check them here. | 266 // resynthesis and should not check them here. |
| 267 if (o is ParenthesizedExpression) { | 267 if (o is ParenthesizedExpression) { |
| 268 // We don't resynthesize parenthesis, so just ignore it. | 268 // We don't resynthesize parenthesis, so just ignore it. |
| 269 compareConstantExpressions(r, o.expression, desc); | 269 compareConstantExpressions(r, o.expression, desc); |
| 270 } else if (o is SimpleIdentifier && r is SimpleIdentifier) { | 270 } else if (o is SimpleIdentifier && r is SimpleIdentifier) { |
| 271 expect(r.name, o.name); | 271 expect(r.name, o.name, reason: desc); |
| 272 compareElements(r.staticElement, o.staticElement, desc); | 272 compareElements(r.staticElement, o.staticElement, desc); |
| 273 } else if (o is PrefixedIdentifier && r is SimpleIdentifier) { | 273 } else if (o is PrefixedIdentifier && r is SimpleIdentifier) { |
| 274 // We don't resynthesize prefixed identifiers. | 274 // We don't resynthesize prefixed identifiers. |
| 275 // We use simple identifiers with correct elements. | 275 // We use simple identifiers with correct elements. |
| 276 compareConstantExpressions(r, o.identifier, desc); | 276 compareConstantExpressions(r, o.identifier, desc); |
| 277 } else if (o is PropertyAccess && r is PropertyAccess) { |
| 278 compareConstantExpressions(r.target, o.target, desc); |
| 279 expect(r.propertyName.name, o.propertyName.name, reason: desc); |
| 280 compareElements( |
| 281 r.propertyName.staticElement, o.propertyName.staticElement, desc); |
| 277 } else if (o is PropertyAccess && r is SimpleIdentifier) { | 282 } else if (o is PropertyAccess && r is SimpleIdentifier) { |
| 278 // We don't resynthesize property access. | 283 // We don't resynthesize property access. |
| 279 // We use simple identifiers with correct elements. | 284 // We use simple identifiers with correct elements. |
| 280 compareConstantExpressions(r, o.propertyName, desc); | 285 compareConstantExpressions(r, o.propertyName, desc); |
| 281 } else if (o is NullLiteral) { | 286 } else if (o is NullLiteral) { |
| 282 expect(r, new isInstanceOf<NullLiteral>(), reason: desc); | 287 expect(r, new isInstanceOf<NullLiteral>(), reason: desc); |
| 283 } else if (o is BooleanLiteral && r is BooleanLiteral) { | 288 } else if (o is BooleanLiteral && r is BooleanLiteral) { |
| 284 expect(r.value, o.value, reason: desc); | 289 expect(r.value, o.value, reason: desc); |
| 285 } else if (o is IntegerLiteral && r is IntegerLiteral) { | 290 } else if (o is IntegerLiteral && r is IntegerLiteral) { |
| 286 expect(r.value, o.value, reason: desc); | 291 expect(r.value, o.value, reason: desc); |
| (...skipping 943 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1230 class C { | 1235 class C { |
| 1231 const C(); | 1236 const C(); |
| 1232 } | 1237 } |
| 1233 '''); | 1238 '''); |
| 1234 checkLibrary(r''' | 1239 checkLibrary(r''' |
| 1235 import 'a.dart' as p; | 1240 import 'a.dart' as p; |
| 1236 const V = const p.C(); | 1241 const V = const p.C(); |
| 1237 '''); | 1242 '''); |
| 1238 } | 1243 } |
| 1239 | 1244 |
| 1245 test_const_length_ofClassConstField() { |
| 1246 shouldCompareConstValues = true; |
| 1247 checkLibrary(r''' |
| 1248 class C { |
| 1249 static const String F = ''; |
| 1250 } |
| 1251 const int v = C.F.length; |
| 1252 '''); |
| 1253 } |
| 1254 |
| 1255 test_const_length_ofClassConstField_imported() { |
| 1256 shouldCompareConstValues = true; |
| 1257 addLibrarySource( |
| 1258 '/a.dart', |
| 1259 r''' |
| 1260 class C { |
| 1261 static const String F = ''; |
| 1262 } |
| 1263 '''); |
| 1264 checkLibrary(r''' |
| 1265 import 'a.dart'; |
| 1266 const int v = C.F.length; |
| 1267 '''); |
| 1268 } |
| 1269 |
| 1270 test_const_length_ofClassConstField_imported_withPrefix() { |
| 1271 shouldCompareConstValues = true; |
| 1272 addLibrarySource( |
| 1273 '/a.dart', |
| 1274 r''' |
| 1275 class C { |
| 1276 static const String F = ''; |
| 1277 } |
| 1278 '''); |
| 1279 checkLibrary(r''' |
| 1280 import 'a.dart' as p; |
| 1281 const int v = p.C.F.length; |
| 1282 '''); |
| 1283 } |
| 1284 |
| 1285 test_const_length_ofStringLiteral() { |
| 1286 shouldCompareConstValues = true; |
| 1287 checkLibrary(r''' |
| 1288 const v = 'abc'.length; |
| 1289 '''); |
| 1290 } |
| 1291 |
| 1292 test_const_length_ofTopLevelVariable() { |
| 1293 shouldCompareConstValues = true; |
| 1294 checkLibrary(r''' |
| 1295 const String S = 'abc'; |
| 1296 const v = S.length; |
| 1297 '''); |
| 1298 } |
| 1299 |
| 1300 test_const_length_ofTopLevelVariable_imported() { |
| 1301 shouldCompareConstValues = true; |
| 1302 addLibrarySource( |
| 1303 '/a.dart', |
| 1304 r''' |
| 1305 const String S = 'abc'; |
| 1306 '''); |
| 1307 checkLibrary(r''' |
| 1308 import 'a.dart'; |
| 1309 const v = S.length; |
| 1310 '''); |
| 1311 } |
| 1312 |
| 1313 test_const_length_ofTopLevelVariable_imported_withPrefix() { |
| 1314 shouldCompareConstValues = true; |
| 1315 addLibrarySource( |
| 1316 '/a.dart', |
| 1317 r''' |
| 1318 const String S = 'abc'; |
| 1319 '''); |
| 1320 checkLibrary(r''' |
| 1321 import 'a.dart' as p; |
| 1322 const v = p.S.length; |
| 1323 '''); |
| 1324 } |
| 1325 |
| 1326 test_const_length_staticMethod() { |
| 1327 shouldCompareConstValues = true; |
| 1328 checkLibrary(r''' |
| 1329 class C { |
| 1330 static int length() => 42; |
| 1331 } |
| 1332 const v = C.length; |
| 1333 '''); |
| 1334 } |
| 1335 |
| 1240 test_const_reference_staticField() { | 1336 test_const_reference_staticField() { |
| 1241 shouldCompareConstValues = true; | 1337 shouldCompareConstValues = true; |
| 1242 checkLibrary(r''' | 1338 checkLibrary(r''' |
| 1243 class C { | 1339 class C { |
| 1244 static const int F = 42; | 1340 static const int F = 42; |
| 1245 } | 1341 } |
| 1246 const V = C.F; | 1342 const V = C.F; |
| 1247 '''); | 1343 '''); |
| 1248 } | 1344 } |
| 1249 | 1345 |
| (...skipping 1239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2489 fail('Unexpectedly tried to get unlinked summary for $uri'); | 2585 fail('Unexpectedly tried to get unlinked summary for $uri'); |
| 2490 } | 2586 } |
| 2491 return serializedUnit; | 2587 return serializedUnit; |
| 2492 } | 2588 } |
| 2493 | 2589 |
| 2494 @override | 2590 @override |
| 2495 bool hasLibrarySummary(String uri) { | 2591 bool hasLibrarySummary(String uri) { |
| 2496 return true; | 2592 return true; |
| 2497 } | 2593 } |
| 2498 } | 2594 } |
| OLD | NEW |