oreohy.blogg.se

Lombok annotations
Lombok annotations











lombok annotations

JCTree.JCReturn returnValue = singletonClassTreeMaker Select(holderInnerClassType, holderInnerClass.toName("INSTANCE")) JCTree.JCFieldAccess instanceVarAccess = holderInnerClassTreeMaker = holderInnerClassTreeMaker.Ident(holderInnerClassDecl.name) = (JCTree.JCClassDecl) holderInnerClass.get() Let's implement that as well: private JCTree.JCBlock addReturnBlock( JavacHandlerUtil.injectMethod(singletonClass, factoryMethod) Ĭlearly, the factory method returns the instance variable from the holder class. 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)

lombok annotations

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()













Lombok annotations