| 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/ast/standard_resolution_map.dart'; | 8 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; |
| 9 import 'package:analyzer/dart/constant/value.dart'; | 9 import 'package:analyzer/dart/constant/value.dart'; |
| 10 import 'package:analyzer/dart/element/element.dart'; | 10 import 'package:analyzer/dart/element/element.dart'; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 abstract class AbstractResynthesizeTest extends AbstractSingleUnitTest { | 36 abstract class AbstractResynthesizeTest extends AbstractSingleUnitTest { |
| 37 Set<Source> otherLibrarySources = new Set<Source>(); | 37 Set<Source> otherLibrarySources = new Set<Source>(); |
| 38 | 38 |
| 39 /** | 39 /** |
| 40 * Names of variables which have initializers that are not valid constants, | 40 * Names of variables which have initializers that are not valid constants, |
| 41 * so they are not resynthesized. | 41 * so they are not resynthesized. |
| 42 */ | 42 */ |
| 43 Set<String> variablesWithNotConstInitializers = new Set<String>(); | 43 Set<String> variablesWithNotConstInitializers = new Set<String>(); |
| 44 | 44 |
| 45 /** | 45 /** |
| 46 * Names that cannot be resolved, e.g. because of duplicate declaration. |
| 47 */ |
| 48 Set<String> namesThatCannotBeResolved = new Set<String>(); |
| 49 |
| 50 /** |
| 46 * Tests may set this to `true` to indicate that a missing file at the time of | 51 * Tests may set this to `true` to indicate that a missing file at the time of |
| 47 * summary resynthesis shouldn't trigger an error. | 52 * summary resynthesis shouldn't trigger an error. |
| 48 */ | 53 */ |
| 49 bool allowMissingFiles = false; | 54 bool allowMissingFiles = false; |
| 50 | 55 |
| 51 void addLibrary(String uri) { | 56 void addLibrary(String uri) { |
| 52 otherLibrarySources.add(context.sourceFactory.forUri(uri)); | 57 otherLibrarySources.add(context.sourceFactory.forUri(uri)); |
| 53 } | 58 } |
| 54 | 59 |
| 55 Source addLibrarySource(String filePath, String contents) { | 60 Source addLibrarySource(String filePath, String contents) { |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 } else { | 379 } else { |
| 375 expect(r, isNotNull, reason: desc); | 380 expect(r, isNotNull, reason: desc); |
| 376 // ConstantAstCloner does not copy static types, and constant values | 381 // ConstantAstCloner does not copy static types, and constant values |
| 377 // computer does not use static types. So, we don't set them during | 382 // computer does not use static types. So, we don't set them during |
| 378 // resynthesis and should not check them here. | 383 // resynthesis and should not check them here. |
| 379 if (o is ParenthesizedExpression) { | 384 if (o is ParenthesizedExpression) { |
| 380 // We don't resynthesize parenthesis, so just ignore it. | 385 // We don't resynthesize parenthesis, so just ignore it. |
| 381 compareConstAsts(r, o.expression, desc); | 386 compareConstAsts(r, o.expression, desc); |
| 382 } else if (o is SimpleIdentifier && r is SimpleIdentifier) { | 387 } else if (o is SimpleIdentifier && r is SimpleIdentifier) { |
| 383 expect(r.name, o.name, reason: desc); | 388 expect(r.name, o.name, reason: desc); |
| 384 compareElements(r.staticElement, o.staticElement, desc); | 389 if (namesThatCannotBeResolved.contains(r.name)) { |
| 390 expect(r.staticElement, isNull); |
| 391 } else { |
| 392 compareElements(r.staticElement, o.staticElement, desc); |
| 393 } |
| 385 } else if (o is PrefixedIdentifier && r is SimpleIdentifier) { | 394 } else if (o is PrefixedIdentifier && r is SimpleIdentifier) { |
| 386 // We don't resynthesize prefixed identifiers when the prefix refers to | 395 // We don't resynthesize prefixed identifiers when the prefix refers to |
| 387 // a PrefixElement or a ClassElement. We use simple identifiers with | 396 // a PrefixElement or a ClassElement. We use simple identifiers with |
| 388 // correct elements. | 397 // correct elements. |
| 389 if (o.prefix.staticElement is PrefixElement || | 398 if (o.prefix.staticElement is PrefixElement || |
| 390 o.prefix.staticElement is ClassElement) { | 399 o.prefix.staticElement is ClassElement) { |
| 391 compareConstAsts(r, o.identifier, desc); | 400 compareConstAsts(r, o.identifier, desc); |
| 392 } else { | 401 } else { |
| 393 fail('Prefix of type ${o.prefix.staticElement.runtimeType} should not' | 402 fail('Prefix of type ${o.prefix.staticElement.runtimeType} should not' |
| 394 ' have been elided'); | 403 ' have been elided'); |
| (...skipping 3498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3893 | 3902 |
| 3894 test_invalid_importPrefix_asTypeArgument() { | 3903 test_invalid_importPrefix_asTypeArgument() { |
| 3895 checkLibrary(''' | 3904 checkLibrary(''' |
| 3896 import 'dart:async' as ppp; | 3905 import 'dart:async' as ppp; |
| 3897 class C { | 3906 class C { |
| 3898 List<ppp> v; | 3907 List<ppp> v; |
| 3899 } | 3908 } |
| 3900 '''); | 3909 '''); |
| 3901 } | 3910 } |
| 3902 | 3911 |
| 3912 test_invalid_nameConflict_imported() { |
| 3913 namesThatCannotBeResolved.add('V'); |
| 3914 addLibrarySource('/a.dart', 'V() {}'); |
| 3915 addLibrarySource('/b.dart', 'V() {}'); |
| 3916 checkLibrary(''' |
| 3917 import 'a.dart'; |
| 3918 import 'b.dart'; |
| 3919 foo([p = V]) {} |
| 3920 '''); |
| 3921 } |
| 3922 |
| 3923 test_invalid_nameConflict_imported_exported() { |
| 3924 namesThatCannotBeResolved.add('V'); |
| 3925 addLibrarySource('/a.dart', 'V() {}'); |
| 3926 addLibrarySource('/b.dart', 'V() {}'); |
| 3927 addLibrarySource( |
| 3928 '/c.dart', |
| 3929 r''' |
| 3930 export 'a.dart'; |
| 3931 export 'b.dart'; |
| 3932 '''); |
| 3933 checkLibrary(''' |
| 3934 import 'c.dart'; |
| 3935 foo([p = V]) {} |
| 3936 '''); |
| 3937 } |
| 3938 |
| 3939 test_invalid_nameConflict_local() { |
| 3940 namesThatCannotBeResolved.add('V'); |
| 3941 checkLibrary(''' |
| 3942 foo([p = V]) {} |
| 3943 V() {} |
| 3944 var V; |
| 3945 '''); |
| 3946 } |
| 3947 |
| 3903 test_invalid_setterParameter_fieldFormalParameter() { | 3948 test_invalid_setterParameter_fieldFormalParameter() { |
| 3904 checkLibrary(''' | 3949 checkLibrary(''' |
| 3905 class C { | 3950 class C { |
| 3906 int foo; | 3951 int foo; |
| 3907 void set bar(this.foo) {} | 3952 void set bar(this.foo) {} |
| 3908 } | 3953 } |
| 3909 '''); | 3954 '''); |
| 3910 } | 3955 } |
| 3911 | 3956 |
| 3912 test_invalid_setterParameter_fieldFormalParameter_self() { | 3957 test_invalid_setterParameter_fieldFormalParameter_self() { |
| (...skipping 1242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5155 fail('Unexpectedly tried to get unlinked summary for $uri'); | 5200 fail('Unexpectedly tried to get unlinked summary for $uri'); |
| 5156 } | 5201 } |
| 5157 return serializedUnit; | 5202 return serializedUnit; |
| 5158 } | 5203 } |
| 5159 | 5204 |
| 5160 @override | 5205 @override |
| 5161 bool hasLibrarySummary(String uri) { | 5206 bool hasLibrarySummary(String uri) { |
| 5162 return true; | 5207 return true; |
| 5163 } | 5208 } |
| 5164 } | 5209 } |
| OLD | NEW |