![]() ![]() SingletonClassType, nil(), nil(), nil(), block, null) ![]() JCTree.JCMethodDecl factoryMethod = singletonClassTreeMaker = addReturnBlock(singletonClassTreeMaker, holderInnerClass) = singletonClassTreeMaker.Ident(singletonClassDecl.name) JCTree.JCModifiers modifiers = singletonClassTreeMaker JavacHandlerUtil.injectField(holderClass, instanceVar) įinally, let’s add a factory method for accessing the singleton object: private void addFactoryMethod( JCTree.JCVariableDecl instanceVar = singletonClassTM ![]() NewClass(null, nil(), singletonClassType, nil(), null) JCTree.JCNewClass newKeyword = singletonClassTM = singletonClassTM.Ident(singletonClassDecl.name) = (JCTree.JCClassDecl) singletonClass.get() Modifiers(Flags.PRIVATE | Flags.STATIC | Flags.FINAL) JCTree.JCModifiers fieldMod = singletonClassTM Now, we’ll add an instance variable in the holder class: private void addInstanceVar( Return JavacHandlerUtil.injectType(singletonClass, innerClassDecl) ClassDef(modifiers, singletonClass.toName(innerClassName), JCTree.JCClassDecl innerClassDecl = singletonTM String innerClassName = singletonClass.getName() + "Holder" Modifiers(Flags.PRIVATE | Flags.STATIC) JCTree.JCModifiers modifiers = singletonTM Next, the inner SingletonHolder class: private JavacNode addInnerClass( JavacHandlerUtil.injectMethod(singletonClass, constructor) JCTree.JCMethodDecl constructor = singletonTM JCTree.JCBlock block = singletonTM.Block(0L, nil()) JCTree.JCModifiers modifiers = singletonTM.Modifiers(Flags.PRIVATE) First, we’ll generate the private constructor: private void addPrivateConstructor( Now, let’s see how other private methods are implemented for generating the code. It’s important to point out that the deleteAnnotationIfNeccessary() and the deleteImportFromCompilationUnit() methods provided by Lombok are used for removing annotations and any imports for them. JavacNode holderInnerClass = addInnerClass(singletonClass, singletonClassTreeMaker) ĪddInstanceVar(singletonClass, singletonClassTreeMaker, holderInnerClass) ĪddFactoryMethod(singletonClass, singletonClassTreeMaker, holderInnerClass) JavacTreeMaker singletonClassTreeMaker = singletonClass.getTreeMaker() ĪddPrivateConstructor(singletonClass, singletonClassTreeMaker) JavacNode singletonClass = annotationNode.up() deleteImportFromCompilationUnit(annotationNode, "lombok.AccessLevel") deleteAnnotationIfNeccessary(annotationNode, Singleton.class) Javac8BasedLombokOptions options = Javac8BasedLombokOptions Context context = annotationNode.getContext() ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |