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/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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 239 compareTypes(r.staticType, o.staticType, desc); | 239 compareTypes(r.staticType, o.staticType, desc); |
| 240 if (o is ParenthesizedExpression) { | 240 if (o is ParenthesizedExpression) { |
| 241 // We don't resynthesize parenthesis, so just ignore it. | 241 // We don't resynthesize parenthesis, so just ignore it. |
| 242 compareConstantExpressions(r, o.expression, desc); | 242 compareConstantExpressions(r, o.expression, desc); |
| 243 } else if (o is SimpleIdentifier && r is SimpleIdentifier) { | 243 } else if (o is SimpleIdentifier && r is SimpleIdentifier) { |
| 244 expect(r.name, o.name); | 244 expect(r.name, o.name); |
| 245 compareElements(r.staticElement, o.staticElement, desc); | 245 compareElements(r.staticElement, o.staticElement, desc); |
| 246 // ConstantAstCloner does not copy static types, and constant values | 246 // ConstantAstCloner does not copy static types, and constant values |
| 247 // computer does not use static types. So, we don't set them during | 247 // computer does not use static types. So, we don't set them during |
| 248 // resynthesis and should not check them. | 248 // resynthesis and should not check them. |
| 249 } else if (o is PrefixedIdentifier) { | 249 } else if (o is PrefixedIdentifier && r is SimpleIdentifier) { |
| 250 // We don't resynthesize prefixed identifiers. | 250 // We don't resynthesize prefixed identifiers. |
| 251 // We use simple identifiers with correct elements and types. | 251 // We use simple identifiers with correct elements. |
| 252 compareConstantExpressions(r as SimpleIdentifier, o.identifier, desc); | 252 compareConstantExpressions(r, o.identifier, desc); |
| 253 } else if (o is PropertyAccess && r is SimpleIdentifier) { | |
| 254 // We don't resynthesize property access. | |
| 255 // We use simple identifiers with correct elements. | |
| 256 compareConstantExpressions(r, o.propertyName, desc); | |
|
Paul Berry
2016/02/01 19:27:17
What about the case of:
const x = 'foo';
scheglov
2016/02/01 19:42:18
We don't support 'length' resynthesizing yet.
| |
| 253 } else if (o is NullLiteral) { | 257 } else if (o is NullLiteral) { |
| 254 expect(r, new isInstanceOf<NullLiteral>(), reason: desc); | 258 expect(r, new isInstanceOf<NullLiteral>(), reason: desc); |
| 255 } else if (o is BooleanLiteral && r is BooleanLiteral) { | 259 } else if (o is BooleanLiteral && r is BooleanLiteral) { |
| 256 expect(r.value, o.value, reason: desc); | 260 expect(r.value, o.value, reason: desc); |
| 257 } else if (o is IntegerLiteral && r is IntegerLiteral) { | 261 } else if (o is IntegerLiteral && r is IntegerLiteral) { |
| 258 expect(r.value, o.value, reason: desc); | 262 expect(r.value, o.value, reason: desc); |
| 259 } else if (o is DoubleLiteral && r is DoubleLiteral) { | 263 } else if (o is DoubleLiteral && r is DoubleLiteral) { |
| 260 expect(r.value, o.value, reason: desc); | 264 expect(r.value, o.value, reason: desc); |
| 261 } else if (o is StringInterpolation && r is StringInterpolation) { | 265 } else if (o is StringInterpolation && r is StringInterpolation) { |
| 262 compareLists(r.elements, o.elements); | 266 compareLists(r.elements, o.elements); |
| (...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1003 } | 1007 } |
| 1004 | 1008 |
| 1005 test_class_type_parameters_f_bound_simple() { | 1009 test_class_type_parameters_f_bound_simple() { |
| 1006 checkLibrary('class C<T extends U, U> {}'); | 1010 checkLibrary('class C<T extends U, U> {}'); |
| 1007 } | 1011 } |
| 1008 | 1012 |
| 1009 test_classes() { | 1013 test_classes() { |
| 1010 checkLibrary('class C {} class D {}'); | 1014 checkLibrary('class C {} class D {}'); |
| 1011 } | 1015 } |
| 1012 | 1016 |
| 1017 test_const_reference_staticField() { | |
| 1018 shouldCompareConstValues = true; | |
| 1019 checkLibrary(r''' | |
| 1020 class C { | |
| 1021 static const int F = 42; | |
| 1022 } | |
| 1023 const V = C.F; | |
| 1024 '''); | |
| 1025 } | |
| 1026 | |
| 1027 test_const_reference_staticField_imported() { | |
| 1028 shouldCompareConstValues = true; | |
| 1029 addLibrarySource( | |
| 1030 '/a.dart', | |
| 1031 r''' | |
| 1032 class C { | |
| 1033 static const int F = 42; | |
| 1034 } | |
| 1035 '''); | |
| 1036 checkLibrary(r''' | |
| 1037 import 'a.dart'; | |
| 1038 const V = C.F; | |
| 1039 '''); | |
| 1040 } | |
| 1041 | |
| 1042 test_const_reference_staticField_imported_withPrefix() { | |
| 1043 shouldCompareConstValues = true; | |
| 1044 addLibrarySource( | |
| 1045 '/a.dart', | |
| 1046 r''' | |
| 1047 class C { | |
| 1048 static const int F = 42; | |
| 1049 } | |
| 1050 '''); | |
| 1051 checkLibrary(r''' | |
| 1052 import 'a.dart' as p; | |
| 1053 const V = p.C.F; | |
| 1054 '''); | |
| 1055 } | |
| 1056 | |
| 1057 test_const_reference_topLevelVariable() { | |
| 1058 shouldCompareConstValues = true; | |
| 1059 checkLibrary(r''' | |
| 1060 const A = 1; | |
| 1061 const B = A + 2; | |
| 1062 '''); | |
| 1063 } | |
| 1064 | |
| 1065 test_const_reference_topLevelVariable_imported() { | |
| 1066 shouldCompareConstValues = true; | |
| 1067 addLibrarySource( | |
| 1068 '/a.dart', | |
| 1069 r''' | |
| 1070 const A = 1; | |
| 1071 '''); | |
| 1072 checkLibrary(r''' | |
| 1073 import 'a.dart'; | |
| 1074 const B = A + 2; | |
| 1075 '''); | |
| 1076 } | |
| 1077 | |
| 1078 test_const_reference_topLevelVariable_imported_withPrefix() { | |
| 1079 shouldCompareConstValues = true; | |
| 1080 addLibrarySource( | |
| 1081 '/a.dart', | |
| 1082 r''' | |
| 1083 const A = 1; | |
| 1084 '''); | |
| 1085 checkLibrary(r''' | |
| 1086 import 'a.dart' as p; | |
| 1087 const B = p.A + 2; | |
| 1088 '''); | |
| 1089 } | |
| 1090 | |
| 1013 test_const_reference_type() { | 1091 test_const_reference_type() { |
| 1014 shouldCompareConstValues = true; | 1092 shouldCompareConstValues = true; |
| 1015 checkLibrary(r''' | 1093 checkLibrary(r''' |
| 1016 class C {} | 1094 class C {} |
| 1017 class D<T> {} | 1095 class D<T> {} |
| 1018 enum E {a, b, c} | 1096 enum E {a, b, c} |
| 1019 typedef F(int a, String b); | 1097 typedef F(int a, String b); |
| 1020 const vDynamic = dynamic; | 1098 const vDynamic = dynamic; |
| 1021 const vNull = Null; | 1099 const vNull = Null; |
| 1022 const vObject = Object; | 1100 const vObject = Object; |
| (...skipping 1110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2133 fail('Unexpectedly tried to get unlinked summary for $uri'); | 2211 fail('Unexpectedly tried to get unlinked summary for $uri'); |
| 2134 } | 2212 } |
| 2135 return serializedUnit; | 2213 return serializedUnit; |
| 2136 } | 2214 } |
| 2137 | 2215 |
| 2138 @override | 2216 @override |
| 2139 bool hasLibrarySummary(String uri) { | 2217 bool hasLibrarySummary(String uri) { |
| 2140 return true; | 2218 return true; |
| 2141 } | 2219 } |
| 2142 } | 2220 } |
| OLD | NEW |