/** * 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); }
/** * {@inheritDoc} */ public void apply() { classReader.accept(this, ClassReader.SKIP_DEBUG | stackMapFrameHandler.getReaderHint()); }
/** * {@inheritDoc} */ public void prepare() { classReader.accept(new ExceptionTableExtractor(), ClassReader.SKIP_FRAMES | ClassReader.SKIP_DEBUG); suppressionHandler.onPrepare(methodVisitor); }
/** * Parses a binary representation and transforms it into a type description. * * @param binaryRepresentation The binary data to be parsed. * @return A type description of the binary data. */ private TypeDescription parse(byte[] binaryRepresentation) { ClassReader classReader = OpenedClassReader.of(binaryRepresentation); TypeExtractor typeExtractor = new TypeExtractor(); classReader.accept(typeExtractor, readerMode.getFlags()); return typeExtractor.toTypeDescription(); }
compute = hasFrames ? MethodWriter.COMPUTE_INSERTED_FRAMES : MethodWriter.COMPUTE_NOTHING; new ClassReader(classFile, 0, /* checkClassVersion = */ false) .accept( this, attributes,
/** * Extracts a class' class version. * * @param typeDescription The type for which to locate a class file version. * @param classFileLocator The class file locator to query for a class file. * @return The type's class file version. * @throws IOException If an error occurs while reading the class file. */ public static ClassFileVersion of(TypeDescription typeDescription, ClassFileLocator classFileLocator) throws IOException { ClassReader classReader = OpenedClassReader.of(classFileLocator.locate(typeDescription.getName()).resolve()); VersionExtractor versionExtractor = new VersionExtractor(); classReader.accept(versionExtractor, ClassReader.SKIP_CODE); return ClassFileVersion.ofMinorMajor(versionExtractor.getClassFileVersionNumber()); }
@Override protected UnresolvedType create(TypeInitializer typeInitializer) { try { int writerFlags = asmVisitorWrapper.mergeWriter(AsmVisitorWrapper.NO_FLAGS); int readerFlags = asmVisitorWrapper.mergeReader(AsmVisitorWrapper.NO_FLAGS); byte[] binaryRepresentation = classFileLocator.locate(originalType.getName()).resolve(); ClassDumpAction.dump(DUMP_FOLDER, instrumentedType, true, binaryRepresentation); ClassReader classReader = OpenedClassReader.of(binaryRepresentation); ClassWriter classWriter = classWriterStrategy.resolve(writerFlags, typePool, classReader); ContextRegistry contextRegistry = new ContextRegistry(); classReader.accept(writeTo(ValidatingClassVisitor.of(classWriter, typeValidation), typeInitializer, contextRegistry, writerFlags, readerFlags), readerFlags); return new UnresolvedType(classWriter.toByteArray(), contextRegistry.getAuxiliaryTypes()); } catch (IOException exception) { throw new RuntimeException("The class file could not be written", exception); } }
ClassReader classReader = new ClassReader(binaryRepresentation); HookMetadataBuilder hookMetadata = new HookMetadataBuilder(className); classReader.accept(new ClassVisitor(Opcodes.ASM5) { @Override public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException { if (loader == null || shouldIgnore(className)) { return null; } final ClassReader reader = new ClassReader(classfileBuffer); final ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS); reader.accept(new PowerMockClassVisitor(writer), ClassReader.SKIP_FRAMES); return writer.toByteArray(); }