In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "what is ClassVisitor". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is ClassVisitor".
Brief introduction
ClassVisitor is used to generate asm and change bytecode. ClassVisitor is a framework for accessing bytecode. The creation and modification of bytecode is mainly represented by its internal ClassVisitor implementation.
ClassVisitor accesses a java class in a certain order, in the following order:
Visit [visitSource] [visitModule] [visitNestHost] [visitOuterClass] (visitAnnotation | visitTypeAnnotation | visitAttribute) *
(visitNestMember | visitInnerClass | visitField | visitMethod) * visitEnd
Note: visit,visitEnd must be called once. [] means at most one call.
() * indicates that the access in () can be called multiple times in order.
Method description
Visit: the header of the access class
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);}}; where version refers to the version of the class; acess refers to the class modifier; name class name; signature class signature, if the class is not generic or does not inherit generic class, then signature is empty; superName class parent class name
VisitSource: access the source code of the class, that is, a .java file, which is generally not needed
Public void visitSource (final String source, final String debug) {if (cv! = null) {cv.visitSource (source, debug);}}
VisitModule: it is not clear what it is used for, but it is used less.
VisitNestHost: access the nest host of the class
Nest refers to a collection of class with the same package name that shares private member variables. There is a host (main class) and multiple members (member classes) in nest. In order to provide larger and more extensive nested types, and to complement the lack of access control detection, two new class file properties are introduced. Nest host and nest member,nest host contain a nest members list to identify other static nest members. Nest member contains a nesthost attribute to determine its nesthost
VisitOuterClass: access the external class of the class, generally used for nest-class
VisitAnnotation: comments for access classes
Public AnnotationVisitor visitAnnotation (final String descriptor, final boolean visible) {if (cv! = null) {return cv.visitAnnotation (descriptor, visible);} return null;} where: descriptor: indicates the description of the annotation class; visible indicates whether the annotation is visible at runtime; return AnnotationVisitor: the Visitor that represents the annotation class, which can be used to access the annotation value
VisitTypeAnnotation: a comment on the signature type (a generic type) of the access class
Public AnnotationVisitor visitTypeAnnotation (final int typeRef, final TypePath typePath, final String descriptor, final boolean visible) {if (api < Opcodes.ASM5) {throw new UnsupportedOperationException ("This feature requires ASM5");} if (cv! = null) {return cv.visitTypeAnnotation (typeRef, typePath, descriptor, visible);} return null;} where: typeRef: refers to the type reference, here can only be TypeReference. (CLASS_TYPE_PARAMETER | CLASS_TYPE_PARAMETER_BOUND | CLASS_EXTENDS) TypePath: the annotated type parameter, wildcard bound,array element type, static inner type;descriptor containing typeRef: description of the annotation class; visible: whether the annotation type is visible at run time
VisitAttribute: access the non-standard properties of a class
Public void visitAttribute (final Attribute attribute) {if (cv! = null) {cv.visitAttribute (attribute);}}
VisitNestMember: access the nest member of the nested class. This method can only be called if host class is visited.
VisitInnerClass: access the information of an inner class
VisitField: access the domain information of a class. If you need to modify or add a domain, you can override this method
Public FieldVisitor visitField (final int access, final String name, final String descriptor,final String signature, final Object value) {if (cv! = null) {return cv.visitField (access, name, descriptor, signature, value);} return null;} where access: indicates the access method of the domain, public,private or static,final, etc. Name: refers to the name of the domain Descriptro: the description of the domain, which generally refers to the parameter type of the field; signature: refers to the signature of the domain, which is usually only signed by the generic field; value: refers to the initial value of the domain reture FiedVisitor: indicates that an access object that can access the annotations and properties of the domain will be returned, and can be set to empty if you are not interested
VisitMethod: access the method of the class, which can be overridden if you need to modify the method information of the class
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;} where: decsriptor: indicates the parameter type and return value type of the method
VisitEnd: access the tail of the class, which can only be called when the class access ends, and must be called at the same time
Thank you for your reading, the above is the content of "what is ClassVisitor", after the study of this article, I believe you have a deeper understanding of what is ClassVisitor, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.