diff options
author | Robbert Jan Grootjans <grootjans@gmail.com> | 2012-05-22 00:24:59 +0200 |
---|---|---|
committer | Robbert Jan Grootjans <grootjans@gmail.com> | 2012-05-22 00:24:59 +0200 |
commit | a6a8e4c5554ff000bbac43f4f7f530f661e036d2 (patch) | |
tree | 49d516b6e6e5a2478841b8465341e31572b6ed0a /src/core/lombok/javac/handlers/JavacHandlerUtil.java | |
parent | 68ca15986728c4d0fdf10a98761693ff6623f18f (diff) | |
download | lombok-a6a8e4c5554ff000bbac43f4f7f530f661e036d2.tar.gz lombok-a6a8e4c5554ff000bbac43f4f7f530f661e036d2.tar.bz2 lombok-a6a8e4c5554ff000bbac43f4f7f530f661e036d2.zip |
Javac implementation of @ExtensionMethod.
Casual tests show that it is working. Taken from lombok-pg.
Diffstat (limited to 'src/core/lombok/javac/handlers/JavacHandlerUtil.java')
-rw-r--r-- | src/core/lombok/javac/handlers/JavacHandlerUtil.java | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java index fc7666ec..6dc97fd4 100644 --- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java +++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java @@ -387,9 +387,7 @@ public class JavacHandlerUtil { * @param node Any node that represents the Type (JCClassDecl) to look in, or any child node thereof. */ public static MemberExistsResult fieldExists(String fieldName, JavacNode node) { - while (node != null && !(node.get() instanceof JCClassDecl)) { - node = node.up(); - } + node = upToTypeNode(node); if (node != null && node.get() instanceof JCClassDecl) { for (JCTree def : ((JCClassDecl)node.get()).defs) { @@ -418,9 +416,7 @@ public class JavacHandlerUtil { * @param 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 MemberExistsResult methodExists(String methodName, JavacNode node, boolean caseSensitive, int params) { - while (node != null && !(node.get() instanceof JCClassDecl)) { - node = node.up(); - } + node = upToTypeNode(node); if (node != null && node.get() instanceof JCClassDecl) { for (JCTree def : ((JCClassDecl)node.get()).defs) { @@ -461,9 +457,7 @@ public class JavacHandlerUtil { * @param node Any node that represents the Type (JCClassDecl) to look in, or any child node thereof. */ public static MemberExistsResult constructorExists(JavacNode node) { - while (node != null && !(node.get() instanceof JCClassDecl)) { - node = node.up(); - } + node = upToTypeNode(node); if (node != null && node.get() instanceof JCClassDecl) { for (JCTree def : ((JCClassDecl)node.get()).defs) { @@ -871,4 +865,28 @@ public class JavacHandlerUtil { } return out.toList(); } + + static boolean isClass(JavacNode typeNode) { + return isClassAndDoesNotHaveFlags(typeNode, Flags.INTERFACE | Flags.ENUM | Flags.ANNOTATION); + } + + static boolean isClassOrEnum(JavacNode typeNode) { + return isClassAndDoesNotHaveFlags(typeNode, Flags.INTERFACE | Flags.ANNOTATION); + } + + private static boolean isClassAndDoesNotHaveFlags(JavacNode typeNode, int flags) { + JCClassDecl typeDecl = null; + if (typeNode.get() instanceof JCClassDecl) typeDecl = (JCClassDecl)typeNode.get(); + else return false; + + long typeDeclflags = typeDecl == null ? 0 : typeDecl.mods.flags; + return (typeDeclflags & flags) == 0; + } + + public static JavacNode upToTypeNode(JavacNode node) { + if (node == null) throw new NullPointerException("node"); + while ((node != null) && !(node.get() instanceof JCClassDecl)) node = node.up(); + + return node; + } } |