In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you what is the use of javac AbstractProcessor in java. I hope you will get something after reading this article. Let's discuss it together.
What can it do?
What it does is, of course, generate a new class or modify the original class, for example, if you encounter such a situation, you can use:
Reflection is so slow. I have seen a large number of Gson. Because reflection is widely used in Gson serialization, every field, every get and set needs reflection, which brings performance problems. The solution is to use it to minimize reflection (replace with JSONObject)
Generate code, as long as there are comments can be read, in short a lot (some android orm frameworks)
Processor
Javax.annotation.processing.Processor, which will provide annotation processing, is extended in accordance with the SPI specification, and jdk has many processor implementations by default.
AbstractProcessor
The annotation processor is the most important extension processing class.
Note: please make sure that the environment variable of JAVA has been configured successfully, and add tools.jar (which is derived from this package) to the environment variable of your computer.
ProcessingEnvironment is a collection of annotation processing tools Element is an interface that represents a program element, which can be a package, class, method, or a variable. The subinterfaces known to Element are:
PackageElement represents a package element. Provides access to information about the package and its members.
ExecutableElement represents the method, constructor, or initializer (static or instance) of a class or interface, including annotation type elements.
TypeElement represents a class or interface program element. Provides access to information about types and their members. Note that an enumerated type is a class, while an annotation type is an interface.
VariableElement represents a field, enum constant, method or constructor parameter, local variable, or exception parameter. Source code
Focus on process method
/ / derives from the name of the supported annotation type specified in the javax.annotation.processing;public abstract class AbstractProcessor implements Processor {/ / collection (full package name + class name if necessary) public Set getSupportedAnnotationTypes () {SupportedAnnotationTypes sat = this.getClass () .getAnnotation (SupportedAnnotationTypes.class) If (sat = = null) {if (isInitialized ()) processingEnv.getMessager () .printMessage (Diagnostic.Kind.WARNING "No SupportedAnnotationTypes annotation" + "found on" + this.getClass (). GetName () + ", returning an empty set. Return Collections.emptySet ();} else return arrayToSet (sat.value ());} / / specify the Java version public SourceVersion getSupportedSourceVersion () {SupportedSourceVersion ssv = this.getClass () .getAnnotation (SupportedSourceVersion.class); SourceVersion sv = null; if (ssv = = null) {sv = SourceVersion.RELEASE_6 If (isInitialized ()) processingEnv.getMessager (). PrintMessage (Diagnostic.Kind.WARNING "No SupportedSourceVersion annotation" + "found on" + this.getClass () .getName () + ", returning" + sv + ".) } else sv = ssv.value (); return sv;} / / initialize processor public synchronized void init (ProcessingEnvironment processingEnv) {if (initialized) throw new IllegalStateException ("Cannot call init more than once."); Objects.requireNonNull (processingEnv, "Tool provided null ProcessingEnvironment"); this.processingEnv = processingEnv; initialized = true } / * whether these comments are processed by Processor. If this method returns ture, it indicates that the comment has been processed and will not be processed by other processors; if false is returned, it can still be processed by other processors * / public abstract boolean process (Set)
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.