Skip to content

Commit

Permalink
Fix empty Javadoc being added
Browse files Browse the repository at this point in the history
  • Loading branch information
shartte committed Dec 22, 2023
1 parent 0cd1c3c commit b3db535
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/main/java/JavadocHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,15 @@ public static void enrichJavadoc(PsiJavaDocumentedElement psiElement,
Map<String, String> renamedParameters,
List<String> parameterOrder,
List<Replacement> 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);

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit b3db535

Please sign in to comment.