From 1670c0144964c419f6ff42b72d5f278eac5a87db Mon Sep 17 00:00:00 2001 From: Knut Wannheden Date: Wed, 4 Oct 2023 21:10:42 +0200 Subject: [PATCH] Fix printing of false Javadoc attributes This to ensure parse-to-print idempotency. --- .../openrewrite/java/tree/JavadocTest.java | 19 +++++++++++++++++++ .../org/openrewrite/java/JavadocPrinter.java | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/rewrite-java-tck/src/main/java/org/openrewrite/java/tree/JavadocTest.java b/rewrite-java-tck/src/main/java/org/openrewrite/java/tree/JavadocTest.java index 1e24d2b586e..15c510c2a38 100644 --- a/rewrite-java-tck/src/main/java/org/openrewrite/java/tree/JavadocTest.java +++ b/rewrite-java-tck/src/main/java/org/openrewrite/java/tree/JavadocTest.java @@ -1707,4 +1707,23 @@ public static void main(String[] args) { ) ); } + + @Test + void emptyAttributes() { + rewriteRun( + java( + """ + /** + * DEFINE TENANCY TenantB AS + * ENDORSE GROUP TO {OBJECTSTORAGE_NAMESPACE_READ} IN TENANCY TenantB + * + * DEFINE TENANCY TenantA AS + * DEFINE GROUP TenantAGroup AS + * ADMIT GROUP TenantAGroup OF TENANCY TenantA TO {OBJECTSTORAGE_NAMESPACE_READ} IN TENANCY + */ + class Test {} + """ + ) + ); + } } diff --git a/rewrite-java/src/main/java/org/openrewrite/java/JavadocPrinter.java b/rewrite-java/src/main/java/org/openrewrite/java/JavadocPrinter.java index 242f4485648..c36750c55fb 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/JavadocPrinter.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/JavadocPrinter.java @@ -35,7 +35,7 @@ public JavadocPrinter() { public Javadoc visitAttribute(Javadoc.Attribute attribute, PrintOutputCapture

p) { beforeSyntax(attribute, p); p.append(attribute.getName()); - if (attribute.getSpaceBeforeEqual() != null) { + if (attribute.getSpaceBeforeEqual() != null && !attribute.getSpaceBeforeEqual().isEmpty()) { visit(attribute.getSpaceBeforeEqual(), p); if (attribute.getValue() != null) { p.append('=');