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(); }
void write() { // write our field to hold target field reference (but just once)... if (fieldRefs.add(targetFieldName)) { visitField(ACC_PRIVATE | ACC_STATIC, fieldRefName, FIELD_TYPE.getDescriptor(), null, null); } visitCode(); if (isSetter) { // pseudocode: // field_x.set(this, arg0); loadFieldRef(); loadTarget(); loadArg(0); Class<?> parameterType = iMethod.getParameterTypes()[0]; if (parameterType.isPrimitive()) { box(Type.getType(parameterType)); } invokeVirtual(FIELD_TYPE, FIELD$SET); returnValue(); } else { // getter // pseudocode: // return field_x.get(this); loadFieldRef(); loadTarget(); invokeVirtual(FIELD_TYPE, FIELD$GET); castForReturn(iMethod.getReturnType()); returnValue(); } endMethod(); }
private void loadFieldRef() { // pseudocode: // if (field$x == null) { // field$x = targetClass.getDeclaredField(name); // field$x.setAccessible(true); // } // -> field reference on stack getStatic(reflectorType, fieldRefName, FIELD_TYPE); dup(); Label haveMethodRef = newLabel(); ifNonNull(haveMethodRef); pop(); // pseudocode: // targetClass.getDeclaredField(name); push(targetType); push(targetFieldName); invokeVirtual(CLASS_TYPE, CLASS$GET_DECLARED_FIELD); // pseudocode: // <field>.setAccessible(true); dup(); push(true); invokeVirtual(FIELD_TYPE, ACCESSIBLE_OBJECT$SET_ACCESSIBLE); // pseudocode: // field$x = method; dup(); putStatic(reflectorType, fieldRefName, FIELD_TYPE); mark(haveMethodRef); } }
void write() { // write our field to hold target field reference (but just once)... if (fieldRefs.add(targetFieldName)) { visitField(ACC_PRIVATE | ACC_STATIC, fieldRefName, FIELD_TYPE.getDescriptor(), null, null); } visitCode(); if (isSetter) { // pseudocode: // field_x.set(this, arg0); loadFieldRef(); loadTarget(); loadArg(0); Class<?> parameterType = iMethod.getParameterTypes()[0]; if (parameterType.isPrimitive()) { box(Type.getType(parameterType)); } invokeVirtual(FIELD_TYPE, FIELD$SET); returnValue(); } else { // getter // pseudocode: // return field_x.get(this); loadFieldRef(); loadTarget(); invokeVirtual(FIELD_TYPE, FIELD$GET); castForReturn(iMethod.getReturnType()); returnValue(); } 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 void loadFieldRef() { // pseudocode: // if (field$x == null) { // field$x = targetClass.getDeclaredField(name); // field$x.setAccessible(true); // } // -> field reference on stack getStatic(reflectorType, fieldRefName, FIELD_TYPE); dup(); Label haveMethodRef = newLabel(); ifNonNull(haveMethodRef); pop(); // pseudocode: // targetClass.getDeclaredField(name); push(targetType); push(targetFieldName); invokeVirtual(CLASS_TYPE, CLASS$GET_DECLARED_FIELD); // pseudocode: // <field>.setAccessible(true); dup(); push(true); invokeVirtual(FIELD_TYPE, ACCESSIBLE_OBJECT$SET_ACCESSIBLE); // pseudocode: // field$x = method; dup(); putStatic(reflectorType, fieldRefName, FIELD_TYPE); mark(haveMethodRef); } }