aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/javac/handlers/HandleToString.java
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2013-03-18 22:10:20 +0100
committerReinier Zwitserloot <reinier@zwitserloot.com>2013-03-18 22:10:20 +0100
commit5ec852b35b9f6e0f330098a302ce0d655f792ff7 (patch)
tree06277e260995c05d3416aca3814cc68f160a3b97 /src/core/lombok/javac/handlers/HandleToString.java
parentf341a00baa992e652f119164e24cf64699281e0d (diff)
downloadlombok-5ec852b35b9f6e0f330098a302ce0d655f792ff7.tar.gz
lombok-5ec852b35b9f6e0f330098a302ce0d655f792ff7.tar.bz2
lombok-5ec852b35b9f6e0f330098a302ce0d655f792ff7.zip
Some halfway work on introducing hideNulls feature to toString. Aborted because it is a lot more work than anticipated, but this code is prettier and slightly more bugfree so worth checking in.
Diffstat (limited to 'src/core/lombok/javac/handlers/HandleToString.java')
-rw-r--r--src/core/lombok/javac/handlers/HandleToString.java20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/core/lombok/javac/handlers/HandleToString.java b/src/core/lombok/javac/handlers/HandleToString.java
index 520acf62..5b3c033c 100644
--- a/src/core/lombok/javac/handlers/HandleToString.java
+++ b/src/core/lombok/javac/handlers/HandleToString.java
@@ -198,18 +198,22 @@ public class HandleToString extends JavacAnnotationHandler<ToString> {
}
for (JavacNode fieldNode : fields) {
- JCVariableDecl field = (JCVariableDecl) fieldNode.get();
JCExpression expr;
JCExpression fieldAccessor = createFieldAccessor(maker, fieldNode, fieldAccess);
- if (getFieldType(fieldNode, fieldAccess) instanceof JCArrayTypeTree) {
- boolean multiDim = ((JCArrayTypeTree)field.vartype).elemtype instanceof JCArrayTypeTree;
- boolean primitiveArray = ((JCArrayTypeTree)field.vartype).elemtype instanceof JCPrimitiveTypeTree;
- boolean useDeepTS = multiDim || !primitiveArray;
-
- JCExpression hcMethod = chainDots(typeNode, "java", "util", "Arrays", useDeepTS ? "deepToString" : "toString");
- expr = maker.Apply(List.<JCExpression>nil(), hcMethod, List.<JCExpression>of(fieldAccessor));
+ JCExpression fieldType = getFieldType(fieldNode, fieldAccess);
+
+ // The distinction between primitive and object will be useful if we ever add a 'hideNulls' option.
+ boolean fieldIsPrimitive = fieldType instanceof JCPrimitiveTypeTree;
+ boolean fieldIsPrimitiveArray = fieldType instanceof JCArrayTypeTree && ((JCArrayTypeTree) fieldType).elemtype instanceof JCPrimitiveTypeTree;
+ boolean fieldIsObjectArray = !fieldIsPrimitiveArray && fieldType instanceof JCArrayTypeTree;
+ @SuppressWarnings("unused")
+ boolean fieldIsObject = !fieldIsPrimitive && !fieldIsPrimitiveArray && !fieldIsObjectArray;
+
+ if (fieldIsPrimitiveArray || fieldIsObjectArray) {
+ JCExpression tsMethod = chainDots(typeNode, "java", "util", "Arrays", fieldIsObjectArray ? "deepToString" : "toString");
+ expr = maker.Apply(List.<JCExpression>nil(), tsMethod, List.<JCExpression>of(fieldAccessor));
} else expr = fieldAccessor;
if (first) {