Skip to content

Commit

Permalink
check with inline tag prefix string instead of list of defined tags a…
Browse files Browse the repository at this point in the history
…s this list can grow + testcases
  • Loading branch information
naren2605 committed Aug 6, 2024
1 parent 82b3bee commit e785811
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4831,19 +4831,19 @@ private void reformatComment() {
nlAdd = null;
String tokenText = javadocTokens.token().text().toString();
int newState;
if (JDOC_PARAM_TAG.equalsIgnoreCase(tokenText)) {
if (hasInlineTagPrefix(text,tokenText,javadocTokens.offset()-offset)) {
insideTag = true;
addMark(Pair.of(currWhiteSpaceOffset, ACTION_TYPE_NO_FORMAT), marks, state);
lastWhiteSpaceOffset = currWhiteSpaceOffset = -1;
break;
} else if (JDOC_PARAM_TAG.equalsIgnoreCase(tokenText)) {
newState = STATE_AFTER_PARAM_TAG;
} else if (JDOC_RETURN_TAG.equalsIgnoreCase(tokenText)) {
newState = STATE_RETURN_DESCRIPTION;
} else if (JDOC_THROWS_TAG.equalsIgnoreCase(tokenText)
|| JDOC_EXCEPTION_TAG.equalsIgnoreCase(tokenText)) {
newState = STATE_AFTER_THROWS_TAG;
} else if (isInlineTag(tokenText)) {
insideTag = true;
addMark(Pair.of(currWhiteSpaceOffset >= 0 ? currWhiteSpaceOffset : javadocTokens.offset() - offset, ACTION_TYPE_NO_FORMAT), marks, state);
lastWhiteSpaceOffset = currWhiteSpaceOffset = -1;
break;
} else {
} else {
if (insideTag)
break;
newState = STATE_AFTER_OTHER_TAG;
Expand Down Expand Up @@ -5420,20 +5420,11 @@ private void reformatComment() {

/**
*
* @see <a href="https://docs.oracle.com/en/java/javase/22/docs/specs/javadoc/doc-comment-spec.html#Where%20Tags%20Can%20Be%20Used">documentation here</a>
* @param tokenText
* @return returns true if inline tag
* @see <a href="https://docs.oracle.com/en/java/javase/22/docs/specs/javadoc/doc-comment-spec.html#Where%20Tags%20Can%20Be%20Used">for more info on inline tags check documentation here.</a>
* @return returns true if has inline tag prefix like {@tagname
*/
private static boolean isInlineTag(String tokenText) {
return JDOC_LINK_TAG.equalsIgnoreCase(tokenText)
|| JDOC_LINKPLAIN_TAG.equalsIgnoreCase(tokenText)
|| JDOC_CODE_TAG.equalsIgnoreCase(tokenText)
|| JDOC_SNIPPET_TAG.equalsIgnoreCase(tokenText)
|| JDOC_DOCROOT_TAG.equalsIgnoreCase(tokenText)
|| JDOC_INHERITDOC_TAG.equalsIgnoreCase(tokenText)
|| JDOC_VALUE_TAG.equalsIgnoreCase(tokenText)
|| JDOC_SUMMARY_TAG.equalsIgnoreCase(tokenText)
|| JDOC_LITERAL_TAG.equalsIgnoreCase(tokenText);
private static boolean hasInlineTagPrefix(String commentsText,String tokenText,int tagTokenStartOffset) {
return commentsText.startsWith("{"+tokenText, tagTokenStartOffset-1);
}

private void addMark(Pair<Integer, Integer> mark, List<Pair<Integer, Integer>> marks, final int state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5201,6 +5201,51 @@ public void testJavadoc() throws Exception {
+ "}\n";
reformat(doc, content, golden);


content ="package hierbas.del.litoral;\n" +
"\n" +
"public class Test{\n" +
"/**{@return foo bar method} */ String bar() { \n" +
" return null; \n" +
" }\n" +
"}";
golden ="package hierbas.del.litoral;\n" +
"\n" +
"public class Test {\n" +
"\n" +
" /**\n" +
" * {@return foo bar method}\n" +
" */\n" +
" String bar() {\n" +
" return null;\n" +
" }\n" +
"}\n";
reformat(doc, content, golden);


content ="package hierbas.del.litoral;\n" +
"\n" +
"public class Test{\n" +
"/** bar method description {@return foo bar method} */ String bar() { \n" +
" return null; \n" +
" }\n" +
"}";
golden ="package hierbas.del.litoral;\n" +
"\n" +
"public class Test {\n" +
"\n" +
" /**\n" +
" * bar method description\n" +
" * {@return foo bar method}\n" +
" */\n" +
" String bar() {\n" +
" return null;\n" +
" }\n" +
"}\n";
reformat(doc, content, golden);



content =
"package hierbas.del.litoral;\n"
+ "\n"
Expand Down

0 comments on commit e785811

Please sign in to comment.