Chromium Code Reviews| 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 908 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 919 if (original.field == null) { | 919 if (original.field == null) { |
| 920 expect(resynthesized.field, isNull, reason: '$desc field'); | 920 expect(resynthesized.field, isNull, reason: '$desc field'); |
| 921 } else { | 921 } else { |
| 922 expect(resynthesized.field, isNotNull, reason: '$desc field'); | 922 expect(resynthesized.field, isNotNull, reason: '$desc field'); |
| 923 compareFieldElements( | 923 compareFieldElements( |
| 924 resynthesized.field, original.field, '$desc field'); | 924 resynthesized.field, original.field, '$desc field'); |
| 925 } | 925 } |
| 926 } | 926 } |
| 927 expect(resynthesized.defaultValueCode, original.defaultValueCode, | 927 expect(resynthesized.defaultValueCode, original.defaultValueCode, |
| 928 reason: desc); | 928 reason: desc); |
| 929 expect(resynthesized.isCovariant, original.isCovariant, reason: desc); | 929 expect((resynthesized as ParameterElementImpl).isExplicitlyCovariant, |
| 930 (original as ParameterElementImpl).isExplicitlyCovariant, | |
| 931 reason: desc); | |
| 932 expect(resynthesized.isCovariant, original.isCovariant, | |
| 933 reason: '$desc isCovariant'); | |
|
scheglov
2017/01/20 00:30:18
We already cast to Impl(s) below.
Brian Wilkerson
2017/01/20 15:59:07
Ok. I moved the first test after the casts and rem
| |
| 930 ParameterElementImpl resynthesizedActual = | 934 ParameterElementImpl resynthesizedActual = |
| 931 getActualElement(resynthesized, desc); | 935 getActualElement(resynthesized, desc); |
| 932 ParameterElementImpl originalActual = getActualElement(original, desc); | 936 ParameterElementImpl originalActual = getActualElement(original, desc); |
| 933 compareFunctionElements( | 937 compareFunctionElements( |
| 934 resynthesizedActual.initializer, originalActual.initializer, desc); | 938 resynthesizedActual.initializer, originalActual.initializer, desc); |
| 935 } | 939 } |
| 936 | 940 |
| 937 void comparePrefixElements(PrefixElementImpl resynthesized, | 941 void comparePrefixElements(PrefixElementImpl resynthesized, |
| 938 PrefixElementImpl original, String desc) { | 942 PrefixElementImpl original, String desc) { |
| 939 compareElements(resynthesized, original, desc); | 943 compareElements(resynthesized, original, desc); |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1198 } else if (modifier == Modifier.ASYNCHRONOUS) { | 1202 } else if (modifier == Modifier.ASYNCHRONOUS) { |
| 1199 if (element is ExecutableElement) { | 1203 if (element is ExecutableElement) { |
| 1200 return element.isAsynchronous; | 1204 return element.isAsynchronous; |
| 1201 } | 1205 } |
| 1202 return false; | 1206 return false; |
| 1203 } else if (modifier == Modifier.CONST) { | 1207 } else if (modifier == Modifier.CONST) { |
| 1204 if (element is VariableElement) { | 1208 if (element is VariableElement) { |
| 1205 return element.isConst; | 1209 return element.isConst; |
| 1206 } | 1210 } |
| 1207 return false; | 1211 return false; |
| 1212 } else if (modifier == Modifier.COVARIANT) { | |
| 1213 if (element is ParameterElementImpl) { | |
| 1214 return element.isExplicitlyCovariant; | |
| 1215 } | |
| 1216 return false; | |
| 1208 } else if (modifier == Modifier.DEFERRED) { | 1217 } else if (modifier == Modifier.DEFERRED) { |
| 1209 if (element is ImportElement) { | 1218 if (element is ImportElement) { |
| 1210 return element.isDeferred; | 1219 return element.isDeferred; |
| 1211 } | 1220 } |
| 1212 return false; | 1221 return false; |
| 1213 } else if (modifier == Modifier.ENUM) { | 1222 } else if (modifier == Modifier.ENUM) { |
| 1214 if (element is ClassElement) { | 1223 if (element is ClassElement) { |
| 1215 return element.isEnum; | 1224 return element.isEnum; |
| 1216 } | 1225 } |
| 1217 return false; | 1226 return false; |
| (...skipping 1597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2815 final x; | 2824 final x; |
| 2816 C() : x = new D(); | 2825 C() : x = new D(); |
| 2817 } | 2826 } |
| 2818 class D { | 2827 class D { |
| 2819 final x; | 2828 final x; |
| 2820 D() : x = new C(); | 2829 D() : x = new C(); |
| 2821 } | 2830 } |
| 2822 '''); | 2831 '''); |
| 2823 } | 2832 } |
| 2824 | 2833 |
| 2825 void test_covariant_parameter() { | |
| 2826 // Note: due to dartbug.com/27393, the keyword "checked" is identified by | |
| 2827 // its presence in a library called "meta". If that bug is fixed, this test | |
| 2828 // my need to be changed. | |
| 2829 checkLibrary(r''' | |
| 2830 library meta; | |
| 2831 const checked = null; | |
| 2832 class A<T> { | |
| 2833 void f(@checked T t) {} | |
| 2834 } | |
| 2835 '''); | |
| 2836 } | |
| 2837 | |
| 2838 void test_covariant_parameter_inherited() { | |
| 2839 // Note: due to dartbug.com/27393, the keyword "checked" is identified by | |
| 2840 // its presence in a library called "meta". If that bug is fixed, this test | |
| 2841 // my need to be changed. | |
| 2842 checkLibrary(r''' | |
| 2843 library meta; | |
| 2844 const checked = null; | |
| 2845 class A<T> { | |
| 2846 void f(@checked T t) {} | |
| 2847 } | |
| 2848 class B<T> extends A<T> { | |
| 2849 void f(T t) {} | |
| 2850 } | |
| 2851 '''); | |
| 2852 } | |
| 2853 | |
| 2854 test_defaultValue_refersToGenericClass_constructor() { | 2834 test_defaultValue_refersToGenericClass_constructor() { |
| 2855 checkLibrary(''' | 2835 checkLibrary(''' |
| 2856 class B<T> { | 2836 class B<T> { |
| 2857 const B(); | 2837 const B(); |
| 2858 } | 2838 } |
| 2859 class C<T> { | 2839 class C<T> { |
| 2860 const C([B<T> b = const B()]); | 2840 const C([B<T> b = const B()]); |
| 2861 } | 2841 } |
| 2862 '''); | 2842 '''); |
| 2863 } | 2843 } |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3096 var typeA = library.definingCompilationUnit.getType('B').supertype; | 3076 var typeA = library.definingCompilationUnit.getType('B').supertype; |
| 3097 expect(typeA.element.source.shortName, 'foo_io.dart'); | 3077 expect(typeA.element.source.shortName, 'foo_io.dart'); |
| 3098 } | 3078 } |
| 3099 | 3079 |
| 3100 test_exports() { | 3080 test_exports() { |
| 3101 addLibrarySource('/a.dart', 'library a;'); | 3081 addLibrarySource('/a.dart', 'library a;'); |
| 3102 addLibrarySource('/b.dart', 'library b;'); | 3082 addLibrarySource('/b.dart', 'library b;'); |
| 3103 checkLibrary('export "a.dart"; export "b.dart";'); | 3083 checkLibrary('export "a.dart"; export "b.dart";'); |
| 3104 } | 3084 } |
| 3105 | 3085 |
| 3086 test_field_covariant() { | |
| 3087 checkLibrary(''' | |
| 3088 class C { | |
| 3089 covariant int x; | |
| 3090 }'''); | |
| 3091 } | |
| 3092 | |
| 3106 test_field_documented() { | 3093 test_field_documented() { |
| 3107 checkLibrary(''' | 3094 checkLibrary(''' |
| 3108 class C { | 3095 class C { |
| 3109 /** | 3096 /** |
| 3110 * Docs | 3097 * Docs |
| 3111 */ | 3098 */ |
| 3112 var x; | 3099 var x; |
| 3113 }'''); | 3100 }'''); |
| 3114 } | 3101 } |
| 3115 | 3102 |
| (...skipping 1051 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4167 test_method_inferred_type_nonStatic_implicit_param() { | 4154 test_method_inferred_type_nonStatic_implicit_param() { |
| 4168 checkLibrary('class C extends D { void f(value) {} }' | 4155 checkLibrary('class C extends D { void f(value) {} }' |
| 4169 ' abstract class D { void f(int value); }'); | 4156 ' abstract class D { void f(int value); }'); |
| 4170 } | 4157 } |
| 4171 | 4158 |
| 4172 test_method_inferred_type_nonStatic_implicit_return() { | 4159 test_method_inferred_type_nonStatic_implicit_return() { |
| 4173 checkLibrary( | 4160 checkLibrary( |
| 4174 'class C extends D { f() => null; } abstract class D { int f(); }'); | 4161 'class C extends D { f() => null; } abstract class D { int f(); }'); |
| 4175 } | 4162 } |
| 4176 | 4163 |
| 4177 test_method_parameter_parameters() { | |
| 4178 checkLibrary('class C { f(g(x, y)) {} }'); | |
| 4179 } | |
| 4180 | |
| 4181 test_method_parameter_parameters_in_generic_class() { | |
| 4182 checkLibrary('class C<A, B> { f(A g(B x)) {} }'); | |
| 4183 } | |
| 4184 | |
| 4185 test_method_parameter_return_type() { | |
| 4186 checkLibrary('class C { f(int g()) {} }'); | |
| 4187 } | |
| 4188 | |
| 4189 test_method_parameter_return_type_void() { | |
| 4190 checkLibrary('class C { f(void g()) {} }'); | |
| 4191 } | |
| 4192 | |
| 4193 test_method_type_parameter() { | 4164 test_method_type_parameter() { |
| 4194 prepareAnalysisContext(createOptions()); | 4165 prepareAnalysisContext(createOptions()); |
| 4195 checkLibrary('class C { T f<T, U>(U u) => null; }'); | 4166 checkLibrary('class C { T f<T, U>(U u) => null; }'); |
| 4196 } | 4167 } |
| 4197 | 4168 |
| 4198 test_method_type_parameter_in_generic_class() { | 4169 test_method_type_parameter_in_generic_class() { |
| 4199 prepareAnalysisContext(createOptions()); | 4170 prepareAnalysisContext(createOptions()); |
| 4200 checkLibrary('class C<T, U> { V f<V, W>(T t, U u, W w) => null; }'); | 4171 checkLibrary('class C<T, U> { V f<V, W>(T t, U u, W w) => null; }'); |
| 4201 } | 4172 } |
| 4202 | 4173 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4282 } | 4253 } |
| 4283 | 4254 |
| 4284 test_operator_index_set() { | 4255 test_operator_index_set() { |
| 4285 checkLibrary('class C { void operator[]=(int i, bool v) {} }'); | 4256 checkLibrary('class C { void operator[]=(int i, bool v) {} }'); |
| 4286 } | 4257 } |
| 4287 | 4258 |
| 4288 test_operator_less_equal() { | 4259 test_operator_less_equal() { |
| 4289 checkLibrary('class C { bool operator<=(C other) => false; }'); | 4260 checkLibrary('class C { bool operator<=(C other) => false; }'); |
| 4290 } | 4261 } |
| 4291 | 4262 |
| 4263 void test_parameter_checked() { | |
| 4264 // Note: due to dartbug.com/27393, the keyword "checked" is identified by | |
| 4265 // its presence in a library called "meta". If that bug is fixed, this test | |
| 4266 // my need to be changed. | |
| 4267 checkLibrary(r''' | |
| 4268 library meta; | |
| 4269 const checked = null; | |
| 4270 class A<T> { | |
| 4271 void f(@checked T t) {} | |
| 4272 } | |
| 4273 '''); | |
| 4274 } | |
| 4275 | |
| 4276 void test_parameter_checked_inherited() { | |
| 4277 // Note: due to dartbug.com/27393, the keyword "checked" is identified by | |
| 4278 // its presence in a library called "meta". If that bug is fixed, this test | |
| 4279 // my need to be changed. | |
| 4280 checkLibrary(r''' | |
| 4281 library meta; | |
| 4282 const checked = null; | |
| 4283 class A<T> { | |
| 4284 void f(@checked T t) {} | |
| 4285 } | |
| 4286 class B<T> extends A<T> { | |
| 4287 void f(T t) {} | |
| 4288 } | |
| 4289 '''); | |
| 4290 } | |
| 4291 | |
| 4292 test_parameter_covariant() { | |
| 4293 prepareAnalysisContext(createOptions()); | |
| 4294 checkLibrary('class C { void m(covariant C c) {} }'); | |
| 4295 } | |
| 4296 | |
| 4297 void test_parameter_covariant_inherited() { | |
| 4298 checkLibrary(r''' | |
| 4299 class A<T> { | |
| 4300 void f(covariant T t) {} | |
| 4301 } | |
| 4302 class B<T> extends A<T> { | |
| 4303 void f(T t) {} | |
| 4304 } | |
| 4305 '''); | |
| 4306 } | |
| 4307 | |
| 4308 test_parameter_parameters() { | |
| 4309 checkLibrary('class C { f(g(x, y)) {} }'); | |
| 4310 } | |
| 4311 | |
| 4312 test_parameter_parameters_in_generic_class() { | |
| 4313 checkLibrary('class C<A, B> { f(A g(B x)) {} }'); | |
| 4314 } | |
| 4315 | |
| 4316 test_parameter_return_type() { | |
| 4317 checkLibrary('class C { f(int g()) {} }'); | |
| 4318 } | |
| 4319 | |
| 4320 test_parameter_return_type_void() { | |
| 4321 checkLibrary('class C { f(void g()) {} }'); | |
| 4322 } | |
| 4323 | |
| 4292 test_parameterTypeNotInferred_constructor() { | 4324 test_parameterTypeNotInferred_constructor() { |
| 4293 // Strong mode doesn't do type inference on constructor parameters, so it's | 4325 // Strong mode doesn't do type inference on constructor parameters, so it's |
| 4294 // ok that we don't store inferred type info for them in summaries. | 4326 // ok that we don't store inferred type info for them in summaries. |
| 4295 checkLibrary(''' | 4327 checkLibrary(''' |
| 4296 class C { | 4328 class C { |
| 4297 C.positional([x = 1]); | 4329 C.positional([x = 1]); |
| 4298 C.named({x: 1}); | 4330 C.named({x: 1}); |
| 4299 } | 4331 } |
| 4300 '''); | 4332 '''); |
| 4301 } | 4333 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4356 | 4388 |
| 4357 test_propagated_type_refers_to_closure() { | 4389 test_propagated_type_refers_to_closure() { |
| 4358 checkLibrary(''' | 4390 checkLibrary(''' |
| 4359 void f() { | 4391 void f() { |
| 4360 var x = () => 0; | 4392 var x = () => 0; |
| 4361 var y = x; | 4393 var y = x; |
| 4362 } | 4394 } |
| 4363 '''); | 4395 '''); |
| 4364 } | 4396 } |
| 4365 | 4397 |
| 4398 test_setter_covariant() { | |
| 4399 checkLibrary('class C { void set x(covariant int value); }'); | |
| 4400 } | |
| 4401 | |
| 4366 test_setter_documented() { | 4402 test_setter_documented() { |
| 4367 checkLibrary(''' | 4403 checkLibrary(''' |
| 4368 // Extra comment so doc comment offset != 0 | 4404 // Extra comment so doc comment offset != 0 |
| 4369 /** | 4405 /** |
| 4370 * Docs | 4406 * Docs |
| 4371 */ | 4407 */ |
| 4372 void set x(value) {}'''); | 4408 void set x(value) {}'''); |
| 4373 } | 4409 } |
| 4374 | 4410 |
| 4375 test_setter_external() { | 4411 test_setter_external() { |
| (...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4898 fail('Unexpectedly tried to get unlinked summary for $uri'); | 4934 fail('Unexpectedly tried to get unlinked summary for $uri'); |
| 4899 } | 4935 } |
| 4900 return serializedUnit; | 4936 return serializedUnit; |
| 4901 } | 4937 } |
| 4902 | 4938 |
| 4903 @override | 4939 @override |
| 4904 bool hasLibrarySummary(String uri) { | 4940 bool hasLibrarySummary(String uri) { |
| 4905 return true; | 4941 return true; |
| 4906 } | 4942 } |
| 4907 } | 4943 } |
| OLD | NEW |