diff options
6 files changed, 36 insertions, 12 deletions
diff --git a/src/core/lombok/eclipse/handlers/HandleToString.java b/src/core/lombok/eclipse/handlers/HandleToString.java index 37c73bc8..93821412 100644 --- a/src/core/lombok/eclipse/handlers/HandleToString.java +++ b/src/core/lombok/eclipse/handlers/HandleToString.java @@ -177,9 +177,7 @@ public class HandleToString implements EclipseAnnotationHandler<ToString> { private MethodDeclaration createToString(EclipseNode type, Collection<EclipseNode> fields, boolean includeFieldNames, boolean callSuper, ASTNode source, boolean useFieldsDirectly) { - TypeDeclaration typeDeclaration = (TypeDeclaration)type.get(); - char[] rawTypeName = typeDeclaration.name; - String typeName = rawTypeName == null ? "" : new String(rawTypeName); + String typeName = getTypeName(type); char[] suffix = ")".toCharArray(); String infixS = ", "; char[] infix = infixS.toCharArray(); @@ -285,6 +283,22 @@ public class HandleToString implements EclipseAnnotationHandler<ToString> { return method; } + private String getTypeName(EclipseNode type) { + String typeName = getSingleTypeName(type); + EclipseNode upType = type.up(); + while (upType.getKind() == Kind.TYPE) { + typeName = getSingleTypeName(upType) + "." + typeName; + upType = upType.up(); + } + return typeName; + } + + private String getSingleTypeName(EclipseNode type) { + TypeDeclaration typeDeclaration = (TypeDeclaration)type.get(); + char[] rawTypeName = typeDeclaration.name; + return rawTypeName == null ? "" : new String(rawTypeName); + } + private static final Set<String> BUILT_IN_TYPES = Collections.unmodifiableSet(new HashSet<String>(Arrays.asList( "byte", "short", "int", "long", "char", "boolean", "double", "float"))); diff --git a/src/core/lombok/javac/handlers/HandleToString.java b/src/core/lombok/javac/handlers/HandleToString.java index 7b1b3b81..4dce4b9f 100644 --- a/src/core/lombok/javac/handlers/HandleToString.java +++ b/src/core/lombok/javac/handlers/HandleToString.java @@ -174,7 +174,7 @@ public class HandleToString implements JavacAnnotationHandler<ToString> { boolean first = true; - String typeName = ((JCClassDecl) typeNode.get()).name.toString(); + String typeName = getTypeName(typeNode); String infix = ", "; String suffix = ")"; String prefix; @@ -237,4 +237,14 @@ public class HandleToString implements JavacAnnotationHandler<ToString> { return maker.MethodDef(mods, typeNode.toName("toString"), returnType, List.<JCTypeParameter>nil(), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), body, null); } + + private String getTypeName(JavacNode typeNode) { + String typeName = ((JCClassDecl) typeNode.get()).name.toString(); + JavacNode upType = typeNode.up(); + while (upType.getKind() == Kind.TYPE) { + typeName = ((JCClassDecl) upType.get()).name.toString() + "." + typeName; + upType = upType.up(); + } + return typeName; + } } diff --git a/test/transform/resource/after-delombok/DataOnLocalClass.java b/test/transform/resource/after-delombok/DataOnLocalClass.java index f5f5ef31..bb3f564d 100644 --- a/test/transform/resource/after-delombok/DataOnLocalClass.java +++ b/test/transform/resource/after-delombok/DataOnLocalClass.java @@ -90,7 +90,7 @@ class DataOnLocalClass2 { @java.lang.Override @java.lang.SuppressWarnings("all") public java.lang.String toString() { - return "InnerLocal(name=" + this.getName() + ")"; + return "Local.InnerLocal(name=" + this.getName() + ")"; } } @java.lang.SuppressWarnings("all") diff --git a/test/transform/resource/after-delombok/ToStringInner.java b/test/transform/resource/after-delombok/ToStringInner.java index fc376a77..bd8967b7 100644 --- a/test/transform/resource/after-delombok/ToStringInner.java +++ b/test/transform/resource/after-delombok/ToStringInner.java @@ -6,7 +6,7 @@ class ToStringOuter { @java.lang.Override @java.lang.SuppressWarnings("all") public java.lang.String toString() { - return "ToStringInner(y=" + this.y + ")"; + return "ToStringOuter.ToStringInner(y=" + this.y + ")"; } } static class ToStringStaticInner { @@ -14,7 +14,7 @@ class ToStringOuter { @java.lang.Override @java.lang.SuppressWarnings("all") public java.lang.String toString() { - return "ToStringStaticInner(y=" + this.y + ")"; + return "ToStringOuter.ToStringStaticInner(y=" + this.y + ")"; } } class ToStringMiddle { @@ -23,7 +23,7 @@ class ToStringOuter { @java.lang.Override @java.lang.SuppressWarnings("all") public java.lang.String toString() { - return "ToStringMoreInner(name=" + this.name + ")"; + return "ToStringOuter.ToStringMiddle.ToStringMoreInner(name=" + this.name + ")"; } } } diff --git a/test/transform/resource/after-ecj/DataOnLocalClass.java b/test/transform/resource/after-ecj/DataOnLocalClass.java index fca83e06..a17033c2 100644 --- a/test/transform/resource/after-ecj/DataOnLocalClass.java +++ b/test/transform/resource/after-ecj/DataOnLocalClass.java @@ -85,7 +85,7 @@ class DataOnLocalClass2 { return result; } public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { - return (("InnerLocal(name=" + this.getName()) + ")"); + return (("Local.InnerLocal(name=" + this.getName()) + ")"); } } final int x; diff --git a/test/transform/resource/after-ecj/ToStringInner.java b/test/transform/resource/after-ecj/ToStringInner.java index 3970cdc4..2f14407e 100644 --- a/test/transform/resource/after-ecj/ToStringInner.java +++ b/test/transform/resource/after-ecj/ToStringInner.java @@ -6,7 +6,7 @@ import lombok.ToString; super(); } public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { - return (("ToStringInner(y=" + this.y) + ")"); + return (("ToStringOuter.ToStringInner(y=" + this.y) + ")"); } } static @ToString class ToStringStaticInner { @@ -15,7 +15,7 @@ import lombok.ToString; super(); } public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { - return (("ToStringStaticInner(y=" + this.y) + ")"); + return (("ToStringOuter.ToStringStaticInner(y=" + this.y) + ")"); } } class ToStringMiddle { @@ -25,7 +25,7 @@ import lombok.ToString; super(); } public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { - return (("ToStringMoreInner(name=" + this.name) + ")"); + return (("ToStringOuter.ToStringMiddle.ToStringMoreInner(name=" + this.name) + ")"); } } ToStringMiddle() { |