Closed kevin-wang001 closed 6 years ago
Could you support private members access right? Then, this framework will be more popular, and it's will be wilder used!
Using asm generates access code like : public class XXXMethodAccess extends MethodAccess { public Object invoke(Object paramObject, int methodIndex, Object[] paramArrayOfObject) { XXX xxx = (XXX) paramObject; try { switch (methodIndex) { case 0: xxx.method0((String[]) paramArrayOfObject[0]); return null; case 1: return xxx.method1((String) paramArrayOfObject[0]); } } catch (java.lang.IllegalAccessError e) { Method method = methods.get(methodIndex); method.setAccessible(true); try { return method.invoke(object, args); } catch (Exception e) { throw new IllegalStateException("invoke method error:" + method.getName(), e); } } throw new IllegalArgumentException("Method not found: " + methodNames[paramInt]); } }
You can write your own fallback if ReflectASM isn't able to access a field. Note your code above won't work in later versions of Java where setAccessible is not allowed.
setAccessible
Could you support private members access right? Then, this framework will be more popular, and it's will be wilder used!
Using asm generates access code like : public class XXXMethodAccess extends MethodAccess { public Object invoke(Object paramObject, int methodIndex, Object[] paramArrayOfObject) { XXX xxx = (XXX) paramObject; try { switch (methodIndex) { case 0: xxx.method0((String[]) paramArrayOfObject[0]); return null; case 1: return xxx.method1((String) paramArrayOfObject[0]); } } catch (java.lang.IllegalAccessError e) { Method method = methods.get(methodIndex); method.setAccessible(true); try { return method.invoke(object, args); } catch (Exception e) { throw new IllegalStateException("invoke method error:" + method.getName(), e); } } throw new IllegalArgumentException("Method not found: " + methodNames[paramInt]); } }