Replace reflective access of role-specific behavior / structure with MethodHandles
Replace all reflective access of role-specific behavior / structure in ReflectiveHelper.scala with MethodHandels.
Hence, we should do:
-
[ ] replace caches using
java.lang.reflect.{Field, Method}with ones storingMethodHandles -
[ ] use
MethodHandle findVirtual(Class<?> refc, String name, MethodType type),MethodHandle findGetter(Class<?> refc, String name, Class<?> type), andMethodHandle findSetter(Class<?> refc, String name, Class<?> type)instead ofgetDeclaredMethods,getDeclaredFields,getAccessibleMethods, andgetAccessibleFields -
[ ] remove unnecessary code, e.g.,
def matchMethod[A](m: Method, name: String, args: Seq[A]): Booleanordef hasMember(on: AnyRef, name: String): Booleansince this could be handled by theMethodHandlesAPI directly. -
[ ] finally, call role-specific functionally with
MethodHandle.invoke(Object... args)
use MethodHandle findVirtual(Class> refc, String name, MethodType type), MethodHandle findGetter(Class> refc, String name, Class> type), and MethodHandle findSetter(Class> refc, String name, Class<?> type) instead of getDeclaredMethods, getDeclaredFields, getAccessibleMethods, and getAccessibleFields
If someone is going to do this replacement, I wanted to note that findGetter() and findSetter() are most probably the wrong methods in the case of Scala. As I understand it, scalac creates accessor methods based on the property name (<propname>() getter and <propname>_$eq() setter) and one should use Lookup.findVirtual() to find these accessor methods.
Good hint. Thanks!