aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/javac/JavacNode.java
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2018-04-23 23:43:15 +0200
committerReinier Zwitserloot <reinier@zwitserloot.com>2018-05-14 22:03:46 +0200
commitad21a1573bab57c63ffd5b9867f8e19ac7f0c94b (patch)
tree6aeb4aff3490999ff799374cf9cbbbc33a5d03c5 /src/core/lombok/javac/JavacNode.java
parent82a7354a848a26021afd3a889cefd65db7693eb9 (diff)
downloadlombok-ad21a1573bab57c63ffd5b9867f8e19ac7f0c94b.tar.gz
lombok-ad21a1573bab57c63ffd5b9867f8e19ac7f0c94b.tar.bz2
lombok-ad21a1573bab57c63ffd5b9867f8e19ac7f0c94b.zip
[annotation based ToString] hey.. we have annotation based ToString now, where you can include/exclude fields by annotating the fields.
Diffstat (limited to 'src/core/lombok/javac/JavacNode.java')
-rw-r--r--src/core/lombok/javac/JavacNode.java71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/core/lombok/javac/JavacNode.java b/src/core/lombok/javac/JavacNode.java
index fa24c2f9..2bce6e3a 100644
--- a/src/core/lombok/javac/JavacNode.java
+++ b/src/core/lombok/javac/JavacNode.java
@@ -21,13 +21,17 @@
*/
package lombok.javac;
+import java.lang.annotation.Annotation;
import java.util.List;
import javax.lang.model.element.Element;
import javax.tools.Diagnostic;
+import lombok.core.AnnotationValues;
import lombok.core.AST.Kind;
+import lombok.javac.handlers.JavacHandlerUtil;
+import com.sun.tools.javac.code.Flags;
import com.sun.tools.javac.code.Symtab;
import com.sun.tools.javac.model.JavacTypes;
import com.sun.tools.javac.tree.JCTree;
@@ -36,6 +40,7 @@ import com.sun.tools.javac.tree.JCTree.JCBlock;
import com.sun.tools.javac.tree.JCTree.JCClassDecl;
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
+import com.sun.tools.javac.tree.JCTree.JCModifiers;
import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.Name;
@@ -256,4 +261,70 @@ public class JavacNode extends lombok.core.LombokNode<JavacAST, JavacNode, JCTre
public void addWarning(String message, DiagnosticPosition pos) {
ast.printMessage(Diagnostic.Kind.WARNING, message, null, pos, false);
}
+
+ @Override public boolean hasAnnotation(Class<? extends Annotation> type) {
+ return JavacHandlerUtil.hasAnnotationAndDeleteIfNeccessary(type, this);
+ }
+
+ @Override public <Z extends Annotation> AnnotationValues<Z> findAnnotation(Class<Z> type) {
+ JavacNode annotation = JavacHandlerUtil.findAnnotation(type, this, true);
+ if (annotation == null) return null;
+ return JavacHandlerUtil.createAnnotation(type, annotation);
+ }
+
+ private JCModifiers getModifiers() {
+ if (node instanceof JCClassDecl) return ((JCClassDecl) node).getModifiers();
+ if (node instanceof JCMethodDecl) return ((JCMethodDecl) node).getModifiers();
+ if (node instanceof JCVariableDecl) return ((JCVariableDecl) node).getModifiers();
+ return null;
+ }
+
+ @Override public boolean isStatic() {
+ if (node instanceof JCClassDecl) {
+ JavacNode directUp = directUp();
+ if (directUp == null || directUp.getKind() == Kind.COMPILATION_UNIT) return true;
+ if (!(directUp.get() instanceof JCClassDecl)) return false;
+ JCClassDecl p = (JCClassDecl) directUp.get();
+ long f = p.mods.flags;
+ if ((Flags.INTERFACE & f) != 0) return true;
+ if ((Flags.ENUM & f) != 0) return true;
+ }
+
+ if (node instanceof JCVariableDecl) {
+ JavacNode directUp = directUp();
+ if (directUp != null && directUp.get() instanceof JCClassDecl) {
+ JCClassDecl p = (JCClassDecl) directUp.get();
+ long f = p.mods.flags;
+ if ((Flags.INTERFACE & f) != 0) return true;
+ }
+ }
+
+ JCModifiers mods = getModifiers();
+ if (mods == null) return false;
+ return (mods.flags & Flags.STATIC) != 0;
+ }
+
+ @Override public boolean isEnumMember() {
+ if (getKind() != Kind.FIELD) return false;
+ JCModifiers mods = getModifiers();
+ return mods != null && (Flags.ENUM & mods.flags) != 0;
+ }
+
+ @Override public boolean isTransient() {
+ if (getKind() != Kind.FIELD) return false;
+ JCModifiers mods = getModifiers();
+ return mods != null && (Flags.TRANSIENT & mods.flags) != 0;
+ }
+
+ @Override public int countMethodParameters() {
+ if (getKind() != Kind.METHOD) return 0;
+
+ com.sun.tools.javac.util.List<JCVariableDecl> params = ((JCMethodDecl) node).params;
+ if (params == null) return 0;
+ return params.size();
+ }
+
+ @Override public int getStartPos() {
+ return node.getPreferredPosition();
+ }
}