aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/javac
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/lombok/javac')
-rw-r--r--src/core/lombok/javac/JavacNode.java8
-rw-r--r--src/core/lombok/javac/handlers/HandleToString.java21
2 files changed, 23 insertions, 6 deletions
diff --git a/src/core/lombok/javac/JavacNode.java b/src/core/lombok/javac/JavacNode.java
index 3963c892..f119f1f9 100644
--- a/src/core/lombok/javac/JavacNode.java
+++ b/src/core/lombok/javac/JavacNode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2017 The Project Lombok Authors.
+ * Copyright (C) 2009-2018 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -317,6 +317,12 @@ public class JavacNode extends lombok.core.LombokNode<JavacAST, JavacNode, JCTre
return mods != null && (Flags.ENUM & mods.flags) != 0;
}
+ @Override public boolean isEnumType() {
+ if (getKind() != Kind.TYPE) 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();
diff --git a/src/core/lombok/javac/handlers/HandleToString.java b/src/core/lombok/javac/handlers/HandleToString.java
index eb6e56f3..3780da79 100644
--- a/src/core/lombok/javac/handlers/HandleToString.java
+++ b/src/core/lombok/javac/handlers/HandleToString.java
@@ -166,23 +166,34 @@ public class HandleToString extends JavacAnnotationHandler<ToString> {
boolean first = true;
String typeName = getTypeName(typeNode);
+ boolean isEnum = typeNode.isEnumType();
+
String infix = ", ";
String suffix = ")";
String prefix;
if (callSuper) {
- prefix = typeName + "(super=";
+ prefix = "(super=";
} else if (members.isEmpty()) {
- prefix = typeName + "()";
+ prefix = isEnum ? "" : "()";
} else if (includeNames) {
Included<JavacNode, ToString.Include> firstMember = members.iterator().next();
String name = firstMember.getInc() == null ? "" : firstMember.getInc().name();
if (name.isEmpty()) name = firstMember.getNode().getName();
- prefix = typeName + "(" + name + "=";
+ prefix = "(" + name + "=";
+ } else {
+ prefix = "(";
+ }
+
+ JCExpression current;
+ if (!isEnum) {
+ current = maker.Literal(typeName + prefix);
} else {
- prefix = typeName + "(";
+ current = maker.Binary(CTC_PLUS, maker.Literal(typeName + "."), maker.Apply(List.<JCExpression>nil(),
+ maker.Select(maker.Ident(typeNode.toName("this")), typeNode.toName("name")),
+ List.<JCExpression>nil()));
+ if (!prefix.isEmpty()) current = maker.Binary(CTC_PLUS, current, maker.Literal(prefix));
}
- JCExpression current = maker.Literal(prefix);
if (callSuper) {
JCMethodInvocation callToSuper = maker.Apply(List.<JCExpression>nil(),