/** * Makes the given visitor visit the JVMS ClassFile structure passed to the constructor of this * {@link ClassReader}. * * @param classVisitor the visitor that must visit this class. * @param parsingOptions the options to use to parse this class. One or more of {@link * #SKIP_CODE}, {@link #SKIP_DEBUG}, {@link #SKIP_FRAMES} or {@link #EXPAND_FRAMES}. */ public void accept(final ClassVisitor classVisitor, final int parsingOptions) { accept(classVisitor, new Attribute[0], parsingOptions); }
/** * Checks for all public super methods that are not overridden. */ protected void processSuperMethods() { for (ClassReader cr : targetClassInfo.superClassReaders) { cr.accept(new EmptyClassVisitor() { String declaredClassName; @Override public void visit(final int version, final int access, final String name, final String signature, final String superName, final String[] interfaces) { declaredClassName = name; } @Override public MethodVisitor visitMethod(final int access, final String name, final String desc, final String signature, final String[] exceptions) { if (name.equals(INIT) || name.equals(CLINIT)) { return null; } MethodSignatureVisitor msign = targetClassInfo.lookupMethodSignatureVisitor(access, name, desc, declaredClassName); if (msign == null) { return null; } return applyProxy(msign); } }, 0); } }
/** * {@inheritDoc} */ @Override protected WorkData process(final ClassReader cr, final TargetClassInfoReader targetClassInfoReader) { InvokeClassBuilder icb = new InvokeClassBuilder( destClassWriter, proxetta.getAspects(new InvokeAspect[0]), resolveClassNameSuffix(), requestedProxyClassName, targetClassInfoReader); cr.accept(icb, 0); return icb.getWorkData(); }
/** * {@inheritDoc} */ @Override protected WorkData process(final ClassReader cr, final TargetClassInfoReader targetClassInfoReader) { ProxettaClassBuilder pcb = new ProxettaClassBuilder( destClassWriter, proxetta.getAspects(new ProxyAspect[0]), resolveClassNameSuffix(), requestedProxyClassName, targetClassInfoReader); cr.accept(pcb, 0); return pcb.getWorkData(); }
compute = hasFrames ? MethodWriter.COMPUTE_INSERTED_FRAMES : MethodWriter.COMPUTE_NOTHING; new ClassReader(classFile, 0, /* checkClassVersion = */ false) .accept( this, attributes,
ClassReader reader = new ClassReader(stream); MethodFinder visitor = new MethodFinder(declaringClass, name, paramTypes); reader.accept(visitor, 0); return visitor.getResolvedParameters();
/** * {@inheritDoc} */ @Override protected WorkData process(final ClassReader cr, final TargetClassInfoReader targetClassInfoReader) { final ProxettaWrapperClassBuilder pcb = new ProxettaWrapperClassBuilder( targetClassOrInterface, targetInterface, targetFieldName, destClassWriter, proxetta.getAspects(new ProxyAspect[0]), resolveClassNameSuffix(), requestedProxyClassName, targetClassInfoReader, createTargetInDefaultCtor ); cr.accept(pcb, 0); return pcb.getWorkData(); }
private MethodInfo getMethodSignatureForSingleMethod(Class klass) throws IOException { InputStream in = ClassLoaderUtil.getClassAsStream(klass.getName()); ClassReader classReader = new ClassReader(in); TargetClassInfoReaderFixture targetClassInfoReader = new TargetClassInfoReaderFixture(this.getClass().getClassLoader()); classReader.accept(targetClassInfoReader, 0); in.close(); Map<String, MethodSignatureVisitor> methodSignatures = targetClassInfoReader.getMethodSignatures(); return methodSignatures.values() .stream() .filter(msv -> { if (msv.getMethodName().equals("<init>")) { return false; } if (msv.getDeclaredClassName().startsWith(CLASS_SIGNATURE)) { return true; } return false; }) .findFirst().get(); } }
adviceClassReader.accept(new EmptyClassVisitor() {
/** * Reads the target and creates destination class. */ protected void process() { if (targetInputStream == null) { throw new ProxettaException("Target missing: " + targetClassName); } // create class reader final ClassReader classReader; try { classReader = new ClassReader(targetInputStream); } catch (IOException ioex) { throw new ProxettaException("Error reading class input stream", ioex); } // reads information final TargetClassInfoReader targetClassInfoReader = new TargetClassInfoReader(proxetta.getClassLoader()); classReader.accept(targetClassInfoReader, 0); this.destClassWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES); // create proxy if (log.isDebugEnabled()) { log.debug("processing: " + classReader.getClassName()); } WorkData wd = process(classReader, targetClassInfoReader); // store important data proxyApplied = wd.proxyApplied; proxyClassName = wd.thisReference.replace('/', '.'); }
aspectData.getAdviceClassReader().accept(new EmptyClassVisitor() {
/** * Makes the given visitor visit the JVMS ClassFile structure passed to the constructor of this * {@link ClassReader}. * * @param classVisitor the visitor that must visit this class. * @param parsingOptions the options to use to parse this class. One or more of {@link * #SKIP_CODE}, {@link #SKIP_DEBUG}, {@link #SKIP_FRAMES} or {@link #EXPAND_FRAMES}. */ public void accept(final ClassVisitor classVisitor, final int parsingOptions) { accept(classVisitor, new Attribute[0], parsingOptions); }
/** * Checks for all public super methods that are not overridden. */ protected void processSuperMethods() { for (ClassReader cr : targetClassInfo.superClassReaders) { cr.accept(new EmptyClassVisitor() { String declaredClassName; @Override public void visit(final int version, final int access, final String name, final String signature, final String superName, final String[] interfaces) { declaredClassName = name; } @Override public MethodVisitor visitMethod(final int access, final String name, final String desc, final String signature, final String[] exceptions) { if (name.equals(INIT) || name.equals(CLINIT)) { return null; } MethodSignatureVisitor msign = targetClassInfo.lookupMethodSignatureVisitor(access, name, desc, declaredClassName); if (msign == null) { return null; } return applyProxy(msign); } }, 0); } }
/** * {@inheritDoc} */ @Override protected WorkData process(final ClassReader cr, final TargetClassInfoReader targetClassInfoReader) { ProxettaClassBuilder pcb = new ProxettaClassBuilder( destClassWriter, proxetta.getAspects(new ProxyAspect[0]), resolveClassNameSuffix(), requestedProxyClassName, targetClassInfoReader); cr.accept(pcb, 0); return pcb.getWorkData(); }
/** * {@inheritDoc} */ @Override protected WorkData process(final ClassReader cr, final TargetClassInfoReader targetClassInfoReader) { InvokeClassBuilder icb = new InvokeClassBuilder( destClassWriter, proxetta.getAspects(new InvokeAspect[0]), resolveClassNameSuffix(), requestedProxyClassName, targetClassInfoReader); cr.accept(icb, 0); return icb.getWorkData(); }
ClassReader reader = new ClassReader(stream); MethodFinder visitor = new MethodFinder(declaringClass, name, paramTypes); reader.accept(visitor, 0); return visitor.getResolvedParameters();
compute = hasFrames ? MethodWriter.COMPUTE_INSERTED_FRAMES : MethodWriter.COMPUTE_NOTHING; new ClassReader(classFile, 0, /* checkClassVersion = */ false) .accept( this, attributes,
/** * {@inheritDoc} */ @Override protected WorkData process(final ClassReader cr, final TargetClassInfoReader targetClassInfoReader) { final ProxettaWrapperClassBuilder pcb = new ProxettaWrapperClassBuilder( targetClassOrInterface, targetInterface, targetFieldName, destClassWriter, proxetta.getAspects(new ProxyAspect[0]), resolveClassNameSuffix(), requestedProxyClassName, targetClassInfoReader, createTargetInDefaultCtor ); cr.accept(pcb, 0); return pcb.getWorkData(); }
/** * Reads the target and creates destination class. */ protected void process() { if (targetInputStream == null) { throw new ProxettaException("Target missing: " + targetClassName); } // create class reader final ClassReader classReader; try { classReader = new ClassReader(targetInputStream); } catch (IOException ioex) { throw new ProxettaException("Error reading class input stream", ioex); } // reads information final TargetClassInfoReader targetClassInfoReader = new TargetClassInfoReader(proxetta.getClassLoader()); classReader.accept(targetClassInfoReader, 0); this.destClassWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES); // create proxy if (log.isDebugEnabled()) { log.debug("processing: " + classReader.getClassName()); } WorkData wd = process(classReader, targetClassInfoReader); // store important data proxyApplied = wd.proxyApplied; proxyClassName = wd.thisReference.replace('/', '.'); }