aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/eclipse/EclipseNode.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/eclipse/EclipseNode.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/eclipse/EclipseNode.java')
-rw-r--r--src/core/lombok/eclipse/EclipseNode.java71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/core/lombok/eclipse/EclipseNode.java b/src/core/lombok/eclipse/EclipseNode.java
index 49867e62..4db1d38d 100644
--- a/src/core/lombok/eclipse/EclipseNode.java
+++ b/src/core/lombok/eclipse/EclipseNode.java
@@ -23,7 +23,9 @@ package lombok.eclipse;
import java.util.List;
+import lombok.core.AnnotationValues;
import lombok.core.AST.Kind;
+import lombok.eclipse.handlers.EclipseHandlerUtil;
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
@@ -36,6 +38,7 @@ import org.eclipse.jdt.internal.compiler.ast.Initializer;
import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration;
import org.eclipse.jdt.internal.compiler.ast.Statement;
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
+import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
/**
* Eclipse specific version of the LombokNode class.
@@ -184,4 +187,72 @@ public class EclipseNode extends lombok.core.LombokNode<EclipseAST, EclipseNode,
public boolean isCompleteParse() {
return ast.isCompleteParse();
}
+
+ @Override public boolean hasAnnotation(Class<? extends java.lang.annotation.Annotation> type) {
+ return EclipseHandlerUtil.hasAnnotation(type, this);
+ }
+
+ @Override public <Z extends java.lang.annotation.Annotation> AnnotationValues<Z> findAnnotation(Class<Z> type) {
+ EclipseNode annotation = EclipseHandlerUtil.findAnnotation(type, this);
+ if (annotation == null) return null;
+ return EclipseHandlerUtil.createAnnotation(type, annotation);
+ }
+
+ private Integer getModifiers() {
+ if (node instanceof TypeDeclaration) return ((TypeDeclaration) node).modifiers;
+ if (node instanceof FieldDeclaration) return ((FieldDeclaration) node).modifiers;
+ if (node instanceof LocalDeclaration) return ((LocalDeclaration) node).modifiers;
+ if (node instanceof AbstractMethodDeclaration) return ((AbstractMethodDeclaration) node).modifiers;
+
+ return null;
+ }
+
+ @Override public boolean isStatic() {
+ if (node instanceof TypeDeclaration) {
+ EclipseNode directUp = directUp();
+ if (directUp == null || directUp.getKind() == Kind.COMPILATION_UNIT) return true;
+ if (!(directUp.get() instanceof TypeDeclaration)) return false;
+ TypeDeclaration p = (TypeDeclaration) directUp.get();
+ int f = p.modifiers;
+ if ((ClassFileConstants.AccInterface & f) != 0) return true;
+ if ((ClassFileConstants.AccEnum & f) != 0) return true;
+ }
+
+ if (node instanceof FieldDeclaration) {
+ EclipseNode directUp = directUp();
+ if (directUp != null && directUp.get() instanceof TypeDeclaration) {
+ TypeDeclaration p = (TypeDeclaration) directUp.get();
+ int f = p.modifiers;
+ if ((ClassFileConstants.AccInterface & f) != 0) return true;
+ }
+ }
+
+ Integer i = getModifiers();
+ if (i == null) return false;
+ int f = i.intValue();
+ return (ClassFileConstants.AccStatic & f) != 0;
+ }
+
+ @Override public boolean isTransient() {
+ if (getKind() != Kind.FIELD) return false;
+ Integer i = getModifiers();
+ return i != null && (i.intValue() & ClassFileConstants.AccTransient) != 0;
+ }
+
+ @Override public boolean isEnumMember() {
+ if (getKind() != Kind.FIELD) return false;
+ return ((FieldDeclaration) node).getKind() == 3;
+ }
+
+ @Override public int countMethodParameters() {
+ if (getKind() != Kind.METHOD) return 0;
+
+ Argument[] a = ((AbstractMethodDeclaration) node).arguments;
+ if (a == null) return 0;
+ return a.length;
+ }
+
+ @Override public int getStartPos() {
+ return node.sourceStart;
+ }
}