void write() { int accessModifiers = iClass.getModifiers() & (Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE); visit( V1_5, accessModifiers | ACC_SUPER | ACC_FINAL, reflectorType.getInternalName(), null, OBJECT_TYPE.getInternalName(), new String[] {iType.getInternalName()}); writeTargetField(); writeConstructor(); for (Method method : iClass.getMethods()) { if (method.isDefault()) continue; Accessor accessor = method.getAnnotation(Accessor.class); if (accessor != null) { new AccessorMethodWriter(method, accessor).write(); } else { new ReflectorMethodWriter(method).write(); } } visitEnd(); }
private Type[] resolveParamTypes(Method iMethod) { Class<?>[] iParamTypes = iMethod.getParameterTypes(); Annotation[][] paramAnnotations = iMethod.getParameterAnnotations(); Type[] targetParamTypes = new Type[iParamTypes.length]; for (int i = 0; i < iParamTypes.length; i++) { Class<?> paramType = findWithType(paramAnnotations[i]); if (paramType == null) { paramType = iParamTypes[i]; } targetParamTypes[i] = Type.getType(paramType); } return targetParamTypes; }
getStatic(reflectorType, methodRefName, METHOD_TYPE); dup(); Label haveMethodRef = newLabel(); ifNonNull(haveMethodRef); pop(); push(targetType); push(iMethod.getName()); Type[] paramTypes = targetParamTypes; push(paramTypes.length); newArray(CLASS_TYPE); for (int i = 0; i < paramTypes.length; i++) { dup(); push(i); push(paramTypes[i]); arrayStore(CLASS_TYPE); invokeVirtual(CLASS_TYPE, CLASS$GET_DECLARED_METHOD); dup(); push(true); invokeVirtual(METHOD_TYPE, ACCESSIBLE_OBJECT$SET_ACCESSIBLE); dup(); putStatic(reflectorType, methodRefName, METHOD_TYPE); mark(haveMethodRef);
void write() { // write field to hold method reference... visitField(ACC_PRIVATE | ACC_STATIC, methodRefName, METHOD_TYPE.getDescriptor(), null, null); visitCode(); // pseudocode: // try { // return methodN.invoke(this, *args); // } catch (InvocationTargetException e) { // throw e.getCause(); // } TryCatch tryCatch = tryStart(INVOCATION_TARGET_EXCEPTION_TYPE); loadOriginalMethodRef(); loadTarget(); loadArgArray(); invokeVirtual(METHOD_TYPE, METHOD$INVOKE); tryCatch.end(); castForReturn(iMethod.getReturnType()); returnValue(); tryCatch.handler(); int exceptionLocalVar = newLocal(THROWABLE_TYPE); storeLocal(exceptionLocalVar); loadLocal(exceptionLocalVar); invokeVirtual(THROWABLE_TYPE, THROWABLE$GET_CAUSE); throwException(); endMethod(); }
void write() { int accessModifiers = iClass.getModifiers() & (Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE); visit( V1_5, accessModifiers | ACC_SUPER | ACC_FINAL, reflectorType.getInternalName(), null, OBJECT_TYPE.getInternalName(), new String[] {iType.getInternalName()}); writeTargetField(); writeConstructor(); for (Method method : iClass.getMethods()) { if (method.isDefault()) continue; Accessor accessor = method.getAnnotation(Accessor.class); if (accessor != null) { new AccessorMethodWriter(method, accessor).write(); } else { new ReflectorMethodWriter(method).write(); } } visitEnd(); }
private Type[] resolveParamTypes(Method iMethod) { Class<?>[] iParamTypes = iMethod.getParameterTypes(); Annotation[][] paramAnnotations = iMethod.getParameterAnnotations(); Type[] targetParamTypes = new Type[iParamTypes.length]; for (int i = 0; i < iParamTypes.length; i++) { Class<?> paramType = findWithType(paramAnnotations[i]); if (paramType == null) { paramType = iParamTypes[i]; } targetParamTypes[i] = Type.getType(paramType); } return targetParamTypes; }
getStatic(reflectorType, methodRefName, METHOD_TYPE); dup(); Label haveMethodRef = newLabel(); ifNonNull(haveMethodRef); pop(); push(targetType); push(iMethod.getName()); Type[] paramTypes = targetParamTypes; push(paramTypes.length); newArray(CLASS_TYPE); for (int i = 0; i < paramTypes.length; i++) { dup(); push(i); push(paramTypes[i]); arrayStore(CLASS_TYPE); invokeVirtual(CLASS_TYPE, CLASS$GET_DECLARED_METHOD); dup(); push(true); invokeVirtual(METHOD_TYPE, ACCESSIBLE_OBJECT$SET_ACCESSIBLE); dup(); putStatic(reflectorType, methodRefName, METHOD_TYPE); mark(haveMethodRef);
void write() { // write field to hold method reference... visitField(ACC_PRIVATE | ACC_STATIC, methodRefName, METHOD_TYPE.getDescriptor(), null, null); visitCode(); // pseudocode: // try { // return methodN.invoke(this, *args); // } catch (InvocationTargetException e) { // throw e.getCause(); // } TryCatch tryCatch = tryStart(INVOCATION_TARGET_EXCEPTION_TYPE); loadOriginalMethodRef(); loadTarget(); loadArgArray(); invokeVirtual(METHOD_TYPE, METHOD$INVOKE); tryCatch.end(); castForReturn(iMethod.getReturnType()); returnValue(); tryCatch.handler(); int exceptionLocalVar = newLocal(THROWABLE_TYPE); storeLocal(exceptionLocalVar); loadLocal(exceptionLocalVar); invokeVirtual(THROWABLE_TYPE, THROWABLE$GET_CAUSE); throwException(); endMethod(); }