From b3db535b4ee049f9d24705dd44a38aefd9662c37 Mon Sep 17 00:00:00 2001 From: Sebastian Hartte Date: Fri, 22 Dec 2023 01:25:43 +0100 Subject: [PATCH] Fix empty Javadoc being added --- src/main/java/JavadocHelper.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/JavadocHelper.java b/src/main/java/JavadocHelper.java index ae75344..8701810 100644 --- a/src/main/java/JavadocHelper.java +++ b/src/main/java/JavadocHelper.java @@ -54,9 +54,15 @@ public static void enrichJavadoc(PsiJavaDocumentedElement psiElement, Map renamedParameters, List parameterOrder, List replacements) { + var existingDocComment = psiElement.getDocComment(); if (existingDocComment != null) { + // If no parameter documentation or javadoc is given, and no parameters were renamed, don't bother + if (javadoc.isEmpty() && parameters.isEmpty() && renamedParameters.isEmpty()) { + return; + } + // Merge the existing body + new lines var bodyLines = getMergedJavadocBody(existingDocComment, javadoc); @@ -89,6 +95,12 @@ public static void enrichJavadoc(PsiJavaDocumentedElement psiElement, JavadocHelper.formatJavadoc(indent, bodyLines, tags, parameterDocs, parameterOrder) )); } else { + + // If no parameter documentation or javadoc is given + if (javadoc.isEmpty() && parameters.isEmpty()) { + return; + } + int indent = 0; // If the element is preceded by whitespace, use the last line of that whitespace as the indent if (psiElement.getPrevSibling() instanceof PsiWhiteSpace psiWhiteSpace) {