Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(276)

Side by Side Diff: pkg/analyzer/test/src/summary/resynthesize_test.dart

Issue 1679923002: Resynthesize constructor initializers. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 'dart:convert'; 7 import 'dart:convert';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/element/element.dart'; 10 import 'package:analyzer/dart/element/element.dart';
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 comparePropertyAccessorElements( 235 comparePropertyAccessorElements(
236 resynthesized.accessors[i], 236 resynthesized.accessors[i],
237 original.accessors 237 original.accessors
238 .singleWhere((PropertyAccessorElement e) => e.name == name), 238 .singleWhere((PropertyAccessorElement e) => e.name == name),
239 'setter $name'); 239 'setter $name');
240 } 240 }
241 } 241 }
242 // TODO(paulberry): test metadata and offsetToElementMap. 242 // TODO(paulberry): test metadata and offsetToElementMap.
243 } 243 }
244 244
245 void compareConstantAsts(AstNode r, AstNode o, String desc) { 245 void compareConstAstLists(
246 void compareLists(List<Object> rItems, List<Object> oItems) { 246 List<Object> rItems, List<Object> oItems, String desc) {
247 if (rItems == null && oItems == null) { 247 if (rItems == null && oItems == null) {
248 return; 248 return;
249 } 249 }
250 expect(rItems != null && oItems != null, isTrue); 250 expect(rItems != null && oItems != null, isTrue);
251 expect(rItems, hasLength(oItems.length)); 251 expect(rItems, hasLength(oItems.length));
252 for (int i = 0; i < oItems.length; i++) { 252 for (int i = 0; i < oItems.length; i++) {
253 Object rItem = rItems[i]; 253 Object rItem = rItems[i];
254 Object oItem = oItems[i]; 254 Object oItem = oItems[i];
255 if (rItem is Expression && oItem is Expression) { 255 if (rItem is Expression && oItem is Expression) {
256 compareConstantAsts(rItem, oItem, desc); 256 compareConstAsts(rItem, oItem, desc);
257 } else if (rItem is TypeName && oItem is TypeName) { 257 } else if (rItem is TypeName && oItem is TypeName) {
258 compareConstantAsts(rItem.name, oItem.name, desc); 258 compareConstAsts(rItem.name, oItem.name, desc);
259 } else if (rItem is InterpolationString && 259 } else if (rItem is InterpolationString && oItem is InterpolationString) {
260 oItem is InterpolationString) { 260 expect(rItem.value, oItem.value);
261 expect(rItem.value, oItem.value); 261 } else if (rItem is InterpolationExpression &&
262 } else if (rItem is InterpolationExpression && 262 oItem is InterpolationExpression) {
263 oItem is InterpolationExpression) { 263 compareConstAsts(rItem.expression, oItem.expression, desc);
264 compareConstantAsts(rItem.expression, oItem.expression, desc); 264 } else if (rItem is MapLiteralEntry && oItem is MapLiteralEntry) {
265 } else if (rItem is MapLiteralEntry && oItem is MapLiteralEntry) { 265 compareConstAsts(rItem.key, oItem.key, desc);
266 compareConstantAsts(rItem.key, oItem.key, desc); 266 compareConstAsts(rItem.value, oItem.value, desc);
267 compareConstantAsts(rItem.value, oItem.value, desc); 267 } else if (oItem is ConstructorFieldInitializer &&
268 rItem is ConstructorFieldInitializer) {
269 compareConstAsts(rItem.fieldName, oItem.fieldName, desc);
270 if (constantInitializersAreInvalid) {
271 _assertUnresolvedIdentifier(rItem.expression, desc);
268 } else { 272 } else {
269 fail('$desc Incompatible item types: ' 273 compareConstAsts(rItem.expression, oItem.expression, desc);
270 '${rItem.runtimeType} vs. ${oItem.runtimeType}');
271 } 274 }
275 } else if (oItem is SuperConstructorInvocation &&
276 rItem is SuperConstructorInvocation) {
277 compareElements(rItem.staticElement, oItem.staticElement, desc);
278 compareConstAsts(rItem.constructorName, oItem.constructorName, desc);
279 compareConstAstLists(
280 rItem.argumentList.arguments, oItem.argumentList.arguments, desc);
281 } else if (oItem is RedirectingConstructorInvocation &&
282 rItem is RedirectingConstructorInvocation) {
283 compareElements(rItem.staticElement, oItem.staticElement, desc);
284 compareConstAsts(rItem.constructorName, oItem.constructorName, desc);
285 compareConstAstLists(
286 rItem.argumentList.arguments, oItem.argumentList.arguments, desc);
287 } else {
288 fail('$desc Incompatible item types: '
289 '${rItem.runtimeType} vs. ${oItem.runtimeType}');
272 } 290 }
273 } 291 }
292 }
293
294 void compareConstAsts(AstNode r, AstNode o, String desc) {
274 if (o == null) { 295 if (o == null) {
275 expect(r, isNull, reason: desc); 296 expect(r, isNull, reason: desc);
276 } else { 297 } else {
277 expect(r, isNotNull, reason: desc); 298 expect(r, isNotNull, reason: desc);
278 // ConstantAstCloner does not copy static types, and constant values 299 // ConstantAstCloner does not copy static types, and constant values
279 // computer does not use static types. So, we don't set them during 300 // computer does not use static types. So, we don't set them during
280 // resynthesis and should not check them here. 301 // resynthesis and should not check them here.
281 if (o is ParenthesizedExpression) { 302 if (o is ParenthesizedExpression) {
282 // We don't resynthesize parenthesis, so just ignore it. 303 // We don't resynthesize parenthesis, so just ignore it.
283 compareConstantAsts(r, o.expression, desc); 304 compareConstAsts(r, o.expression, desc);
284 } else if (o is SimpleIdentifier && r is SimpleIdentifier) { 305 } else if (o is SimpleIdentifier && r is SimpleIdentifier) {
285 expect(r.name, o.name, reason: desc); 306 expect(r.name, o.name, reason: desc);
286 compareElements(r.staticElement, o.staticElement, desc); 307 compareElements(r.staticElement, o.staticElement, desc);
287 } else if (o is PrefixedIdentifier && r is SimpleIdentifier) { 308 } else if (o is PrefixedIdentifier && r is SimpleIdentifier) {
288 // We often don't resynthesize prefixed identifiers. 309 // We often don't resynthesize prefixed identifiers.
289 // We use simple identifiers with correct elements. 310 // We use simple identifiers with correct elements.
290 compareConstantAsts(r, o.identifier, desc); 311 compareConstAsts(r, o.identifier, desc);
291 } else if (o is PrefixedIdentifier && r is PrefixedIdentifier) { 312 } else if (o is PrefixedIdentifier && r is PrefixedIdentifier) {
292 compareConstantAsts(r.prefix, o.prefix, desc); 313 compareConstAsts(r.prefix, o.prefix, desc);
293 compareConstantAsts(r.identifier, o.identifier, desc); 314 compareConstAsts(r.identifier, o.identifier, desc);
294 } else if (o is PropertyAccess && r is PropertyAccess) { 315 } else if (o is PropertyAccess && r is PropertyAccess) {
295 compareConstantAsts(r.target, o.target, desc); 316 compareConstAsts(r.target, o.target, desc);
296 expect(r.propertyName.name, o.propertyName.name, reason: desc); 317 expect(r.propertyName.name, o.propertyName.name, reason: desc);
297 compareElements( 318 compareElements(
298 r.propertyName.staticElement, o.propertyName.staticElement, desc); 319 r.propertyName.staticElement, o.propertyName.staticElement, desc);
299 } else if (o is PropertyAccess && r is SimpleIdentifier) { 320 } else if (o is PropertyAccess && r is SimpleIdentifier) {
300 // We don't resynthesize property access. 321 // We don't resynthesize property access.
301 // We use simple identifiers with correct elements. 322 // We use simple identifiers with correct elements.
302 compareConstantAsts(r, o.propertyName, desc); 323 compareConstAsts(r, o.propertyName, desc);
303 } else if (o is NullLiteral) { 324 } else if (o is NullLiteral) {
304 expect(r, new isInstanceOf<NullLiteral>(), reason: desc); 325 expect(r, new isInstanceOf<NullLiteral>(), reason: desc);
305 } else if (o is BooleanLiteral && r is BooleanLiteral) { 326 } else if (o is BooleanLiteral && r is BooleanLiteral) {
306 expect(r.value, o.value, reason: desc); 327 expect(r.value, o.value, reason: desc);
307 } else if (o is IntegerLiteral && r is IntegerLiteral) { 328 } else if (o is IntegerLiteral && r is IntegerLiteral) {
308 expect(r.value, o.value, reason: desc); 329 expect(r.value, o.value, reason: desc);
309 } else if (o is DoubleLiteral && r is DoubleLiteral) { 330 } else if (o is DoubleLiteral && r is DoubleLiteral) {
310 expect(r.value, o.value, reason: desc); 331 expect(r.value, o.value, reason: desc);
311 } else if (o is StringInterpolation && r is StringInterpolation) { 332 } else if (o is StringInterpolation && r is StringInterpolation) {
312 compareLists(r.elements, o.elements); 333 compareConstAstLists(r.elements, o.elements, desc);
313 } else if (o is StringLiteral && r is StringLiteral) { 334 } else if (o is StringLiteral && r is StringLiteral) {
314 // We don't keep all the tokens of AdjacentStrings. 335 // We don't keep all the tokens of AdjacentStrings.
315 // So, we can compare only their values. 336 // So, we can compare only their values.
316 expect(r.stringValue, o.stringValue, reason: desc); 337 expect(r.stringValue, o.stringValue, reason: desc);
317 } else if (o is SymbolLiteral && r is SymbolLiteral) { 338 } else if (o is SymbolLiteral && r is SymbolLiteral) {
318 // We don't keep all the tokens of symbol literals. 339 // We don't keep all the tokens of symbol literals.
319 // So, we can compare only their values. 340 // So, we can compare only their values.
320 expect(r.components.map((t) => t.lexeme).join('.'), 341 expect(r.components.map((t) => t.lexeme).join('.'),
321 o.components.map((t) => t.lexeme).join('.'), 342 o.components.map((t) => t.lexeme).join('.'),
322 reason: desc); 343 reason: desc);
323 } else if (o is NamedExpression && r is NamedExpression) { 344 } else if (o is NamedExpression && r is NamedExpression) {
324 expect(r.name.label.name, o.name.label.name, reason: desc); 345 expect(r.name.label.name, o.name.label.name, reason: desc);
325 compareConstantAsts(r.expression, o.expression, desc); 346 compareConstAsts(r.expression, o.expression, desc);
326 } else if (o is BinaryExpression && r is BinaryExpression) { 347 } else if (o is BinaryExpression && r is BinaryExpression) {
327 expect(r.operator.lexeme, o.operator.lexeme, reason: desc); 348 expect(r.operator.lexeme, o.operator.lexeme, reason: desc);
328 compareConstantAsts(r.leftOperand, o.leftOperand, desc); 349 compareConstAsts(r.leftOperand, o.leftOperand, desc);
329 compareConstantAsts(r.rightOperand, o.rightOperand, desc); 350 compareConstAsts(r.rightOperand, o.rightOperand, desc);
330 } else if (o is PrefixExpression && r is PrefixExpression) { 351 } else if (o is PrefixExpression && r is PrefixExpression) {
331 expect(r.operator.lexeme, o.operator.lexeme, reason: desc); 352 expect(r.operator.lexeme, o.operator.lexeme, reason: desc);
332 compareConstantAsts(r.operand, o.operand, desc); 353 compareConstAsts(r.operand, o.operand, desc);
333 } else if (o is ConditionalExpression && r is ConditionalExpression) { 354 } else if (o is ConditionalExpression && r is ConditionalExpression) {
334 compareConstantAsts(r.condition, o.condition, desc); 355 compareConstAsts(r.condition, o.condition, desc);
335 compareConstantAsts(r.thenExpression, o.thenExpression, desc); 356 compareConstAsts(r.thenExpression, o.thenExpression, desc);
336 compareConstantAsts(r.elseExpression, o.elseExpression, desc); 357 compareConstAsts(r.elseExpression, o.elseExpression, desc);
337 } else if (o is ListLiteral && r is ListLiteral) { 358 } else if (o is ListLiteral && r is ListLiteral) {
338 compareLists(r.typeArguments?.arguments, o.typeArguments?.arguments); 359 compareConstAstLists(
339 compareLists(r.elements, o.elements); 360 r.typeArguments?.arguments, o.typeArguments?.arguments, desc);
361 compareConstAstLists(r.elements, o.elements, desc);
340 } else if (o is MapLiteral && r is MapLiteral) { 362 } else if (o is MapLiteral && r is MapLiteral) {
341 compareLists(r.typeArguments?.arguments, o.typeArguments?.arguments); 363 compareConstAstLists(
342 compareLists(r.entries, o.entries); 364 r.typeArguments?.arguments, o.typeArguments?.arguments, desc);
365 compareConstAstLists(r.entries, o.entries, desc);
343 } else if (o is InstanceCreationExpression && 366 } else if (o is InstanceCreationExpression &&
344 r is InstanceCreationExpression) { 367 r is InstanceCreationExpression) {
345 compareElements(r.staticElement, o.staticElement, desc); 368 compareElements(r.staticElement, o.staticElement, desc);
346 ConstructorName oConstructor = o.constructorName; 369 ConstructorName oConstructor = o.constructorName;
347 ConstructorName rConstructor = r.constructorName; 370 ConstructorName rConstructor = r.constructorName;
348 expect(oConstructor, isNotNull, reason: desc); 371 expect(oConstructor, isNotNull, reason: desc);
349 expect(rConstructor, isNotNull, reason: desc); 372 expect(rConstructor, isNotNull, reason: desc);
350 compareElements( 373 compareElements(
351 rConstructor.staticElement, oConstructor.staticElement, desc); 374 rConstructor.staticElement, oConstructor.staticElement, desc);
352 TypeName oType = oConstructor.type; 375 TypeName oType = oConstructor.type;
353 TypeName rType = rConstructor.type; 376 TypeName rType = rConstructor.type;
354 expect(oType, isNotNull, reason: desc); 377 expect(oType, isNotNull, reason: desc);
355 expect(rType, isNotNull, reason: desc); 378 expect(rType, isNotNull, reason: desc);
356 compareConstantAsts(rType.name, oType.name, desc); 379 compareConstAsts(rType.name, oType.name, desc);
357 compareConstantAsts(rConstructor.name, oConstructor.name, desc); 380 compareConstAsts(rConstructor.name, oConstructor.name, desc);
358 compareLists( 381 compareConstAstLists(rType.typeArguments?.arguments,
359 rType.typeArguments?.arguments, oType.typeArguments?.arguments); 382 oType.typeArguments?.arguments, desc);
360 compareLists(r.argumentList.arguments, o.argumentList.arguments); 383 compareConstAstLists(
384 r.argumentList.arguments, o.argumentList.arguments, desc);
361 } else if (o is AnnotationImpl && r is AnnotationImpl) { 385 } else if (o is AnnotationImpl && r is AnnotationImpl) {
362 expect(o.atSign.lexeme, r.atSign.lexeme, reason: desc); 386 expect(o.atSign.lexeme, r.atSign.lexeme, reason: desc);
363 Identifier rName = r.name; 387 Identifier rName = r.name;
364 Identifier oName = o.name; 388 Identifier oName = o.name;
365 if (oName is PrefixedIdentifier && o.constructorName != null) { 389 if (oName is PrefixedIdentifier && o.constructorName != null) {
366 // E.g. `@prefix.cls.ctor`. This gets resynthesized as `@cls.ctor`, 390 // E.g. `@prefix.cls.ctor`. This gets resynthesized as `@cls.ctor`,
367 // with `cls.ctor` represented as a PrefixedIdentifier. 391 // with `cls.ctor` represented as a PrefixedIdentifier.
368 expect(rName, new isInstanceOf<PrefixedIdentifier>(), reason: desc); 392 expect(rName, new isInstanceOf<PrefixedIdentifier>(), reason: desc);
369 if (rName is PrefixedIdentifier) { 393 if (rName is PrefixedIdentifier) {
370 compareConstantAsts(rName.prefix, oName.identifier, desc); 394 compareConstAsts(rName.prefix, oName.identifier, desc);
371 expect(rName.period.lexeme, '.', reason: desc); 395 expect(rName.period.lexeme, '.', reason: desc);
372 compareConstantAsts(rName.identifier, o.constructorName, desc); 396 compareConstAsts(rName.identifier, o.constructorName, desc);
373 expect(r.period, isNull, reason: desc); 397 expect(r.period, isNull, reason: desc);
374 expect(r.constructorName, isNull, reason: desc); 398 expect(r.constructorName, isNull, reason: desc);
375 } 399 }
376 } else { 400 } else {
377 compareConstantAsts(r.name, o.name, desc); 401 compareConstAsts(r.name, o.name, desc);
378 expect(r.period?.lexeme, o.period?.lexeme, reason: desc); 402 expect(r.period?.lexeme, o.period?.lexeme, reason: desc);
379 compareConstantAsts(r.constructorName, o.constructorName, desc); 403 compareConstAsts(r.constructorName, o.constructorName, desc);
380 } 404 }
381 compareLists(r.arguments?.arguments, o.arguments?.arguments); 405 compareConstAstLists(
406 r.arguments?.arguments, o.arguments?.arguments, desc);
382 Element expectedElement = o.element; 407 Element expectedElement = o.element;
383 if (oName is PrefixedIdentifier && o.constructorName != null) { 408 if (oName is PrefixedIdentifier && o.constructorName != null) {
384 // Due to dartbug.com/25706, [o.element] incorrectly points to the 409 // Due to dartbug.com/25706, [o.element] incorrectly points to the
385 // class rather than the named constructor. Hack around this. 410 // class rather than the named constructor. Hack around this.
386 // TODO(paulberry): when dartbug.com/25706 is fixed, remove this. 411 // TODO(paulberry): when dartbug.com/25706 is fixed, remove this.
387 expectedElement = (expectedElement as ClassElement) 412 expectedElement = (expectedElement as ClassElement)
388 .getNamedConstructor(o.constructorName.name); 413 .getNamedConstructor(o.constructorName.name);
389 expect(expectedElement, isNotNull, reason: desc); 414 expect(expectedElement, isNotNull, reason: desc);
390 } 415 }
391 compareElements(r.element, expectedElement, desc); 416 compareElements(r.element, expectedElement, desc);
392 // elementAnnotation should be null; it is only used in the full AST. 417 // elementAnnotation should be null; it is only used in the full AST.
393 expect(o.elementAnnotation, isNull); 418 expect(o.elementAnnotation, isNull);
394 expect(r.elementAnnotation, isNull); 419 expect(r.elementAnnotation, isNull);
395 } else if (o is ConstructorName && r is ConstructorName) {
396 fail('Not implemented for ${r.runtimeType} vs. ${o.runtimeType}');
397 } else { 420 } else {
398 fail('Not implemented for ${r.runtimeType} vs. ${o.runtimeType}'); 421 fail('Not implemented for ${r.runtimeType} vs. ${o.runtimeType}');
399 } 422 }
400 } 423 }
401 } 424 }
402 425
403 void compareConstructorElements(ConstructorElementImpl resynthesized, 426 void compareConstructorElements(ConstructorElementImpl resynthesized,
404 ConstructorElementImpl original, String desc) { 427 ConstructorElementImpl original, String desc) {
405 compareExecutableElements(resynthesized, original, desc); 428 compareExecutableElements(resynthesized, original, desc);
406 // TODO(paulberry): test redirectedConstructor and constantInitializers 429 compareConstAstLists(resynthesized.constantInitializers,
430 original.constantInitializers, desc);
431 // TODO(paulberry): test redirectedConstructor
407 } 432 }
408 433
409 void compareElementAnnotations(ElementAnnotationImpl resynthesized, 434 void compareElementAnnotations(ElementAnnotationImpl resynthesized,
410 ElementAnnotationImpl original, String desc) { 435 ElementAnnotationImpl original, String desc) {
411 expect(resynthesized.element, isNotNull, reason: desc); 436 expect(resynthesized.element, isNotNull, reason: desc);
412 expect(resynthesized.element.kind, original.element.kind, reason: desc); 437 expect(resynthesized.element.kind, original.element.kind, reason: desc);
413 expect(resynthesized.element.location, original.element.location, 438 expect(resynthesized.element.location, original.element.location,
414 reason: desc); 439 reason: desc);
415 expect(resynthesized.compilationUnit, isNotNull, reason: desc); 440 expect(resynthesized.compilationUnit, isNotNull, reason: desc);
416 expect(resynthesized.compilationUnit.location, 441 expect(resynthesized.compilationUnit.location,
417 original.compilationUnit.location, 442 original.compilationUnit.location,
418 reason: desc); 443 reason: desc);
419 expect(resynthesized.annotationAst, isNotNull, reason: desc); 444 expect(resynthesized.annotationAst, isNotNull, reason: desc);
420 compareConstantAsts( 445 compareConstAsts(resynthesized.annotationAst, original.annotationAst, desc);
421 resynthesized.annotationAst, original.annotationAst, desc);
422 } 446 }
423 447
424 void compareElements(Element resynthesized, Element original, String desc) { 448 void compareElements(Element resynthesized, Element original, String desc) {
425 expect(resynthesized, isNotNull); 449 expect(resynthesized, isNotNull);
426 expect(resynthesized.kind, original.kind); 450 expect(resynthesized.kind, original.kind);
427 expect(resynthesized.location, original.location, reason: desc); 451 expect(resynthesized.location, original.location, reason: desc);
428 expect(resynthesized.name, original.name); 452 expect(resynthesized.name, original.name);
429 expect(resynthesized.nameOffset, original.nameOffset, reason: desc); 453 expect(resynthesized.nameOffset, original.nameOffset, reason: desc);
430 expect(resynthesized.documentationComment, original.documentationComment, 454 expect(resynthesized.documentationComment, original.documentationComment,
431 reason: desc); 455 reason: desc);
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 expect(resynthesized.uriEnd, original.uriEnd, reason: desc); 766 expect(resynthesized.uriEnd, original.uriEnd, reason: desc);
743 } 767 }
744 768
745 void compareVariableElements(VariableElementImpl resynthesized, 769 void compareVariableElements(VariableElementImpl resynthesized,
746 VariableElementImpl original, String desc) { 770 VariableElementImpl original, String desc) {
747 compareElements(resynthesized, original, desc); 771 compareElements(resynthesized, original, desc);
748 compareTypes(resynthesized.type, original.type, desc); 772 compareTypes(resynthesized.type, original.type, desc);
749 if (original is ConstVariableElement) { 773 if (original is ConstVariableElement) {
750 Expression initializer = resynthesized.constantInitializer; 774 Expression initializer = resynthesized.constantInitializer;
751 if (constantInitializersAreInvalid) { 775 if (constantInitializersAreInvalid) {
752 expect(initializer, new isInstanceOf<SimpleIdentifier>(), reason: desc); 776 _assertUnresolvedIdentifier(initializer, desc);
753 SimpleIdentifier identifier = initializer;
754 expect(identifier.staticElement, isNull, reason: desc);
755 } else { 777 } else {
756 compareConstantAsts(initializer, original.constantInitializer, desc); 778 compareConstAsts(initializer, original.constantInitializer, desc);
757 } 779 }
758 } 780 }
759 } 781 }
760 782
761 /** 783 /**
762 * Serialize the given [library] into a summary. Then create a 784 * Serialize the given [library] into a summary. Then create a
763 * [_TestSummaryResynthesizer] which can deserialize it, along with any 785 * [_TestSummaryResynthesizer] which can deserialize it, along with any
764 * references it makes to `dart:core`. 786 * references it makes to `dart:core`.
765 * 787 *
766 * Errors will lead to a test failure unless [allowErrors] is `true`. 788 * Errors will lead to a test failure unless [allowErrors] is `true`.
(...skipping 1019 matching lines...) Expand 10 before | Expand all | Expand 10 after
1786 test_constructor_documented() { 1808 test_constructor_documented() {
1787 checkLibrary(''' 1809 checkLibrary('''
1788 class C { 1810 class C {
1789 /** 1811 /**
1790 * Docs 1812 * Docs
1791 */ 1813 */
1792 C(); 1814 C();
1793 }'''); 1815 }''');
1794 } 1816 }
1795 1817
1818 test_constructor_initializers_field() {
1819 checkLibrary('''
1820 class C {
1821 final x;
1822 const C() : x = 42;
1823 }
1824 ''');
1825 }
1826
1827 test_constructor_initializers_field_notConst() {
1828 constantInitializersAreInvalid = true;
1829 checkLibrary(
1830 '''
1831 class C {
1832 final x;
1833 const A() : x = foo();
1834 }
1835 int foo() => 42;
1836 ''',
1837 allowErrors: true);
1838 }
1839
1840 test_constructor_initializers_field_withParameter() {
1841 checkLibrary('''
1842 class C {
1843 final x;
1844 const C(int p) : x = 1 + p;
1845 }
1846 ''');
1847 }
1848
1849 test_constructor_initializers_superInvocation_named() {
1850 checkLibrary('''
1851 class A {
1852 const A.aaa(int p);
1853 }
1854 class C extends A {
1855 const C() : super.aaa(42);
1856 }
1857 ''');
1858 }
1859
1860 test_constructor_initializers_superInvocation_unnamed() {
1861 checkLibrary('''
1862 class A {
1863 const A(int p);
1864 }
1865 class C extends A {
1866 const C.ccc() : super(42);
1867 }
1868 ''');
1869 }
1870
1871 test_constructor_initializers_thisInvocation_named() {
1872 checkLibrary('''
1873 class C {
1874 const C() : this.named(1, 'bbb');
1875 const C.named(int a, String b);
1876 }
1877 ''');
1878 }
1879
1880 test_constructor_initializers_thisInvocation_unnamed() {
1881 checkLibrary('''
1882 class C {
1883 const C.named() : this(1, 'bbb');
1884 const C(int a, String b);
1885 }
1886 ''');
1887 }
1888
1796 test_core() { 1889 test_core() {
1797 String uri = 'dart:core'; 1890 String uri = 'dart:core';
1798 LibraryElementImpl original = 1891 LibraryElementImpl original =
1799 resolve2(analysisContext2.sourceFactory.forUri(uri)); 1892 resolve2(analysisContext2.sourceFactory.forUri(uri));
1800 LibraryElementImpl resynthesized = resynthesizeLibraryElement( 1893 LibraryElementImpl resynthesized = resynthesizeLibraryElement(
1801 encodeLibraryElement(original), uri, original); 1894 encodeLibraryElement(original), uri, original);
1802 checkLibraryElements(original, resynthesized); 1895 checkLibraryElements(original, resynthesized);
1803 } 1896 }
1804 1897
1805 test_enum_documented() { 1898 test_enum_documented() {
(...skipping 1037 matching lines...) Expand 10 before | Expand all | Expand 10 after
2843 _TestSummaryResynthesizer resynthesizer = encodeLibrary(original.library); 2936 _TestSummaryResynthesizer resynthesizer = encodeLibrary(original.library);
2844 ElementLocationImpl location = original.location; 2937 ElementLocationImpl location = original.location;
2845 Element result = resynthesizer.getElement(location); 2938 Element result = resynthesizer.getElement(location);
2846 checkMinimalResynthesisWork(resynthesizer, original.library); 2939 checkMinimalResynthesisWork(resynthesizer, original.library);
2847 // Check that no other summaries needed to be resynthesized to resynthesize 2940 // Check that no other summaries needed to be resynthesized to resynthesize
2848 // the library element. 2941 // the library element.
2849 expect(resynthesizer.resynthesisCount, 1); 2942 expect(resynthesizer.resynthesisCount, 1);
2850 expect(result.location, location); 2943 expect(result.location, location);
2851 return result; 2944 return result;
2852 } 2945 }
2946
2947 void _assertUnresolvedIdentifier(Expression initializer, String desc) {
2948 expect(initializer, new isInstanceOf<SimpleIdentifier>(), reason: desc);
2949 SimpleIdentifier identifier = initializer;
2950 expect(identifier.staticElement, isNull, reason: desc);
2951 }
2853 } 2952 }
2854 2953
2855 class _TestSummaryResynthesizer extends SummaryResynthesizer { 2954 class _TestSummaryResynthesizer extends SummaryResynthesizer {
2856 final Map<String, UnlinkedUnit> unlinkedSummaries; 2955 final Map<String, UnlinkedUnit> unlinkedSummaries;
2857 final Map<String, LinkedLibrary> linkedSummaries; 2956 final Map<String, LinkedLibrary> linkedSummaries;
2858 2957
2859 /** 2958 /**
2860 * The set of uris for which unlinked summaries have been requested using 2959 * The set of uris for which unlinked summaries have been requested using
2861 * [getUnlinkedSummary]. 2960 * [getUnlinkedSummary].
2862 */ 2961 */
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2896 fail('Unexpectedly tried to get unlinked summary for $uri'); 2995 fail('Unexpectedly tried to get unlinked summary for $uri');
2897 } 2996 }
2898 return serializedUnit; 2997 return serializedUnit;
2899 } 2998 }
2900 2999
2901 @override 3000 @override
2902 bool hasLibrarySummary(String uri) { 3001 bool hasLibrarySummary(String uri) {
2903 return true; 3002 return true;
2904 } 3003 }
2905 } 3004 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698