/** * pushes an array of the specified size to the method visitor. The generated bytecode will leave * the new array at the top of the stack. * * @param mv MethodVisitor to use * @param size Size of the array to create * @param type Type of array to create * @throws ProxyGenerationException */ private void createArrayDefinition(MethodVisitor mv, int size, Class<?> type) throws ProxyGenerationException { // create a new array of java.lang.class (2) if (size < 0) { throw new ProxyGenerationException("Array size cannot be less than zero"); } pushIntOntoStack(mv, size); mv.visitTypeInsn(ANEWARRAY, type.getCanonicalName().replaceAll("\\.", "/")); }
private Class createProxy(Class<?> clsToProxy, String proxyName, ClassLoader cl) { String clsName = proxyName.replaceAll("\\.", "/"); try { return cl.loadClass(proxyName); } catch (Exception e) { } try { byte[] proxyBytes = generateProxy(clsToProxy, clsName); return (Class<?>) unsafe.defineClass(proxyName, proxyBytes, 0, proxyBytes.length, cl, this.getClass().getProtectionDomain()); } catch (ProxyGenerationException e) { throw new InternalError(e.toString()); } }
/** * pushes an array of the specified size to the method visitor. The generated bytecode will leave * the new array at the top of the stack. * * @param mv MethodVisitor to use * @param size Size of the array to create * @param type Type of array to create * @throws ProxyGenerationException */ private static void createArrayDefinition(final MethodVisitor mv, final int size, final Class<?> type) throws ProxyGenerationException { // create a new array of java.lang.class (2) if (size < 0) { throw new ProxyGenerationException("Array size cannot be less than zero"); } pushIntOntoStack(mv, size); mv.visitTypeInsn(ANEWARRAY, type.getCanonicalName().replace('.', '/')); }
/** * pushes an array of the specified size to the method visitor. The generated bytecode will leave * the new array at the top of the stack. * * @param mv MethodVisitor to use * @param size Size of the array to create * @param type Type of array to create * @throws ProxyGenerationException */ private static void createArrayDefinition(final MethodVisitor mv, final int size, final Class<?> type) throws ProxyGenerationException { // create a new array of java.lang.class (2) if (size < 0) { throw new ProxyGenerationException("Array size cannot be less than zero"); } pushIntOntoStack(mv, size); mv.visitTypeInsn(ANEWARRAY, type.getCanonicalName().replace('.', '/')); }
private static void copyMethodAnnotations(final Class<?> classToProxy, final Map<String, MethodVisitor> visitors) throws ProxyGenerationException { // Move all the annotations onto the newly implemented methods // Ensures CDI and JAX-RS and JAX-WS still work Class clazz = classToProxy; while (clazz != null && !clazz.equals(Object.class)) { try { final ClassReader classReader = new ClassReader(readClassFile(clazz)); final ClassVisitor copyMethodAnnotations = new CopyMethodAnnotations(visitors); classReader.accept(copyMethodAnnotations, ClassReader.SKIP_CODE); } catch (final IOException e) { throw new ProxyGenerationException(e); } clazz = clazz.getSuperclass(); } }
private static void copyMethodAnnotations(final Class<?> classToProxy, final Map<String, MethodVisitor> visitors) throws ProxyGenerationException { // Move all the annotations onto the newly implemented methods // Ensures CDI and JAX-RS and JAX-WS still work Class clazz = classToProxy; while (clazz != null && !clazz.equals(Object.class)) { try { final ClassReader classReader = new ClassReader(readClassFile(clazz)); final ClassVisitor copyMethodAnnotations = new CopyMethodAnnotations(visitors); classReader.accept(copyMethodAnnotations, ClassReader.SKIP_CODE); } catch (final IOException e) { throw new ProxyGenerationException(e); } clazz = clazz.getSuperclass(); } }
private static void copyClassAnnotations(final Class<?> clazz, final ClassVisitor newClass) throws ProxyGenerationException { try { final ClassReader classReader = new ClassReader(readClassFile(clazz)); final ClassVisitor visitor = new CopyClassAnnotations(newClass); classReader.accept(visitor, ClassReader.SKIP_CODE); } catch (final IOException e) { throw new ProxyGenerationException(e); } }
private static void copyClassAnnotations(final Class<?> clazz, final ClassVisitor newClass) throws ProxyGenerationException { try { final ClassReader classReader = new ClassReader(readClassFile(clazz)); final ClassVisitor visitor = new CopyClassAnnotations(newClass); classReader.accept(visitor, ClassReader.SKIP_CODE); } catch (final IOException e) { throw new ProxyGenerationException(e); } }