Lombok - v0.9.3

lombok.javac.handlers
Class JavacHandlerUtil

java.lang.Object
  extended by lombok.javac.handlers.JavacHandlerUtil

public class JavacHandlerUtil
extends java.lang.Object

Container for static utility methods useful to handlers written for javac.


Nested Class Summary
static class JavacHandlerUtil.MemberExistsResult
          Serves as return value for the methods that check for the existence of fields and methods.
 
Method Summary
static com.sun.tools.javac.tree.JCTree.JCExpression chainDots(com.sun.tools.javac.tree.TreeMaker maker, JavacNode node, java.lang.String... elems)
          In javac, dotted access of any kind, from java.lang.String to var.methodName is represented by a fold-left of Select nodes with the leftmost string represented by a Ident node.
static JavacHandlerUtil.MemberExistsResult constructorExists(JavacNode node)
          Checks if there is a (non-default) constructor.
static com.sun.tools.javac.util.List<java.lang.Integer> createListOfNonExistentFields(com.sun.tools.javac.util.List<java.lang.String> list, JavacNode type, boolean excludeStandard, boolean excludeTransient)
          Given a list of field names and a node referring to a type, finds each name in the list that does not match a field within the type.
static void deleteImportFromCompilationUnit(JavacNode node, java.lang.String name)
           
static JavacHandlerUtil.MemberExistsResult fieldExists(java.lang.String fieldName, JavacNode node)
          Checks if there is a field with the provided name.
static com.sun.tools.javac.util.List<com.sun.tools.javac.tree.JCTree.JCAnnotation> findAnnotations(JavacNode fieldNode, java.util.regex.Pattern namePattern)
          Searches the given field node for annotations and returns each one that matches the provided regular expression pattern.
static com.sun.tools.javac.tree.JCTree.JCStatement generateNullCheck(com.sun.tools.javac.tree.TreeMaker treeMaker, JavacNode variable)
          Generates a new statement that checks if the given variable is null, and if so, throws a NullPointerException with the variable name as message.
static void injectField(JavacNode typeNode, com.sun.tools.javac.tree.JCTree.JCVariableDecl field)
          Adds the given new field declaration to the provided type AST Node.
static void injectMethod(JavacNode typeNode, com.sun.tools.javac.tree.JCTree.JCMethodDecl method)
          Adds the given new method declaration to the provided type AST Node.
static boolean isPrimitive(com.sun.tools.javac.tree.JCTree.JCExpression ref)
          Checks if the given expression (that really ought to refer to a type expression) represents a primitive type.
static void markAnnotationAsProcessed(JavacNode annotation, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
          Removes the annotation from javac's AST (it remains in lombok's AST), then removes any import statement that imports this exact annotation (not star imports).
static JavacHandlerUtil.MemberExistsResult methodExists(java.lang.String methodName, JavacNode node)
           
static JavacHandlerUtil.MemberExistsResult methodExists(java.lang.String methodName, JavacNode node, boolean caseSensitive)
          Checks if there is a method with the provided name.
static java.util.List<java.lang.String> toAllGetterNames(com.sun.tools.javac.tree.JCTree.JCVariableDecl field)
          Translates the given field into all possible getter names.
static java.lang.String toGetterName(com.sun.tools.javac.tree.JCTree.JCVariableDecl field)
           
static int toJavacModifier(AccessLevel accessLevel)
          Turns an AccessLevel instance into the flag bit used by javac.
static java.lang.String toSetterName(com.sun.tools.javac.tree.JCTree.JCVariableDecl field)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isPrimitive

public static boolean isPrimitive(com.sun.tools.javac.tree.JCTree.JCExpression ref)
Checks if the given expression (that really ought to refer to a type expression) represents a primitive type.


markAnnotationAsProcessed

public static void markAnnotationAsProcessed(JavacNode annotation,
                                             java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Removes the annotation from javac's AST (it remains in lombok's AST), then removes any import statement that imports this exact annotation (not star imports). Only does this if the DeleteLombokAnnotations class is in the context.


deleteImportFromCompilationUnit

public static void deleteImportFromCompilationUnit(JavacNode node,
                                                   java.lang.String name)

toAllGetterNames

public static java.util.List<java.lang.String> toAllGetterNames(com.sun.tools.javac.tree.JCTree.JCVariableDecl field)
Translates the given field into all possible getter names. Convenient wrapper around TransformationsUtil.toAllGetterNames(CharSequence, boolean).


