| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 import 'package:analyzer/dart/ast/ast.dart'; | 5 import 'package:analyzer/dart/ast/ast.dart'; |
| 6 import 'package:analyzer/dart/ast/token.dart'; | 6 import 'package:analyzer/dart/ast/token.dart'; |
| 7 import 'package:analyzer/file_system/file_system.dart'; | 7 import 'package:analyzer/file_system/file_system.dart'; |
| 8 import 'package:analyzer/file_system/memory_file_system.dart'; | 8 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 9 import 'package:analyzer/src/dart/sdk/patch.dart'; | 9 import 'package:analyzer/src/dart/sdk/patch.dart'; |
| 10 import 'package:analyzer/src/dart/sdk/sdk.dart'; | 10 import 'package:analyzer/src/dart/sdk/sdk.dart'; |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 '''); | 219 '''); |
| 220 _assertUnitCode(unit, 'class C {int f; C.named() : f = 2 {print(42);}}'); | 220 _assertUnitCode(unit, 'class C {int f; C.named() : f = 2 {print(42);}}'); |
| 221 ClassDeclaration clazz = unit.declarations[0]; | 221 ClassDeclaration clazz = unit.declarations[0]; |
| 222 ConstructorDeclaration constructor = clazz.members[1]; | 222 ConstructorDeclaration constructor = clazz.members[1]; |
| 223 expect(constructor.externalKeyword, isNull); | 223 expect(constructor.externalKeyword, isNull); |
| 224 _assertPrevNextToken(constructor.parameters.endToken, | 224 _assertPrevNextToken(constructor.parameters.endToken, |
| 225 constructor.initializers.beginToken.previous); | 225 constructor.initializers.beginToken.previous); |
| 226 _assertPrevNextToken(constructor.endToken, clazz.rightBracket); | 226 _assertPrevNextToken(constructor.endToken, clazz.rightBracket); |
| 227 } | 227 } |
| 228 | 228 |
| 229 test_class_field_append() { |
| 230 CompilationUnit unit = _doTopLevelPatching( |
| 231 r''' |
| 232 class C { |
| 233 void a() {} |
| 234 } |
| 235 ''', |
| 236 r''' |
| 237 @patch |
| 238 class C { |
| 239 int _b = 42; |
| 240 } |
| 241 '''); |
| 242 _assertUnitCode(unit, 'class C {void a() {} int _b = 42;}'); |
| 243 ClassDeclaration clazz = unit.declarations[0]; |
| 244 MethodDeclaration a = clazz.members[0]; |
| 245 FieldDeclaration b = clazz.members[1]; |
| 246 _assertPrevNextToken(a.endToken, b.beginToken); |
| 247 _assertPrevNextToken(b.endToken, clazz.rightBracket); |
| 248 } |
| 249 |
| 250 test_class_field_append_fail_moreThanOne() { |
| 251 expect(() { |
| 252 _doTopLevelPatching( |
| 253 r''' |
| 254 class A {} |
| 255 ''', |
| 256 r''' |
| 257 @patch |
| 258 class A { |
| 259 @patch |
| 260 int _f1, _f2; |
| 261 } |
| 262 '''); |
| 263 }, throwsArgumentError); |
| 264 } |
| 265 |
| 266 test_class_field_append_fail_notPrivate() { |
| 267 expect(() { |
| 268 _doTopLevelPatching( |
| 269 r''' |
| 270 class A {} |
| 271 ''', |
| 272 r''' |
| 273 @patch |
| 274 class A { |
| 275 @patch |
| 276 int b; |
| 277 } |
| 278 '''); |
| 279 }, throwsArgumentError); |
| 280 } |
| 281 |
| 282 test_class_field_append_publiInPrivateClass() { |
| 283 CompilationUnit unit = _doTopLevelPatching( |
| 284 r''' |
| 285 class _C { |
| 286 void a() {} |
| 287 } |
| 288 ''', |
| 289 r''' |
| 290 @patch |
| 291 class _C { |
| 292 int b = 42; |
| 293 } |
| 294 '''); |
| 295 _assertUnitCode(unit, 'class _C {void a() {} int b = 42;}'); |
| 296 ClassDeclaration clazz = unit.declarations[0]; |
| 297 MethodDeclaration a = clazz.members[0]; |
| 298 FieldDeclaration b = clazz.members[1]; |
| 299 _assertPrevNextToken(a.endToken, b.beginToken); |
| 300 _assertPrevNextToken(b.endToken, clazz.rightBracket); |
| 301 } |
| 302 |
| 303 test_class_field_patch_fail() { |
| 304 expect(() { |
| 305 _doTopLevelPatching( |
| 306 r''' |
| 307 class A {} |
| 308 ''', |
| 309 r''' |
| 310 @patch |
| 311 class A { |
| 312 @patch |
| 313 int _f; |
| 314 } |
| 315 '''); |
| 316 }, throwsArgumentError); |
| 317 } |
| 318 |
| 229 test_class_getter_append() { | 319 test_class_getter_append() { |
| 230 CompilationUnit unit = _doTopLevelPatching( | 320 CompilationUnit unit = _doTopLevelPatching( |
| 231 r''' | 321 r''' |
| 232 class C { | 322 class C { |
| 233 void a() {} | 323 void a() {} |
| 234 } | 324 } |
| 235 ''', | 325 ''', |
| 236 r''' | 326 r''' |
| 237 @patch | 327 @patch |
| 238 class C { | 328 class C { |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 void _setSdkLibraries(String code) { | 728 void _setSdkLibraries(String code) { |
| 639 provider.newFile( | 729 provider.newFile( |
| 640 _p('/sdk/lib/_internal/sdk_library_metadata/lib/libraries.dart'), code); | 730 _p('/sdk/lib/_internal/sdk_library_metadata/lib/libraries.dart'), code); |
| 641 } | 731 } |
| 642 | 732 |
| 643 static void _assertPrevNextToken(Token prev, Token next) { | 733 static void _assertPrevNextToken(Token prev, Token next) { |
| 644 expect(prev.next, same(next)); | 734 expect(prev.next, same(next)); |
| 645 expect(next.previous, same(prev)); | 735 expect(next.previous, same(prev)); |
| 646 } | 736 } |
| 647 } | 737 } |
| OLD | NEW |