mbien commented on code in PR #7641:
URL: https://github.com/apache/netbeans/pull/7641#discussion_r1711506377
##########
java/java.source.base/src/org/netbeans/modules/java/source/save/Reformatter.java:
##########
@@ -4775,7 +4775,31 @@ private void scanMethodCall(MethodInvocationTree node) {
continuationIndent = old;
}
}
-
+
+
+ private enum JavadocReformattingState{
Review Comment:
nitpick: we typically add a space before the `{`, analog to the other
occurrences in this file
##########
java/java.source.base/src/org/netbeans/modules/java/source/save/Reformatter.java:
##########
@@ -4790,87 +4814,70 @@ private void reformatComment() {
}
final String text = tokens.token().text().toString();
final int offset = tokens.offset();
- LinkedList<Pair<Integer, Integer>> marks = new
LinkedList<Pair<Integer, Integer>>();
+ LinkedList<Pair<Integer, JavadocReformattingActionType>> marks =
new LinkedList<>();
int maxParamNameLength = 0;
int maxExcNameLength = 0;
int initTextEndOffset = Integer.MAX_VALUE;
- final int ACTION_TYPE_ADD_BLANK_LINE = 0;
- final int ACTION_TYPE_ADD_NEW_LINE = 1;
- final int ACTION_TYPE_ALIGN_PARAMS = 2;
- final int ACTION_TYPE_ALIGN_RETURN = 3;
- final int ACTION_TYPE_ALIGN_EXCEPTIONS = 4;
- final int ACTION_TYPE_NO_FORMAT = 5;
- final int ACTION_TYPE_FORMAT = 6;
if (javadocTokens != null) {
-
- final int STATE_INITIAL_TEXT = 0;
- final int STATE_AFTER_PARAM_TAG = 1;
- final int STATE_PARAM_DESCRIPTION = 2;
- final int STATE_RETURN_DESCRIPTION = 3;
- final int STATE_AFTER_THROWS_TAG = 4;
- final int STATE_EXCEPTION_DESCRIPTION = 5;
- final int STATE_AFTER_PRE_TAG = 6;
- final int STATE_AFTER_OTHER_TAG = 7;
-
- int state = STATE_INITIAL_TEXT;
- int currWhiteSpaceOffset = -1;
- int lastWhiteSpaceOffset = -1;
+ JavadocReformattingState state =
JavadocReformattingState.INITIAL_TEXT;
+ int currWSOffset = -1;
+ int lastWSOffset = -1;
int identStart = -1;
int lastNLOffset = -1;
int lastAddedNLOffset = -1;
boolean afterText = false;
boolean insideTag = false;
int nestedParenCnt = 0;
StringBuilder cseq = null;
- Pair<Integer, Integer> marker = null;
- Pair<Integer, Integer> nlAdd = null;
+ Pair<Integer, JavadocReformattingActionType> marker = null;
+ Pair<Integer, JavadocReformattingActionType> nlAdd = null;
while (javadocTokens.moveNext()) {
switch (javadocTokens.token().id()) {
case TAG:
marker = null;
nlAdd = null;
String tokenText =
javadocTokens.token().text().toString();
- int newState;
+ JavadocReformattingState newState;
if
(hasInlineTagPrefix(text,tokenText,javadocTokens.offset()-offset)) {
insideTag = true;
- addMark(Pair.of(currWhiteSpaceOffset,
ACTION_TYPE_NO_FORMAT), marks, state);
- lastWhiteSpaceOffset = currWhiteSpaceOffset =
-1;
+ addMark(Pair.of(currWSOffset,
JavadocReformattingActionType.NO_FORMAT), marks, state);
+ lastWSOffset = currWSOffset = -1;
break;
} else if
(JDOC_PARAM_TAG.equalsIgnoreCase(tokenText)) {
- newState = STATE_AFTER_PARAM_TAG;
+ newState =
JavadocReformattingState.AFTER_PARAM_TAG;
} else if
(JDOC_RETURN_TAG.equalsIgnoreCase(tokenText)) {
- newState = STATE_RETURN_DESCRIPTION;
+ newState =
JavadocReformattingState.RETURN_DESCRIPTION;
} else if
(JDOC_THROWS_TAG.equalsIgnoreCase(tokenText)
||
JDOC_EXCEPTION_TAG.equalsIgnoreCase(tokenText)) {
- newState = STATE_AFTER_THROWS_TAG;
+ newState =
JavadocReformattingState.AFTER_THROWS_TAG;
} else {
if (insideTag)
break;
- newState = STATE_AFTER_OTHER_TAG;
+ newState =
JavadocReformattingState.AFTER_OTHER_TAG;
}
- if (lastWhiteSpaceOffset < initTextEndOffset &&
newState > STATE_INITIAL_TEXT) {
- initTextEndOffset = lastWhiteSpaceOffset;
+ if (lastWSOffset < initTextEndOffset && (newState
!= JavadocReformattingState.INITIAL_TEXT)) {
+ initTextEndOffset = lastWSOffset;
}
- if (currWhiteSpaceOffset >= 0 && afterText) {
- addMark(Pair.of(currWhiteSpaceOffset,
state == STATE_INITIAL_TEXT && cs.blankLineAfterJavadocDescription()
- || state == STATE_PARAM_DESCRIPTION &&
newState != STATE_AFTER_PARAM_TAG &&
cs.blankLineAfterJavadocParameterDescriptions()
- || state == STATE_RETURN_DESCRIPTION
&& cs.blankLineAfterJavadocReturnTag() ? ACTION_TYPE_ADD_BLANK_LINE :
ACTION_TYPE_ADD_NEW_LINE), marks, state);
+ if (currWSOffset >= 0 && afterText) {
+ addMark(Pair.of(currWSOffset, state ==
JavadocReformattingState.INITIAL_TEXT && cs.blankLineAfterJavadocDescription()
+ || state ==
JavadocReformattingState.PARAM_DESCRIPTION && newState !=
JavadocReformattingState.AFTER_PARAM_TAG &&
cs.blankLineAfterJavadocParameterDescriptions()
+ || state ==
JavadocReformattingState.RETURN_DESCRIPTION &&
cs.blankLineAfterJavadocReturnTag() ?
JavadocReformattingActionType.ADD_BLANK_LINE :
JavadocReformattingActionType.ADD_NEW_LINE), marks, state);
Review Comment:
you could move this block 4 spaces to the left
##########
java/java.source.base/src/org/netbeans/modules/java/source/save/Reformatter.java:
##########
@@ -5411,8 +5426,17 @@ private void reformatComment() {
}
}
- private void addMark(Pair<Integer, Integer> mark, List<Pair<Integer,
Integer>> marks, int state) {
- if (state != 6) {
+ /**
+ *
+ * @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 hasInlineTagPrefix(String commentsText,String
tokenText,int tagTokenStartOffset) {
Review Comment:
space after `,`
##########
java/java.source.base/src/org/netbeans/modules/java/source/save/Reformatter.java:
##########
@@ -4775,7 +4775,31 @@ private void scanMethodCall(MethodInvocationTree node) {
continuationIndent = old;
}
}
-
+
+
+ private enum JavadocReformattingState{
+ INITIAL_TEXT,
+ AFTER_PARAM_TAG,
+ PARAM_DESCRIPTION,
+ RETURN_DESCRIPTION,
+ AFTER_THROWS_TAG,
+ EXCEPTION_DESCRIPTION,
+ AFTER_PRE_TAG,
+ AFTER_OTHER_TAG
+
Review Comment:
nitpick: remove empty line
##########
java/java.source.base/src/org/netbeans/modules/java/source/save/Reformatter.java:
##########
@@ -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 {
Review Comment:
remove extra space again
##########
java/java.source.base/src/org/netbeans/modules/java/source/save/Reformatter.java:
##########
@@ -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)) {
Review Comment:
space after `,` and before/after `-`, analog to other usages in this file
##########
java/java.source.base/test/unit/src/org/netbeans/modules/java/source/save/FormatingTest.java:
##########
@@ -5201,6 +5201,58 @@ public void testJavadoc() throws Exception {
+ "}\n";
reformat(doc, content, golden);
+
+ content ="""
+ package hierbas.del.litoral;
+
+ public class Test{
+ /**{@return foo bar method} */ String bar() {
+ return null;
+ }
+ }""";
+ golden ="""
+ package hierbas.del.litoral;
+
+ public class Test {
+
+ /**
+ * {@return foo bar method}
+ */
+ String bar() {
+ return null;
+ }
+ }
+ """;
+ reformat(doc, content, golden);
+
+
+ content ="""
+ package hierbas.del.litoral;
+
+ public class Test{
+ /** bar method description {@return foo bar method} */
String bar() {
+ return null;
+ }
+ }
+ """;
+ golden ="""
+ package hierbas.del.litoral;
+
+ public class Test {
+
+ /**
+ * bar method description
+ * {@return foo bar method}
+ */
+ String bar() {
+ return null;
+ }
+ }
+ """;
+ reformat(doc, content, golden);
+
+
+
Review Comment:
nitpick: leave one empty line between test cases like in the rest of the
method
##########
java/java.source.base/src/org/netbeans/modules/java/source/save/Reformatter.java:
##########
@@ -5411,8 +5426,17 @@ private void reformatComment() {
}
}
- private void addMark(Pair<Integer, Integer> mark, List<Pair<Integer,
Integer>> marks, int state) {
- if (state != 6) {
+ /**
+ *
+ * @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
Review Comment:
you probably have to quote `{@tagname` here, otherwise javadoc tool might
complain
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists