Skip to content

Commit

Permalink
Remove duplicate content in copied @param tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawi01 committed Jun 15, 2024
1 parent 26c8271 commit a2dd5ff
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 13 deletions.
21 changes: 14 additions & 7 deletions src/core/lombok/core/handlers/HandlerUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -910,9 +910,13 @@ public enum JavadocTag {
}
}

public static String stripLinesWithTagFromJavadoc(String javadoc, JavadocTag tag) {
public static String stripLinesWithTagFromJavadoc(String javadoc, JavadocTag... tags) {
if (javadoc == null || javadoc.isEmpty()) return javadoc;
return tag.pattern.matcher(javadoc).replaceAll("").trim();
String result = javadoc;
for (JavadocTag tag : tags) {
result = tag.pattern.matcher(result).replaceAll("").trim();
}
return result;
}

public static String stripSectionsFromJavadoc(String javadoc) {
Expand Down Expand Up @@ -968,7 +972,7 @@ public static String addReturnsUpdatedSelfIfNeeded(String in) {

public static String addJavadocLine(String in, String line) {
if (in == null) return line;
if (in.endsWith("\n")) return in + line + "\n";
if (in.endsWith("\n")) return in + line;
return in + "\n" + line;
}

Expand All @@ -990,11 +994,14 @@ public static String getConstructorParameterJavadoc(String paramName, String fie
String fieldBaseJavadoc = stripSectionsFromJavadoc(fieldJavadoc);

String paramJavadoc = getParamJavadoc(fieldBaseJavadoc, paramName);
if (paramJavadoc == null) {
paramJavadoc = stripLinesWithTagFromJavadoc(fieldBaseJavadoc, JavadocTag.PARAM);
paramJavadoc = stripLinesWithTagFromJavadoc(paramJavadoc, JavadocTag.RETURN);
if (paramJavadoc != null) {
return paramJavadoc;
}

return paramJavadoc;
String javadocWithoutTags = stripLinesWithTagFromJavadoc(fieldBaseJavadoc, JavadocTag.PARAM, JavadocTag.RETURN);
if (javadocWithoutTags != null) {
return "@param " + paramName + " " + javadocWithoutTags;
}
return null;
}
}
4 changes: 2 additions & 2 deletions src/core/lombok/eclipse/handlers/HandleConstructor.java
Original file line number Diff line number Diff line change
Expand Up @@ -598,12 +598,12 @@ private void generateConstructorJavadoc(EclipseNode typeNode, EclipseNode constr
String paramJavadoc = getConstructorParameterJavadoc(paramName, fieldJavadoc);

if (paramJavadoc == null) {
paramJavadoc = "";
paramJavadoc = "@param " + paramName;
} else {
fieldDescriptionAdded = true;
}

constructorJavadoc = addJavadocLine(constructorJavadoc, "@param " + paramName + " " + paramJavadoc);
constructorJavadoc = addJavadocLine(constructorJavadoc, paramJavadoc);
}
if (fieldDescriptionAdded) {
setDocComment(typeNode, constructorNode, constructorJavadoc);
Expand Down
4 changes: 2 additions & 2 deletions src/core/lombok/javac/handlers/HandleConstructor.java
Original file line number Diff line number Diff line change
Expand Up @@ -490,12 +490,12 @@ private void generateConstructorJavadoc(JCMethodDecl constructor, JavacNode type
String paramJavadoc = getConstructorParameterJavadoc(paramName, fieldJavadoc);

if (paramJavadoc == null) {
paramJavadoc = "";
paramJavadoc = "@param " + paramName;
} else {
fieldDescriptionAdded = true;
}

constructorJavadoc = addJavadocLine(constructorJavadoc, "@param " + paramName + " " + paramJavadoc);
constructorJavadoc = addJavadocLine(constructorJavadoc, paramJavadoc);
}
if (fieldDescriptionAdded) {
setDocComment(cu, constructor, constructorJavadoc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ConstructorJavadoc {
/**
* Creates a new {@code ConstructorJavadoc} instance.
*
* @param fieldName Some text
* @param fieldName Hello, World1
* @param fieldName2 Sky is blue
*/
@java.lang.SuppressWarnings("all")
Expand Down
2 changes: 1 addition & 1 deletion test/transform/resource/after-ecj/ConstructorJavadoc.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* Creates a new {@code ConstructorJavadoc} instance.
*
* @param fieldName Some text
* @param fieldName Hello, World1
* @param fieldName2 Sky is blue
*/
public @java.lang.SuppressWarnings("all") @lombok.Generated ConstructorJavadoc(final int fieldName, final int fieldName2) {
Expand Down

0 comments on commit a2dd5ff

Please sign in to comment.