| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart Team. All rights reserved. Use of this | 1 // Copyright (c) 2015, the Dart Team. All rights reserved. Use of this |
| 2 // source code is governed by a BSD-style license that can be found in | 2 // source code is governed by a BSD-style license that can be found in |
| 3 // the LICENSE file. | 3 // the LICENSE file. |
| 4 | 4 |
| 5 // TODO(sigurdm) doc: Make NoSuchCapability messages streamlined (the same in | 5 // TODO(sigurdm) doc: Make NoSuchCapability messages streamlined (the same in |
| 6 // both `reflectable_mirror_based.dart` and | 6 // both `reflectable_mirror_based.dart` and |
| 7 // `reflectable_transformer_based.dart`, and explaining as well as possible | 7 // `reflectable_transformer_based.dart`, and explaining as well as possible |
| 8 // which capability is missing.) | 8 // which capability is missing.) |
| 9 | 9 |
| 10 /// Implementation of the reflectable interface using dart mirrors. | 10 /// Implementation of the reflectable interface using dart mirrors. |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 } | 250 } |
| 251 return false; | 251 return false; |
| 252 } else { | 252 } else { |
| 253 return false; | 253 return false; |
| 254 } | 254 } |
| 255 } | 255 } |
| 256 | 256 |
| 257 bool result = reflectable.hasCapability(predicate); | 257 bool result = reflectable.hasCapability(predicate); |
| 258 if (!result && | 258 if (!result && |
| 259 impliesCorrespondingSetter(reflectable.capabilities) && | 259 impliesCorrespondingSetter(reflectable.capabilities) && |
| 260 name.endsWith("=")) { | 260 _isSetterName(name)) { |
| 261 return reflectableSupportsInstanceInvoke( | 261 return reflectableSupportsInstanceInvoke( |
| 262 reflectable, name.substring(0, name.length - 1), classMirror); | 262 reflectable, _setterNameToGetterName(name), classMirror); |
| 263 } | 263 } |
| 264 return result; | 264 return result; |
| 265 } | 265 } |
| 266 | 266 |
| 267 /// Returns true if [classMirror] supports looking up the declaration of the | 267 /// Returns true if [classMirror] supports looking up the declaration of the |
| 268 /// instance-member named [name] according to the capabilities of [reflectable]. | 268 /// instance-member named [name] according to the capabilities of [reflectable]. |
| 269 bool reflectableSupportsDeclaration( | 269 bool reflectableSupportsDeclaration( |
| 270 ReflectableImpl reflectable, String name, dm.ClassMirror classMirror) { | 270 ReflectableImpl reflectable, String name, dm.ClassMirror classMirror) { |
| 271 Symbol nameSymbol = new Symbol(name); | 271 Symbol nameSymbol = new Symbol(name); |
| 272 | 272 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 } | 309 } |
| 310 if (capability is StaticInvokeMetaCapability) { | 310 if (capability is StaticInvokeMetaCapability) { |
| 311 return metadataSupported(metadata, capability); | 311 return metadataSupported(metadata, capability); |
| 312 } | 312 } |
| 313 return false; | 313 return false; |
| 314 } | 314 } |
| 315 | 315 |
| 316 bool result = reflectable.hasCapability(predicate); | 316 bool result = reflectable.hasCapability(predicate); |
| 317 if (!result && | 317 if (!result && |
| 318 impliesCorrespondingSetter(reflectable.capabilities) && | 318 impliesCorrespondingSetter(reflectable.capabilities) && |
| 319 name.endsWith("=")) { | 319 _isSetterName(name)) { |
| 320 result = reflectableSupportsStaticInvoke( | 320 result = reflectableSupportsStaticInvoke( |
| 321 reflectable, name.substring(0, name.length - 1), getterMetadata, null); | 321 reflectable, _setterNameToGetterName(name), getterMetadata, null); |
| 322 } | 322 } |
| 323 return result; | 323 return result; |
| 324 } | 324 } |
| 325 | 325 |
| 326 /// Returns true iff [reflectable] supports top-level invoke of [name]. | 326 /// Returns true iff [reflectable] supports top-level invoke of [name]. |
| 327 bool reflectableSupportsTopLevelInvoke(ReflectableImpl reflectable, String name, | 327 bool reflectableSupportsTopLevelInvoke(ReflectableImpl reflectable, String name, |
| 328 List<dm.InstanceMirror> metadata) { | 328 List<dm.InstanceMirror> metadata, List<dm.InstanceMirror> getterMetadata) { |
| 329 // We don't have to check for `libraryCapability` because this method is only | 329 // We don't have to check for `libraryCapability` because this method is only |
| 330 // ever called from the methods of a `LibraryMirrorImpl` and the existence of | 330 // ever called from the methods of a `LibraryMirrorImpl` and the existence of |
| 331 // an instance of a `LibraryMirrorImpl` implies the `libraryMirrorCapability`. | 331 // an instance of a `LibraryMirrorImpl` implies the `libraryMirrorCapability`. |
| 332 // Finally, we do not have to check for the capability as given to a subtype, | 332 // Finally, we do not have to check for the capability as given to a subtype, |
| 333 // because a library is never a subtype of anything. | 333 // because a library is never a subtype of anything. |
| 334 return reflectable.hasCapability((ApiReflectCapability capability) { | 334 return reflectable.hasCapability((ApiReflectCapability capability) { |
| 335 if (capability == topLevelInvokeCapability) { | 335 if (capability == topLevelInvokeCapability) { |
| 336 return true; | 336 return true; |
| 337 } else if (capability is TopLevelInvokeCapability) { | 337 } else if (capability is TopLevelInvokeCapability) { |
| 338 return new RegExp(capability.namePattern).hasMatch(name); | 338 return new RegExp(capability.namePattern).hasMatch(name); |
| 339 } | 339 } |
| 340 if (capability is TopLevelInvokeMetaCapability) { | 340 if (capability is TopLevelInvokeMetaCapability) { |
| 341 return metadataSupported(metadata, capability); | 341 return metadataSupported(metadata, capability); |
| 342 } | 342 } |
| 343 if (impliesCorrespondingSetter(reflectable.capabilities) && |
| 344 _isSetterName(name)) { |
| 345 return reflectableSupportsTopLevelInvoke( |
| 346 reflectable, _setterNameToGetterName(name), getterMetadata, null); |
| 347 } |
| 343 return false; | 348 return false; |
| 344 }); | 349 }); |
| 345 } | 350 } |
| 346 | 351 |
| 347 /// Returns true iff [reflectable] supports invoke of [name]. | 352 /// Returns true iff [reflectable] supports invoke of [name]. |
| 348 bool reflectableSupportsConstructorInvoke( | 353 bool reflectableSupportsConstructorInvoke( |
| 349 ReflectableImpl reflectable, dm.ClassMirror classMirror, String name) { | 354 ReflectableImpl reflectable, dm.ClassMirror classMirror, String name) { |
| 350 bool predicate(ApiReflectCapability capability) { | 355 bool predicate(ApiReflectCapability capability) { |
| 351 if (capability == newInstanceCapability) { | 356 if (capability == newInstanceCapability) { |
| 352 return true; | 357 return true; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 372 | 377 |
| 373 bool reflectableSupportsDeclarations(Reflectable reflectable) { | 378 bool reflectableSupportsDeclarations(Reflectable reflectable) { |
| 374 bool predicate(ApiReflectCapability capability) => | 379 bool predicate(ApiReflectCapability capability) => |
| 375 capability == declarationsCapability; | 380 capability == declarationsCapability; |
| 376 return reflectable.hasCapability(predicate); | 381 return reflectable.hasCapability(predicate); |
| 377 } | 382 } |
| 378 | 383 |
| 379 /// Returns [setterName] with final "=" removed. | 384 /// Returns [setterName] with final "=" removed. |
| 380 /// If the it does not have a final "=" it is returned as is. | 385 /// If the it does not have a final "=" it is returned as is. |
| 381 String _setterToGetter(String setterName) { | 386 String _setterToGetter(String setterName) { |
| 382 if (!setterName.endsWith("=")) { | 387 if (!_isSetterName(setterName)) { |
| 383 return setterName; | 388 return setterName; |
| 384 } | 389 } |
| 385 return setterName.substring(0, setterName.length - 1); | 390 return _setterNameToGetterName(setterName); |
| 386 } | 391 } |
| 387 | 392 |
| 388 /// Returns [getterName] with a final "=" added. | 393 /// Returns [getterName] with a final "=" added. |
| 389 /// If [getter] already ends with "=" an error is thrown. | 394 /// If [getter] already ends with "=" an error is thrown. |
| 390 String _getterToSetter(String getterName) { | 395 String _getterToSetter(String getterName) { |
| 391 if (getterName.endsWith("=")) { | 396 if (_isSetterName(getterName)) { |
| 392 throw new ArgumentError( | 397 throw new ArgumentError( |
| 393 "$getterName is a setter name (ends with `=`) already."); | 398 "$getterName is a setter name (ends with `=`) already."); |
| 394 } | 399 } |
| 395 return '$getterName='; | 400 return '$getterName='; |
| 396 } | 401 } |
| 397 | 402 |
| 398 bool _supportsType(List<ReflectCapability> capabilities) { | 403 bool _supportsType(List<ReflectCapability> capabilities) { |
| 399 return capabilities | 404 return capabilities |
| 400 .any((ReflectCapability capability) => capability is TypeCapability); | 405 .any((ReflectCapability capability) => capability is TypeCapability); |
| 401 } | 406 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 414 | 419 |
| 415 @override | 420 @override |
| 416 Uri get uri => _libraryMirror.uri; | 421 Uri get uri => _libraryMirror.uri; |
| 417 | 422 |
| 418 @override | 423 @override |
| 419 Map<String, rm.DeclarationMirror> get declarations { | 424 Map<String, rm.DeclarationMirror> get declarations { |
| 420 if (!reflectableSupportsDeclarations(_reflectable)) { | 425 if (!reflectableSupportsDeclarations(_reflectable)) { |
| 421 throw new NoSuchCapabilityError( | 426 throw new NoSuchCapabilityError( |
| 422 "Attempt to get declarations without capability"); | 427 "Attempt to get declarations without capability"); |
| 423 } | 428 } |
| 424 Map<Symbol, dm.DeclarationMirror> decls = _libraryMirror.declarations; | 429 Map<String, rm.DeclarationMirror> result = |
| 425 Iterable<Symbol> relevantKeys = decls.keys.where((k) { | 430 new Map<String, rm.DeclarationMirror>(); |
| 426 List<dm.InstanceMirror> metadata = decls[k].metadata; | 431 _libraryMirror.declarations |
| 427 for (var item in metadata) { | 432 .forEach((Symbol nameSymbol, dm.DeclarationMirror declarationMirror) { |
| 428 if (item.hasReflectee && item.reflectee == _reflectable) return true; | 433 String name = dm.MirrorSystem.getName(nameSymbol); |
| 434 if (declarationMirror is dm.MethodMirror) { |
| 435 List<dm.InstanceMirror> getterMetadata = null; |
| 436 if (declarationMirror.isSetter && |
| 437 !declarationMirror.isSynthetic && |
| 438 _isSetterName(name)) { |
| 439 dm.DeclarationMirror correspondingGetter = |
| 440 _libraryMirror.declarations[ |
| 441 new Symbol(_setterNameToGetterName(name))]; |
| 442 getterMetadata = correspondingGetter?.metadata; |
| 443 } |
| 444 if (reflectableSupportsTopLevelInvoke( |
| 445 _reflectable, name, declarationMirror.metadata, getterMetadata)) { |
| 446 result[name] = wrapDeclarationMirror(declarationMirror, _reflectable); |
| 447 } |
| 448 } else if (declarationMirror is dm.VariableMirror) { |
| 449 // For variableMirrors we test both for support of the name and the |
| 450 // derived setter name. |
| 451 if (reflectableSupportsTopLevelInvoke( |
| 452 _reflectable, name, declarationMirror.metadata, null) || |
| 453 reflectableSupportsTopLevelInvoke(_reflectable, |
| 454 _getterToSetter(name), declarationMirror.metadata, null)) { |
| 455 result[name] = wrapDeclarationMirror(declarationMirror, _reflectable); |
| 456 } |
| 457 } else { |
| 458 // The additional subtypes of [dm.DeclarationMirror] are |
| 459 // [dm.LibraryMirror]: doees not occur inside another library, |
| 460 // [dm.ParameterMirror]: not declared in a library, [dm.TypeMirror], |
| 461 // and the 4 subtypes thereof; [dm.ClassMirror]: processed here, |
| 462 // [dm.TypedefMirror]: not yet supported, [dm.FunctionTypeMirror]: not |
| 463 // yet supported, and [dm.TypeVariableMirror]: not yet supported. |
| 464 if (declarationMirror is dm.ClassMirror) { |
| 465 if (_reflectable._supportedClasses.contains(declarationMirror)) { |
| 466 result[name] = |
| 467 wrapDeclarationMirror(declarationMirror, _reflectable); |
| 468 } |
| 469 } else { |
| 470 // TODO(eernst) implement: currently ignoring the unsupported cases. |
| 471 } |
| 429 } | 472 } |
| 430 return false; | |
| 431 }); | 473 }); |
| 432 return new Map<String, rm.DeclarationMirror>.fromIterable(relevantKeys, | 474 return result; |
| 433 key: (k) => dm.MirrorSystem.getName(k), | |
| 434 value: (v) => wrapDeclarationMirror(decls[v], _reflectable)); | |
| 435 } | 475 } |
| 436 | 476 |
| 437 @override | 477 @override |
| 438 Object invoke(String memberName, List positionalArguments, | 478 Object invoke(String memberName, List positionalArguments, |
| 439 [Map<Symbol, dynamic> namedArguments]) { | 479 [Map<Symbol, dynamic> namedArguments]) { |
| 440 if (!reflectableSupportsTopLevelInvoke(_reflectable, memberName, | 480 dm.DeclarationMirror declaration = |
| 441 _libraryMirror.declarations[new Symbol(memberName)].metadata)) { | 481 _libraryMirror.declarations[new Symbol(memberName)]; |
| 482 List<dm.InstanceMirror> metadata = declaration.metadata; |
| 483 List<dm.InstanceMirror> getterMetadata = null; |
| 484 if (impliesCorrespondingSetter(_reflectable.capabilities) && |
| 485 declaration is dm.MethodMirror && |
| 486 declaration.isSetter) { |
| 487 dm.MethodMirror correspondingGetter = _libraryMirror.declarations[ |
| 488 new Symbol(_setterNameToGetterName(memberName))]; |
| 489 getterMetadata = correspondingGetter?.metadata; |
| 490 } |
| 491 if (!reflectableSupportsTopLevelInvoke( |
| 492 _reflectable, memberName, metadata, getterMetadata)) { |
| 442 throw new NoSuchInvokeCapabilityError( | 493 throw new NoSuchInvokeCapabilityError( |
| 443 _receiver, memberName, positionalArguments, namedArguments); | 494 _receiver, memberName, positionalArguments, namedArguments); |
| 444 } | 495 } |
| 445 | |
| 446 return _libraryMirror | 496 return _libraryMirror |
| 447 .invoke(new Symbol(memberName), positionalArguments, namedArguments) | 497 .invoke(new Symbol(memberName), positionalArguments, namedArguments) |
| 448 .reflectee; | 498 .reflectee; |
| 449 } | 499 } |
| 450 | 500 |
| 451 @override | 501 @override |
| 452 Object invokeGetter(String getterName) { | 502 Object invokeGetter(String getterName) { |
| 453 if (!reflectableSupportsTopLevelInvoke(_reflectable, getterName, | 503 if (!reflectableSupportsTopLevelInvoke(_reflectable, getterName, |
| 454 _libraryMirror.declarations[new Symbol(getterName)].metadata)) { | 504 _libraryMirror.declarations[new Symbol(getterName)].metadata, null)) { |
| 455 throw new NoSuchInvokeCapabilityError(_receiver, getterName, [], null); | 505 throw new NoSuchInvokeCapabilityError(_receiver, getterName, [], null); |
| 456 } | 506 } |
| 457 Symbol getterNameSymbol = new Symbol(getterName); | 507 Symbol getterNameSymbol = new Symbol(getterName); |
| 458 return _libraryMirror.getField(getterNameSymbol).reflectee; | 508 return _libraryMirror.getField(getterNameSymbol).reflectee; |
| 459 } | 509 } |
| 460 | 510 |
| 461 @override | 511 @override |
| 462 Object invokeSetter(String setterName, Object value) { | 512 Object invokeSetter(String setterName, Object value) { |
| 463 if (!reflectableSupportsTopLevelInvoke(_reflectable, setterName, | 513 dm.DeclarationMirror declaration = |
| 464 _libraryMirror.declarations[new Symbol(setterName)].metadata)) { | 514 _libraryMirror.declarations[new Symbol(setterName)]; |
| 515 List<dm.InstanceMirror> metadata = declaration.metadata; |
| 516 List<dm.InstanceMirror> getterMetadata = null; |
| 517 String getterName = _setterToGetter(setterName); |
| 518 Symbol getterNameSymbol = new Symbol(getterName); |
| 519 if (impliesCorrespondingSetter(_reflectable.capabilities) && |
| 520 declaration is dm.MethodMirror && |
| 521 declaration.isSetter) { |
| 522 dm.MethodMirror correspondingGetter = |
| 523 _libraryMirror.declarations[getterNameSymbol]; |
| 524 getterMetadata = correspondingGetter?.metadata; |
| 525 } |
| 526 if (!reflectableSupportsTopLevelInvoke( |
| 527 _reflectable, setterName, metadata, getterMetadata)) { |
| 465 throw new NoSuchInvokeCapabilityError( | 528 throw new NoSuchInvokeCapabilityError( |
| 466 _receiver, setterName, [value], null); | 529 _receiver, setterName, [value], null); |
| 467 } | 530 } |
| 468 String getterName = _setterToGetter(setterName); | |
| 469 Symbol getterNameSymbol = new Symbol(getterName); | |
| 470 return _libraryMirror.setField(getterNameSymbol, value).reflectee; | 531 return _libraryMirror.setField(getterNameSymbol, value).reflectee; |
| 471 } | 532 } |
| 472 | 533 |
| 473 @override | 534 @override |
| 474 bool operator ==(other) { | 535 bool operator ==(other) { |
| 475 return other is _LibraryMirrorImpl | 536 return other is _LibraryMirrorImpl |
| 476 ? _libraryMirror == other._libraryMirror | 537 ? _libraryMirror == other._libraryMirror |
| 477 : false; | 538 : false; |
| 478 } | 539 } |
| 479 | 540 |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 678 included = included || | 739 included = included || |
| 679 reflectableSupportsConstructorInvoke( | 740 reflectableSupportsConstructorInvoke( |
| 680 _reflectable, _classMirror, name); | 741 _reflectable, _classMirror, name); |
| 681 } else { | 742 } else { |
| 682 // `declarationMirror` is a non-constructor. | 743 // `declarationMirror` is a non-constructor. |
| 683 if (declarationMirror.isStatic) { | 744 if (declarationMirror.isStatic) { |
| 684 // `declarationMirror` is a static method/getter/setter. | 745 // `declarationMirror` is a static method/getter/setter. |
| 685 List<dm.InstanceMirror> getterMetadata = null; | 746 List<dm.InstanceMirror> getterMetadata = null; |
| 686 if (declarationMirror.isSetter && | 747 if (declarationMirror.isSetter && |
| 687 !declarationMirror.isSynthetic && | 748 !declarationMirror.isSynthetic && |
| 688 name.endsWith("=")) { | 749 _isSetterName(name)) { |
| 689 dm.DeclarationMirror correspondingGetter = | 750 dm.DeclarationMirror correspondingGetter = |
| 690 _classMirror.declarations[ | 751 _classMirror.declarations[ |
| 691 new Symbol(name.substring(0, name.length - 1))]; | 752 new Symbol(_setterNameToGetterName(name))]; |
| 692 getterMetadata = correspondingGetter?.metadata; | 753 getterMetadata = correspondingGetter?.metadata; |
| 693 } | 754 } |
| 694 included = included || | 755 included = included || |
| 695 reflectableSupportsStaticInvoke(_reflectable, name, | 756 reflectableSupportsStaticInvoke(_reflectable, name, |
| 696 declarationMirror.metadata, getterMetadata); | 757 declarationMirror.metadata, getterMetadata); |
| 697 } else { | 758 } else { |
| 698 // `declarationMirror` is an instance method/getter/setter. | 759 // `declarationMirror` is an instance method/getter/setter. |
| 699 included = included || | 760 included = included || |
| 700 reflectableSupportsDeclaration( | 761 reflectableSupportsDeclaration( |
| 701 _reflectable, name, _classMirror); | 762 _reflectable, name, _classMirror); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 780 @override | 841 @override |
| 781 Object invoke(String memberName, List positionalArguments, | 842 Object invoke(String memberName, List positionalArguments, |
| 782 [Map<Symbol, dynamic> namedArguments]) { | 843 [Map<Symbol, dynamic> namedArguments]) { |
| 783 dm.DeclarationMirror declaration = | 844 dm.DeclarationMirror declaration = |
| 784 _classMirror.declarations[new Symbol(memberName)]; | 845 _classMirror.declarations[new Symbol(memberName)]; |
| 785 List<Object> metadata = declaration == null ? null : declaration.metadata; | 846 List<Object> metadata = declaration == null ? null : declaration.metadata; |
| 786 List<dm.InstanceMirror> getterMetadata = null; | 847 List<dm.InstanceMirror> getterMetadata = null; |
| 787 if (declaration is dm.MethodMirror && | 848 if (declaration is dm.MethodMirror && |
| 788 declaration.isSetter && | 849 declaration.isSetter && |
| 789 !declaration.isSynthetic && | 850 !declaration.isSynthetic && |
| 790 memberName.endsWith("=")) { | 851 _isSetterName(memberName)) { |
| 791 dm.DeclarationMirror correspondingGetter = _classMirror.declarations[ | 852 dm.DeclarationMirror correspondingGetter = _classMirror.declarations[ |
| 792 memberName.substring(0, memberName.length - 1)]; | 853 new Symbol(_setterNameToGetterName(memberName))]; |
| 793 getterMetadata = correspondingGetter?.metadata; | 854 getterMetadata = correspondingGetter?.metadata; |
| 794 } | 855 } |
| 795 if (reflectableSupportsStaticInvoke( | 856 if (reflectableSupportsStaticInvoke( |
| 796 _reflectable, memberName, metadata, getterMetadata)) { | 857 _reflectable, memberName, metadata, getterMetadata)) { |
| 797 Symbol memberNameSymbol = new Symbol(memberName); | 858 Symbol memberNameSymbol = new Symbol(memberName); |
| 798 return _classMirror | 859 return _classMirror |
| 799 .invoke(memberNameSymbol, positionalArguments, namedArguments) | 860 .invoke(memberNameSymbol, positionalArguments, namedArguments) |
| 800 .reflectee; | 861 .reflectee; |
| 801 } | 862 } |
| 802 throw new NoSuchInvokeCapabilityError( | 863 throw new NoSuchInvokeCapabilityError( |
| 803 _receiver, memberName, positionalArguments, namedArguments); | 864 _receiver, memberName, positionalArguments, namedArguments); |
| 804 } | 865 } |
| 805 | 866 |
| 806 @override | 867 @override |
| 807 Object invokeGetter(String getterName) { | 868 Object invokeGetter(String getterName) { |
| 808 if (reflectableSupportsStaticInvoke(_reflectable, getterName, | 869 if (reflectableSupportsStaticInvoke(_reflectable, getterName, |
| 809 _classMirror.declarations[new Symbol(getterName)]?.metadata, null)) { | 870 _classMirror.declarations[new Symbol(getterName)]?.metadata, null)) { |
| 810 Symbol getterNameSymbol = new Symbol(getterName); | 871 Symbol getterNameSymbol = new Symbol(getterName); |
| 811 return _classMirror.getField(getterNameSymbol).reflectee; | 872 return _classMirror.getField(getterNameSymbol).reflectee; |
| 812 } | 873 } |
| 813 throw new NoSuchInvokeCapabilityError(_receiver, getterName, [], null); | 874 throw new NoSuchInvokeCapabilityError(_receiver, getterName, [], null); |
| 814 } | 875 } |
| 815 | 876 |
| 816 @override | 877 @override |
| 817 Object invokeSetter(String setterName, Object value) { | 878 Object invokeSetter(String setterName, Object value) { |
| 818 List<dm.InstanceMirror> metadata = | 879 List<dm.InstanceMirror> metadata = |
| 819 _classMirror.declarations[new Symbol(setterName)]?.metadata; | 880 _classMirror.declarations[new Symbol(setterName)]?.metadata; |
| 820 List<dm.InstanceMirror> getterMetadata = null; | 881 List<dm.InstanceMirror> getterMetadata = null; |
| 821 if (setterName.endsWith("=")) { | 882 if (_isSetterName(setterName)) { |
| 822 dm.DeclarationMirror correspondingGetter = _classMirror.declarations[ | 883 dm.DeclarationMirror correspondingGetter = _classMirror.declarations[ |
| 823 new Symbol(setterName.substring(0, setterName.length - 1))]; | 884 new Symbol(_setterNameToGetterName(setterName))]; |
| 824 getterMetadata = correspondingGetter?.metadata; | 885 getterMetadata = correspondingGetter?.metadata; |
| 825 } | 886 } |
| 826 if (reflectableSupportsStaticInvoke( | 887 if (reflectableSupportsStaticInvoke( |
| 827 _reflectable, setterName, metadata, getterMetadata)) { | 888 _reflectable, setterName, metadata, getterMetadata)) { |
| 828 String getterName = _setterToGetter(setterName); | 889 String getterName = _setterToGetter(setterName); |
| 829 Symbol getterNameSymbol = new Symbol(getterName); | 890 Symbol getterNameSymbol = new Symbol(getterName); |
| 830 return _classMirror.setField(getterNameSymbol, value).reflectee; | 891 return _classMirror.setField(getterNameSymbol, value).reflectee; |
| 831 } | 892 } |
| 832 throw new NoSuchInvokeCapabilityError(_receiver, setterName, [value], null); | 893 throw new NoSuchInvokeCapabilityError(_receiver, setterName, [value], null); |
| 833 } | 894 } |
| (...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1408 ReflectCapability cap5 = null, | 1469 ReflectCapability cap5 = null, |
| 1409 ReflectCapability cap6 = null, | 1470 ReflectCapability cap6 = null, |
| 1410 ReflectCapability cap7 = null, | 1471 ReflectCapability cap7 = null, |
| 1411 ReflectCapability cap8 = null, | 1472 ReflectCapability cap8 = null, |
| 1412 ReflectCapability cap9 = null]) | 1473 ReflectCapability cap9 = null]) |
| 1413 : super(cap0, cap1, cap2, cap3, cap4, cap5, cap6, cap7, cap8, cap9); | 1474 : super(cap0, cap1, cap2, cap3, cap4, cap5, cap6, cap7, cap8, cap9); |
| 1414 | 1475 |
| 1415 const ReflectableImpl.fromList(List<ReflectCapability> capabilities) | 1476 const ReflectableImpl.fromList(List<ReflectCapability> capabilities) |
| 1416 : super.fromList(capabilities); | 1477 : super.fromList(capabilities); |
| 1417 | 1478 |
| 1418 bool _canReflect(dm.InstanceMirror mirror) => | 1479 bool _canReflect(dm.InstanceMirror mirror) { |
| 1419 _supportedClasses.contains(mirror.type.originalDeclaration); | 1480 dm.ClassMirror classMirror = mirror.type.originalDeclaration; |
| 1481 return !classMirror.isPrivate && _supportedClasses.contains(classMirror); |
| 1482 } |
| 1420 | 1483 |
| 1421 /// Determines whether reflection is supported for the given [o]. | 1484 /// Determines whether reflection is supported for the given [o]. |
| 1422 @override | 1485 @override |
| 1423 bool canReflect(Object o) => _canReflect(dm.reflect(o)); | 1486 bool canReflect(Object o) => _canReflect(dm.reflect(o)); |
| 1424 | 1487 |
| 1425 /// Returns a mirror of the given object [reflectee] | 1488 /// Returns a mirror of the given object [reflectee] |
| 1426 @override | 1489 @override |
| 1427 rm.InstanceMirror reflect(Object o) { | 1490 rm.InstanceMirror reflect(Object o) { |
| 1428 dm.InstanceMirror mirror = dm.reflect(o); | 1491 dm.InstanceMirror mirror = dm.reflect(o); |
| 1429 if (_canReflect(mirror)) return wrapInstanceMirror(mirror, this); | 1492 if (_canReflect(mirror)) return wrapInstanceMirror(mirror, this); |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1777 for (dm.ParameterMirror parameter in declaration.parameters) { | 1840 for (dm.ParameterMirror parameter in declaration.parameters) { |
| 1778 dm.TypeMirror typeMirror = parameter.type.originalDeclaration; | 1841 dm.TypeMirror typeMirror = parameter.type.originalDeclaration; |
| 1779 if (typeMirror is dm.ClassMirror) yield typeMirror; | 1842 if (typeMirror is dm.ClassMirror) yield typeMirror; |
| 1780 } | 1843 } |
| 1781 dm.TypeMirror typeMirror = declaration.returnType; | 1844 dm.TypeMirror typeMirror = declaration.returnType; |
| 1782 if (typeMirror is dm.ClassMirror) yield typeMirror; | 1845 if (typeMirror is dm.ClassMirror) yield typeMirror; |
| 1783 } | 1846 } |
| 1784 } | 1847 } |
| 1785 } | 1848 } |
| 1786 } | 1849 } |
| 1850 |
| 1851 bool _isSetterName(String name) => name.endsWith("="); |
| 1852 |
| 1853 String _setterNameToGetterName(String name) { |
| 1854 assert(_isSetterName(name)); |
| 1855 return name.substring(0, name.length - 1); |
| 1856 } |
| OLD | NEW |