/** * An order-sensitive invocation of {@link ClassVisitor#visitMethod(int, String, String, String, String[])}. * * @param modifiers The method's modifiers. * @param internalName The method's internal name. * @param descriptor The field type's descriptor. * @param signature The method's generic signature or {@code null} if the method is not generic. * @param exception The method's declared exceptions or {@code null} if no exceptions are declared. * @return A method visitor to visit the method or {@code null} to ignore it. */ protected MethodVisitor onVisitMethod(int modifiers, String internalName, String descriptor, String signature, String[] exception) { return super.visitMethod(modifiers, internalName, descriptor, signature, exception); }
/** * Visits the header of the class. * * @param version the class version. The minor version is stored in the 16 most significant bits, * and the major version in the 16 least significant bits. * @param access the class's access flags (see {@link Opcodes}). This parameter also indicates if * the class is deprecated. * @param name the internal name of the class (see {@link Type#getInternalName()}). * @param signature the signature of this class. May be {@literal null} if the class is not a * generic one, and does not extend or implement generic classes or interfaces. * @param superName the internal of name of the super class (see {@link Type#getInternalName()}). * For interfaces, the super class is {@link Object}. May be {@literal null}, but only for the * {@link Object} class. * @param interfaces the internal names of the class's interfaces (see {@link * Type#getInternalName()}). May be {@literal null}. */ public void visit( final int version, final int access, final String name, final String signature, final String superName, final String[] interfaces) { if (cv != null) { cv.visit(version, access, name, signature, superName, interfaces); } }
/** * An order-sensitive invocation of {@link ClassVisitor#visitAnnotation(String, boolean)}. * * @param descriptor The annotation type's descriptor. * @param visible {@code true} if the annotation is visible at runtime. * @return An annotation visitor or {@code null} if the annotation should be ignored. */ protected AnnotationVisitor onVisitAnnotation(String descriptor, boolean visible) { return super.visitAnnotation(descriptor, visible); }
classVisitor.visit( readInt(cpInfoOffsets[1] - 7), accessFlags, thisClass, signature, superClass, interfaces); classVisitor.visitSource(sourceFile, sourceDebugExtension); classVisitor.visitNestHost(nestHostClass); String name = methodIndex == 0 ? null : readUTF8(cpInfoOffsets[methodIndex], charBuffer); String type = methodIndex == 0 ? null : readUTF8(cpInfoOffsets[methodIndex] + 2, charBuffer); classVisitor.visitOuterClass(className, name, type); classVisitor.visitAnnotation(annotationDescriptor, /* visible = */ true), currentAnnotationOffset, /* named = */ true, classVisitor.visitAnnotation(annotationDescriptor, /* visible = */ false), currentAnnotationOffset, /* named = */ true, classVisitor.visitTypeAnnotation( context.currentTypeAnnotationTarget, context.currentTypeAnnotationTargetPath, classVisitor.visitTypeAnnotation( context.currentTypeAnnotationTarget, context.currentTypeAnnotationTargetPath, classVisitor.visitAttribute(attributes); attributes = nextAttribute;
writerFlags, asmVisitorWrapper.mergeReader(AsmVisitorWrapper.NO_FLAGS)); classVisitor.visit(classFileVersion.getMinorMajorVersion(), instrumentedType.getActualModifiers(!instrumentedType.isInterface()), instrumentedType.getInternalName(), instrumentedType.getInterfaces().asErasures().toInternalNames()); if (!instrumentedType.isNestHost()) { classVisitor.visitNestHost(instrumentedType.getNestHost().getInternalName()); classVisitor.visitOuterClass(enclosingMethod.getDeclaringType().getInternalName(), enclosingMethod.getInternalName(), enclosingMethod.getDescriptor()); } else if (instrumentedType.isLocalType() || instrumentedType.isAnonymousType()) { classVisitor.visitOuterClass(instrumentedType.getEnclosingType().getInternalName(), NO_REFERENCE, NO_REFERENCE); if (instrumentedType.isNestHost()) { for (TypeDescription typeDescription : instrumentedType.getNestMembers().filter(not(is(instrumentedType)))) { classVisitor.visitNestMember(typeDescription.getInternalName()); classVisitor.visitInnerClass(instrumentedType.getInternalName(), declaringType.getInternalName(), instrumentedType.getSimpleName(), instrumentedType.getModifiers()); } else if (instrumentedType.isLocalType()) { classVisitor.visitInnerClass(instrumentedType.getInternalName(), NO_REFERENCE, instrumentedType.getSimpleName(), instrumentedType.getModifiers());
/** * An order-sensitive invocation of {@link ClassVisitor#visitInnerClass(String, String, String, int)}. * * @param name The internal name of the inner class. * @param outerName The internal name of the outer class. * @param innerName The inner class's simple name or {@code null} for an anonymous class. * @param modifiers The inner class's source code modifiers. */ protected void onVisitInnerClass(String name, String outerName, String innerName, int modifiers) { super.visitInnerClass(name, outerName, innerName, modifiers); }
if (!filter.matches(typeDescription)) { while (typeDescription != null && typeDescription.isNestedClass()) { super.visitInnerClass(typeDescription.getInternalName(), typeDescription.isMemberType() ? typeDescription.getDeclaringType().getInternalName() super.visitEnd();
/** * An order-sensitive invocation of {@link ClassVisitor#visitAttribute(Attribute)}. * * @param attribute The attribute to visit. */ protected void onVisitAttribute(Attribute attribute) { super.visitAttribute(attribute); }
/** * Visits the end of the class. This method, which is the last one to be called, is used to inform * the visitor that all the fields and methods of the class have been visited. */ public void visitEnd() { if (cv != null) { cv.visitEnd(); } } }
/** * Visits information about an inner class. This inner class is not necessarily a member of the * class being visited. * * @param name the internal name of an inner class (see {@link Type#getInternalName()}). * @param outerName the internal name of the class to which the inner class belongs (see {@link * Type#getInternalName()}). May be {@literal null} for not member classes. * @param innerName the (simple) name of the inner class inside its enclosing class. May be * {@literal null} for anonymous inner classes. * @param access the access flags of the inner class as originally declared in the enclosing * class. */ public void visitInnerClass( final String name, final String outerName, final String innerName, final int access) { if (cv != null) { cv.visitInnerClass(name, outerName, innerName, access); } }
/** * Visits a non standard attribute of the class. * * @param attribute an attribute. */ public void visitAttribute(final Attribute attribute) { if (cv != null) { cv.visitAttribute(attribute); } }
/** * An order-sensitive invocation of {@link ClassVisitor#visitEnd()}. */ protected void onVisitEnd() { super.visitEnd(); } }
/** * Visits a method of the class. This method <i>must</i> return a new {@link MethodVisitor} * instance (or {@literal null}) each time it is called, i.e., it should not return a previously * returned visitor. * * @param access the method's access flags (see {@link Opcodes}). This parameter also indicates if * the method is synthetic and/or deprecated. * @param name the method's name. * @param descriptor the method's descriptor (see {@link Type}). * @param signature the method's signature. May be {@literal null} if the method parameters, * return type and exceptions do not use generic types. * @param exceptions the internal names of the method's exception classes (see {@link * Type#getInternalName()}). May be {@literal null}. * @return an object to visit the byte code of the method, or {@literal null} if this class * visitor is not interested in visiting the code of this method. */ public MethodVisitor visitMethod( final int access, final String name, final String descriptor, final String signature, final String[] exceptions) { if (cv != null) { return cv.visitMethod(access, name, descriptor, signature, exceptions); } return null; }
@Override public void visit(int version, int modifiers, String internalName, String genericSignature, String superClassInternalName, String[] interfaceInternalName) { if (superClassInternalName != null) { observedTypes.add(superClassInternalName); } if (interfaceInternalName != null) { observedTypes.addAll(Arrays.asList(interfaceInternalName)); } super.visit(version, modifiers, internalName, genericSignature, superClassInternalName, interfaceInternalName); }
/** * {@inheritDoc} */ public AnnotationVisitor visit(String annotationTypeDescriptor, boolean visible) { return classVisitor.visitAnnotation(annotationTypeDescriptor, visible); }
@Override public void visitInnerClass(String internalName, String outerName, String innerName, int modifiers) { visitedInnerTypes.add(internalName); super.visitInnerClass(internalName, outerName, innerName, modifiers); }
@Override public MethodVisitor visitMethod(int modifiers, String internalName, String descriptor, String signature, String[] exception) { MethodDescription methodDescription = methods.get(internalName + descriptor); return methodDescription != null && methodMatcher.matches(methodDescription) ? REMOVE_METHOD : super.visitMethod(modifiers, internalName, descriptor, signature, exception); } }
@Override public void visit(int version, int modifiers, String name, String signature, String superClassName, String[] interfaceName) { supportsTypeConstants = ClassFileVersion.ofMinorMajor(version).isAtLeast(ClassFileVersion.JAVA_V5); super.visit(version, modifiers, name, signature, superClassName, interfaceName); }
/** * Visits an annotation of the class. * * @param descriptor the class descriptor of the annotation class. * @param visible {@literal true} if the annotation is visible at runtime. * @return a visitor to visit the annotation values, or {@literal null} if this visitor is not * interested in visiting this annotation. */ public AnnotationVisitor visitAnnotation(final String descriptor, final boolean visible) { if (cv != null) { return cv.visitAnnotation(descriptor, visible); } return null; }
@Override public void visitInnerClass(String internalName, String outerName, String innerName, int modifiers) { if (instrumentedType.getInternalName().equals(internalName)) { for (Adjustment<TypeDescription> adjustment : typeAdjustments) { if (adjustment.matches(instrumentedType)) { modifiers = adjustment.resolve(modifiers); break; } } } super.visitInnerClass(internalName, outerName, innerName, modifiers); }