aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/eclipse
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2018-11-05 23:26:59 +0100
committerReinier Zwitserloot <reinier@zwitserloot.com>2018-11-05 23:30:09 +0100
commita73965b2b7b4fe2e163cdb7d104fc5dff1aa7476 (patch)
treedaf21a21c677408ced8c72618ea99beb72efb1f6 /src/core/lombok/eclipse
parent2c0ec9315577cbc8d406aca2b3f3b6ad233f4f35 (diff)
downloadlombok-a73965b2b7b4fe2e163cdb7d104fc5dff1aa7476.tar.gz
lombok-a73965b2b7b4fe2e163cdb7d104fc5dff1aa7476.tar.bz2
lombok-a73965b2b7b4fe2e163cdb7d104fc5dff1aa7476.zip
[fixes #1918] toString now supports a configkey to tell it how to deal with super.
Diffstat (limited to 'src/core/lombok/eclipse')
-rw-r--r--src/core/lombok/eclipse/handlers/HandleToString.java28
1 files changed, 22 insertions, 6 deletions
diff --git a/src/core/lombok/eclipse/handlers/HandleToString.java b/src/core/lombok/eclipse/handlers/HandleToString.java
index 02a19f8d..303e5bea 100644
--- a/src/core/lombok/eclipse/handlers/HandleToString.java
+++ b/src/core/lombok/eclipse/handlers/HandleToString.java
@@ -36,6 +36,7 @@ import lombok.ConfigurationKeys;
import lombok.ToString;
import lombok.core.AST.Kind;
import lombok.core.AnnotationValues;
+import lombok.core.configuration.CallSuperType;
import lombok.core.handlers.InclusionExclusionUtils;
import lombok.core.handlers.InclusionExclusionUtils.Included;
import lombok.eclipse.Eclipse;
@@ -119,12 +120,6 @@ public class HandleToString extends EclipseAnnotationHandler<ToString> {
boolean notAClass = (modifiers &
(ClassFileConstants.AccInterface | ClassFileConstants.AccAnnotation)) != 0;
- if (callSuper == null) {
- try {
- callSuper = ((Boolean)ToString.class.getMethod("callSuper").getDefaultValue()).booleanValue();
- } catch (Exception ignore) {}
- }
-
if (typeDecl == null || notAClass) {
errorNode.addError("@ToString is only supported on a class or enum.");
return;
@@ -132,6 +127,27 @@ public class HandleToString extends EclipseAnnotationHandler<ToString> {
switch (methodExists("toString", typeNode, 0)) {
case NOT_EXISTS:
+ if (callSuper == null) {
+ if (isDirectDescendantOfObject(typeNode)) {
+ callSuper = false;
+ } else {
+ CallSuperType cst = typeNode.getAst().readConfiguration(ConfigurationKeys.TO_STRING_CALL_SUPER);
+ if (cst == null) cst = CallSuperType.SKIP;
+ switch (cst) {
+ default:
+ case SKIP:
+ callSuper = false;
+ break;
+ case WARN:
+ errorNode.addWarning("Generating toString implementation but without a call to superclass, even though this class does not extend java.lang.Object. If this intentional, add '@ToString(callSuper=false)' to your type.");
+ callSuper = false;
+ break;
+ case CALL:
+ callSuper = true;
+ break;
+ }
+ }
+ }
MethodDeclaration toString = createToString(typeNode, members, includeFieldNames, callSuper, errorNode.get(), fieldAccess);
injectMethod(typeNode, toString);
break;