-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
22
-
generic
-
generic
ADDITIONAL SYSTEM INFORMATION :
org.eclipse.justj.openjdk.hotspot.jre.full.linux.x86_64_22.0.1.v20240426-1149 (embedded Adoptium 22.0.1 in Eclipse IDE)
A DESCRIPTION OF THE PROBLEM :
With this code to orchestrate the compiler
```
JavadocTokenizer commentTokenizer = new JavadocTokenizer(scannerFactory, rawText.toCharArray(), rawText.length()) {
@Override
protected com.sun.tools.javac.parser.Tokens.Comment processComment(int pos, int endPos, CommentStyle style) {
var res = super.processComment(pos, endPos, style);
if (noCommentAt(unit, pos)) { // not already processed
var comment = converter.convert(res, pos, endPos);
missingComments.add(comment);
}
return res;
}
};
Scanner javacScanner = new Scanner(scannerFactory, commentTokenizer) {
// subclass just to access constructor
};
do { // consume all tokens to populate comments
javacScanner.nextToken();
} while (javacScanner.token() != null && javacScanner.token().kind != TokenKind.EOF);
```
I get that parsing/tokenizing a file such as
```
class A {
/**/
}
```
does return a JavadocComment with JAVADOC style for `/**/` while the expectation is that
In practice, the issue is not the comment that is created, but the CommentStyle that is received by processComment() method being incorrect.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the minimal scanning/tokenizing code in description to view or collect the comments, and check the comment retrieved when tokenizing `class A { /**/ }`
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The comment is a BasicComment, with style BLOCK
ACTUAL -
The comment is a JavadocComment, with style JAVADOC
---------- BEGIN SOURCE ----------
// not verified
String rawText = "public class A { /**/ }";
CommentStyle[] commentStyle = new CommentStyle[1];
JavadocTokenizer commentTokenizer = new JavadocTokenizer(scannerFactory, rawText.toCharArray(), rawText.length()) {
@Override
protected com.sun.tools.javac.parser.Tokens.Comment processComment(int pos, int endPos, CommentStyle style) {
commentStyle[0] = style;
return super.processComment(pos, endPos, style);
}
};
Scanner javacScanner = new Scanner(scannerFactory, commentTokenizer) {
// subclass just to access constructor
};
do { // consume all tokens to populate comments
javacScanner.nextToken();
} while (javacScanner.token() != null && javacScanner.token().kind != TokenKind.EOF);
assertEquals(CommentStyle.BLOCK, commentStyle[0]);
```
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
In my custom JavadocTokenizer.processComment() method, I can add as first line a basic condition such as `if (style == CommentStyle.JAVADOC && endPos - pos <= 4) style = CommentStyle.BLOCK`, since we know that a Javadoc cannot be less than 5 characters `/***/`.
FREQUENCY : always
org.eclipse.justj.openjdk.hotspot.jre.full.linux.x86_64_22.0.1.v20240426-1149 (embedded Adoptium 22.0.1 in Eclipse IDE)
A DESCRIPTION OF THE PROBLEM :
With this code to orchestrate the compiler
```
JavadocTokenizer commentTokenizer = new JavadocTokenizer(scannerFactory, rawText.toCharArray(), rawText.length()) {
@Override
protected com.sun.tools.javac.parser.Tokens.Comment processComment(int pos, int endPos, CommentStyle style) {
var res = super.processComment(pos, endPos, style);
if (noCommentAt(unit, pos)) { // not already processed
var comment = converter.convert(res, pos, endPos);
missingComments.add(comment);
}
return res;
}
};
Scanner javacScanner = new Scanner(scannerFactory, commentTokenizer) {
// subclass just to access constructor
};
do { // consume all tokens to populate comments
javacScanner.nextToken();
} while (javacScanner.token() != null && javacScanner.token().kind != TokenKind.EOF);
```
I get that parsing/tokenizing a file such as
```
class A {
/**/
}
```
does return a JavadocComment with JAVADOC style for `/**/` while the expectation is that
In practice, the issue is not the comment that is created, but the CommentStyle that is received by processComment() method being incorrect.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the minimal scanning/tokenizing code in description to view or collect the comments, and check the comment retrieved when tokenizing `class A { /**/ }`
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The comment is a BasicComment, with style BLOCK
ACTUAL -
The comment is a JavadocComment, with style JAVADOC
---------- BEGIN SOURCE ----------
// not verified
String rawText = "public class A { /**/ }";
CommentStyle[] commentStyle = new CommentStyle[1];
JavadocTokenizer commentTokenizer = new JavadocTokenizer(scannerFactory, rawText.toCharArray(), rawText.length()) {
@Override
protected com.sun.tools.javac.parser.Tokens.Comment processComment(int pos, int endPos, CommentStyle style) {
commentStyle[0] = style;
return super.processComment(pos, endPos, style);
}
};
Scanner javacScanner = new Scanner(scannerFactory, commentTokenizer) {
// subclass just to access constructor
};
do { // consume all tokens to populate comments
javacScanner.nextToken();
} while (javacScanner.token() != null && javacScanner.token().kind != TokenKind.EOF);
assertEquals(CommentStyle.BLOCK, commentStyle[0]);
```
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
In my custom JavadocTokenizer.processComment() method, I can add as first line a basic condition such as `if (style == CommentStyle.JAVADOC && endPos - pos <= 4) style = CommentStyle.BLOCK`, since we know that a Javadoc cannot be less than 5 characters `/***/`.
FREQUENCY : always