toGetterName

public static java.lang.String toGetterName(com.sun.tools.javac.tree.JCTree.JCVariableDecl field)
Returns:
the likely getter name for the stated field. (e.g. private boolean foo; to isFoo). Convenient wrapper around TransformationsUtil.toGetterName(CharSequence, boolean).

toSetterName

public static java.lang.String toSetterName(com.sun.tools.javac.tree.JCTree.JCVariableDecl field)
Returns:
the likely setter name for the stated field. (e.g. private boolean foo; to setFoo). Convenient wrapper around TransformationsUtil.toSetterName(CharSequence).

fieldExists

public static JavacHandlerUtil.MemberExistsResult fieldExists(java.lang.String fieldName,
                                                              JavacNode node)
Checks if there is a field with the provided name.

Parameters:
fieldName - the field name to check for.
node - Any node that represents the Type (JCClassDecl) to look in, or any child node thereof.

methodExists

public static JavacHandlerUtil.MemberExistsResult methodExists(java.lang.String methodName,
                                                               JavacNode node)

methodExists

public static JavacHandlerUtil.MemberExistsResult methodExists(java.lang.String methodName,
                                                               JavacNode node,
                                                               boolean caseSensitive)
Checks if there is a method with the provided name. In case of multiple methods (overloading), only the first method decides if EXISTS_BY_USER or EXISTS_BY_LOMBOK is returned.

Parameters:
methodName - the method name to check for.
node - Any node that represents the Type (JCClassDecl) to look in, or any child node thereof.
caseSensitive - If the search should be case sensitive.

constructorExists

public static JavacHandlerUtil.MemberExistsResult constructorExists(JavacNode node)
Checks if there is a (non-default) constructor. In case of multiple constructors (overloading), only the first constructor decides if EXISTS_BY_USER or EXISTS_BY_LOMBOK is returned.

Parameters:
node - Any node that represents the Type (JCClassDecl) to look in, or any child node thereof.

toJavacModifier

public static int toJavacModifier(AccessLevel accessLevel)
Turns an AccessLevel instance into the flag bit used by javac.


injectField

public static void injectField(JavacNode typeNode,
                               com.sun.tools.javac.tree.JCTree.JCVariableDecl field)
Adds the given new field declaration to the provided type AST Node. Also takes care of updating the JavacAST.


injectMethod

public static void injectMethod(JavacNode typeNode,
                                com.sun.tools.javac.tree.JCTree.JCMethodDecl method)
Adds the given new method declaration to the provided type AST Node. Can also inject constructors. Also takes care of updating the JavacAST.


chainDots

public static com.sun.tools.javac.tree.JCTree.JCExpression chainDots(com.sun.tools.javac.tree.TreeMaker maker,
                                                                     JavacNode node,
                                                                     java.lang.String... elems)
In javac, dotted access of any kind, from java.lang.String to var.methodName is represented by a fold-left of Select nodes with the leftmost string represented by a Ident node. This method generates such an expression. For example, maker.Select(maker.Select(maker.Ident(NAME[java]), NAME[lang]), NAME[String]).

See Also:
JCTree.JCIdent, JCTree.JCFieldAccess

findAnnotations

public static com.sun.tools.javac.util.List<com.sun.tools.javac.tree.JCTree.JCAnnotation> findAnnotations(JavacNode fieldNode,
                                                                                                          java.util.regex.Pattern namePattern)
Searches the given field node for annotations and returns each one that matches the provided regular expression pattern. Only the simple name is checked - the package and any containing class are ignored.


generateNullCheck

public static com.sun.tools.javac.tree.JCTree.JCStatement generateNullCheck(com.sun.tools.javac.tree.TreeMaker treeMaker,
                                                                            JavacNode variable)
Generates a new statement that checks if the given variable is null, and if so, throws a NullPointerException with the variable name as message.


createListOfNonExistentFields

public static com.sun.tools.javac.util.List<java.lang.Integer> createListOfNonExistentFields(com.sun.tools.javac.util.List<java.lang.String> list,
                                                                                             JavacNode type,
                                                                                             boolean excludeStandard,
                                                                                             boolean excludeTransient)
Given a list of field names and a node referring to a type, finds each name in the list that does not match a field within the type.


Lombok - v0.9.3

Copyright © 2009 Reinier Zwitserloot and Roel Spilker, licensed under the MIT licence.