public class JavacHandlerUtil extends Object
Modifier and Type | Class and Description |
---|---|
static class |
JavacHandlerUtil.CopyJavadoc |
static class |
JavacHandlerUtil.FieldAccess |
static class |
JavacHandlerUtil.MemberExistsResult
Serves as return value for the methods that check for the existence of fields and methods.
|
Modifier and Type | Method and Description |
---|---|
static long |
addFinalIfNeeded(long flags,
Context context) |
static void |
addGenerated(JCModifiers mods,
JavacNode node,
int pos,
JCTree source,
Context context) |
static void |
addSuppressWarningsAll(JCModifiers mods,
JavacNode node,
int pos,
JCTree source,
Context context) |
static boolean |
annotationTypeMatches(Class<? extends Annotation> type,
JavacNode node)
Checks if the Annotation AST Node provided is likely to be an instance of the provided annotation type.
|
static JCExpression |
chainDots(JavacNode node,
int pos,
String elem1,
String elem2,
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 JCExpression |
chainDots(JavacNode node,
lombok.core.LombokImmutableList<String> elems) |
static JCExpression |
chainDots(JavacNode node,
String[] elems) |
static JCExpression |
chainDots(JavacNode node,
String elem1,
String elem2,
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 JCExpression |
chainDotsString(JavacNode node,
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 JCExpression |
cloneSelfType(JavacNode childOfType) |
static JCExpression |
cloneType(lombok.javac.JavacTreeMaker maker,
JCExpression in,
JCTree source,
Context context)
Creates a full clone of a given javac AST type node.
|
static JavacHandlerUtil.MemberExistsResult |
constructorExists(JavacNode node)
Checks if there is a (non-default) constructor.
|
static void |
copyJavadoc(JavacNode from,
JCTree to,
JavacHandlerUtil.CopyJavadoc copyMode)
Copies javadoc on one node to the other.
|
static <any> |
copyTypeParams(lombok.javac.JavacTreeMaker maker,
<any> params) |
static <A extends Annotation> |
createAnnotation(Class<A> type,
JavacNode node)
Creates an instance of
AnnotationValues for the provided AST Node. |
static <any> |
createListOfNonExistentFields(<any> 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 |
deleteAnnotationIfNeccessary(JavacNode annotation,
Class<? extends 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 void |
deleteAnnotationIfNeccessary(JavacNode annotation,
Class<? extends Annotation> annotationType1,
Class<? extends Annotation> annotationType2)
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 void |
deleteImportFromCompilationUnit(JavacNode node,
String name) |
static JavacHandlerUtil.MemberExistsResult |
fieldExists(String fieldName,
JavacNode node)
Checks if there is a field with the provided name.
|
static <any> |
findAnnotations(JavacNode fieldNode,
Pattern namePattern)
Searches the given field node for annotations and returns each one that matches the provided regular expression pattern.
|
static JCStatement |
generateNullCheck(lombok.javac.JavacTreeMaker maker,
JavacNode variable,
JavacNode source)
Generates a new statement that checks if the given variable is null, and if so, throws a specified exception with the
variable name as message.
|
static JCExpression |
genJavaLangTypeRef(JavacNode node,
int pos,
String... simpleNames) |
static JCExpression |
genJavaLangTypeRef(JavacNode node,
String... simpleNames) |
static JCExpression |
genTypeRef(JavacNode node,
String complexName) |
static AnnotationValues<Accessors> |
getAccessorsForField(JavacNode field) |
static JCTree |
getGeneratedBy(JCTree node) |
static boolean |
hasAnnotation(Class<? extends Annotation> type,
JavacNode node) |
static boolean |
hasAnnotationAndDeleteIfNeccessary(Class<? extends Annotation> type,
JavacNode node) |
static JavacNode |
injectField(JavacNode typeNode,
JCVariableDecl field)
Adds the given new field declaration to the provided type AST Node.
|
static JavacNode |
injectFieldAndMarkGenerated(JavacNode typeNode,
JCVariableDecl field)
Adds the given new field declaration to the provided type AST Node.
|
static void |
injectMethod(JavacNode typeNode,
JCMethodDecl method)
Adds the given new method declaration to the provided type AST Node.
|
static JavacNode |
injectType(JavacNode typeNode,
JCClassDecl type)
Adds an inner type (class, interface, enum) to the given type.
|
static boolean |
inNetbeansEditor(JavacNode node)
Contributed by Jan Lahoda; many lombok transformations should not be run (or a lite version should be run) when the netbeans editor
is running javac on the open source file to find inline errors and such.
|
static boolean |
isBoolean(JavacNode field) |
static boolean |
isBoolean(JCExpression varType) |
static boolean |
isClassAndDoesNotHaveFlags(JavacNode typeNode,
int flags) |
static boolean |
isConstructorCall(JCStatement statement) |
static boolean |
isEnumConstant(JCVariableDecl field) |
static boolean |
isFieldDeprecated(JavacNode field)
Returns if a field is marked deprecated, either by
@Deprecated or in javadoc |
static boolean |
isGenerated(JCTree node) |
static JavacHandlerUtil.MemberExistsResult |
methodExists(String methodName,
JavacNode node,
boolean caseSensitive,
int params)
Checks if there is a method with the provided name.
|
static JavacHandlerUtil.MemberExistsResult |
methodExists(String methodName,
JavacNode node,
int params) |
static JCExpression |
namePlusTypeParamsToTypeReference(lombok.javac.JavacTreeMaker maker,
Name typeName,
<any> params) |
static boolean |
nodeHasDeprecatedFlag(JCTree node)
Returns if a node is marked deprecated (as picked up on by the parser).
|
static <T extends JCTree> |
recursiveSetGeneratedBy(T node,
JCTree source,
Context context) |
static Name |
removePrefixFromField(JavacNode field) |
static void |
sanityCheckForMethodGeneratingAnnotationsOnBuilderClass(JavacNode typeNode,
JavacNode errorNode) |
static <T extends JCTree> |
setGeneratedBy(T node,
JCTree source,
Context context) |
static boolean |
shouldReturnThis(JavacNode field)
When generating a setter, the setter either returns void (beanspec) or Self (fluent).
|
static String[] |
splitJavadocOnSectionIfPresent(String javadoc,
String sectionName) |
static String |
stripLinesWithTagFromJavadoc(String javadoc,
String regexpFragment) |
static String |
stripSectionsFromJavadoc(String javadoc) |
static List<String> |
toAllGetterNames(JavacNode field)
Translates the given field into all possible getter names.
|
static List<String> |
toAllSetterNames(JavacNode field)
Translates the given field into all possible setter names.
|
static List<String> |
toAllWitherNames(JavacNode field)
Translates the given field into all possible wither names.
|
static String |
toGetterName(JavacNode field) |
static int |
toJavacModifier(AccessLevel accessLevel)
Turns an
AccessLevel instance into the flag bit used by javac. |
static String |
toSetterName(JavacNode field) |
static String |
toWitherName(JavacNode field) |
static boolean |
typeMatches(Class<?> type,
JavacNode node,
JCTree typeNode)
Checks if the given TypeReference node is likely to be a reference to the provided class.
|
static JavacNode |
upToTypeNode(JavacNode node) |
public static boolean inNetbeansEditor(JavacNode node)
public static JCTree getGeneratedBy(JCTree node)
public static boolean isGenerated(JCTree node)
public static <T extends JCTree> T recursiveSetGeneratedBy(T node, JCTree source, Context context)
public static <T extends JCTree> T setGeneratedBy(T node, JCTree source, Context context)
public static boolean hasAnnotation(Class<? extends Annotation> type, JavacNode node)
public static boolean hasAnnotationAndDeleteIfNeccessary(Class<? extends Annotation> type, JavacNode node)
public static boolean annotationTypeMatches(Class<? extends Annotation> type, JavacNode node)
type
- An actual annotation type, such as lombok.Getter.class
.node
- A Lombok AST node representing an annotation in source code.public static boolean typeMatches(Class<?> type, JavacNode node, JCTree typeNode)
type
- An actual type. This method checks if typeNode
is likely to be a reference to this type.node
- A Lombok AST node. Any node in the appropriate compilation unit will do (used to get access to import statements).typeNode
- A type reference to check.public static boolean isFieldDeprecated(JavacNode field)
@Deprecated
or in javadocfield
- the field to checktrue
if a field is marked deprecated, either by @Deprecated
or in javadoc, otherwise false
public static boolean nodeHasDeprecatedFlag(JCTree node)
node
- the node to check (type, method, or field decl).public static <A extends Annotation> AnnotationValues<A> createAnnotation(Class<A> type, JavacNode node)
AnnotationValues
for the provided AST Node.type
- An annotation class type, such as lombok.Getter.class
.node
- A Lombok AST node representing an annotation in source code.public static void deleteAnnotationIfNeccessary(JavacNode annotation, Class<? extends Annotation> annotationType)
public static void deleteAnnotationIfNeccessary(JavacNode annotation, Class<? extends Annotation> annotationType1, Class<? extends Annotation> annotationType2)
public static void deleteImportFromCompilationUnit(JavacNode node, String name)
public static List<String> toAllGetterNames(JavacNode field)
TransformationsUtil#toAllGetterNames(lombok.core.AnnotationValues, CharSequence, boolean)
.public static String toGetterName(JavacNode field)
TransformationsUtil#toGetterName(lombok.core.AnnotationValues, CharSequence, boolean)
.public static List<String> toAllSetterNames(JavacNode field)
TransformationsUtil#toAllSetterNames(lombok.core.AnnotationValues, CharSequence, boolean)
.public static String toSetterName(JavacNode field)
TransformationsUtil#toSetterName(lombok.core.AnnotationValues, CharSequence, boolean)
.public static List<String> toAllWitherNames(JavacNode field)
TransformationsUtil#toAllWitherNames(lombok.core.AnnotationValues, CharSequence, boolean)
.public static String toWitherName(JavacNode field)
TransformationsUtil#toWitherName(lombok.core.AnnotationValues, CharSequence, boolean)
.public static boolean shouldReturnThis(JavacNode field)
Accessors
annotation to figure that out.public static JCExpression cloneSelfType(JavacNode childOfType)
public static boolean isBoolean(JavacNode field)
public static boolean isBoolean(JCExpression varType)
public static Name removePrefixFromField(JavacNode field)
public static AnnotationValues<Accessors> getAccessorsForField(JavacNode field)
public static JavacHandlerUtil.MemberExistsResult fieldExists(String fieldName, JavacNode node)
fieldName
- the field name to check for.node
- Any node that represents the Type (JCClassDecl) to look in, or any child node thereof.public static JavacHandlerUtil.MemberExistsResult methodExists(String methodName, JavacNode node, int params)
public static JavacHandlerUtil.MemberExistsResult methodExists(String methodName, JavacNode node, boolean caseSensitive, int params)
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.params
- The number of parameters the method should have; varargs count as 0-*. Set to -1 to find any method with the appropriate name regardless of parameter count.public static JavacHandlerUtil.MemberExistsResult constructorExists(JavacNode node)
node
- Any node that represents the Type (JCClassDecl) to look in, or any child node thereof.public static boolean isConstructorCall(JCStatement statement)
public static int toJavacModifier(AccessLevel accessLevel)
AccessLevel
instance into the flag bit used by javac.public static JavacNode injectFieldAndMarkGenerated(JavacNode typeNode, JCVariableDecl field)
SuppressWarnings
("all") annotation.
Also takes care of updating the JavacAST.public static JavacNode injectField(JavacNode typeNode, JCVariableDecl field)
public static boolean isEnumConstant(JCVariableDecl field)
public static void injectMethod(JavacNode typeNode, JCMethodDecl method)
public static JavacNode injectType(JavacNode typeNode, JCClassDecl type)
typeNode
- parent type to inject new type intotype
- New type (class, interface, etc) to inject.public static long addFinalIfNeeded(long flags, Context context)
public static JCExpression genJavaLangTypeRef(JavacNode node, String... simpleNames)
public static JCExpression genJavaLangTypeRef(JavacNode node, int pos, String... simpleNames)
public static void addSuppressWarningsAll(JCModifiers mods, JavacNode node, int pos, JCTree source, Context context)
public static void addGenerated(JCModifiers mods, JavacNode node, int pos, JCTree source, Context context)
public static JCExpression chainDots(JavacNode node, String elem1, String elem2, String... elems)
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.
The position of the generated node(s) will be unpositioned (-1). For example, maker.Select(maker.Select(maker.Ident(NAME[java]), NAME[lang]), NAME[String]).
JCIdent
,
JCFieldAccess
public static JCExpression chainDots(JavacNode node, lombok.core.LombokImmutableList<String> elems)
public static JCExpression chainDots(JavacNode node, int pos, String elem1, String elem2, String... elems)
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.
The position of the generated node(s) will be equal to the pos
parameter.
For example, maker.Select(maker.Select(maker.Ident(NAME[java]), NAME[lang]), NAME[String]).
JCIdent
,
JCFieldAccess
public static JCExpression chainDotsString(JavacNode node, String elems)
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]).JCIdent
,
JCFieldAccess
public static <any> findAnnotations(JavacNode fieldNode, Pattern namePattern)
public static JCStatement generateNullCheck(lombok.javac.JavacTreeMaker maker, JavacNode variable, JavacNode source)
exName
- The name of the exception to throw; normally java.lang.NullPointerException
.public static <any> createListOfNonExistentFields(<any> list, JavacNode type, boolean excludeStandard, boolean excludeTransient)
public static <any> copyTypeParams(lombok.javac.JavacTreeMaker maker, <any> params)
public static JCExpression namePlusTypeParamsToTypeReference(lombok.javac.JavacTreeMaker maker, Name typeName, <any> params)
public static void sanityCheckForMethodGeneratingAnnotationsOnBuilderClass(JavacNode typeNode, JavacNode errorNode)
public static boolean isClassAndDoesNotHaveFlags(JavacNode typeNode, int flags)
public static JCExpression cloneType(lombok.javac.JavacTreeMaker maker, JCExpression in, JCTree source, Context context)
T
is different from the class notion of T
. If you're duplicating
a type used in the class context, you need to use this method.public static String stripLinesWithTagFromJavadoc(String javadoc, String regexpFragment)
public static String[] splitJavadocOnSectionIfPresent(String javadoc, String sectionName)
public static void copyJavadoc(JavacNode from, JCTree to, JavacHandlerUtil.CopyJavadoc copyMode)
@param
lines and other sections.
any @return
lines are stripped from 'from'.
in 'SETTER' mode, stripping works similarly to 'GETTER' mode, except param
are copied and stripped from the original and @return
are skipped.Copyright © 2009-2015 The Project Lombok Authors, licensed under the MIT licence.