Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix failing ModelUtilTests #3247 #3257

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ protected char[] getUnparsedDocComment(Element e)
* Javac's behavior with regard to tab expansion and trimming of whitespace and
* asterisks is bizarre and undocumented. We do our best here to emulate it.
*/
private static String formatJavadoc(char[] unparsed)
protected static String formatJavadoc(char[] unparsed)
{
if (unparsed == null || unparsed.length < 5) { // delimiters take 5 chars
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,19 +293,27 @@ public boolean isCompactConstructor(ExecutableElement e) {
MethodBinding methodBinding = (MethodBinding) ((ExecutableElementImpl) e)._binding;
return methodBinding.isCompactConstructor();
}
// Must pass a non-null, non-empty char[]
private boolean isTraditionalJavadoc(char[] unparsed) {
String[] allLines = new String(unparsed).split("\n"); //$NON-NLS-1$
Matcher delimiterMatcher = INITIAL_DELIMITER.matcher(allLines[0]);
return delimiterMatcher.find();
}
@Override
public String getDocComment(Element e) {
DocCommentKind kind = getDocCommentKind(e);
if (kind == null)
char[] unparsed = getUnparsedDocComment(e);
if (unparsed == null)
return null;
if (kind == DocCommentKind.TRADITIONAL) {
return super.getDocComment(e);
if (isTraditionalJavadoc(unparsed)) {
// There will be some duplication of sanity checks between
// isTraditionalJavadoc() and formatJavadoc()
// but will have to live with that.
return super.formatJavadoc(unparsed);
}
// 1. Get the unparsed document content and convert it to individual lines
// 2. Remove the /// from each line
// 3. Common whitespace after /// in each line is removed
// 4. The lines are put together with \n as delimiter and returned
char[] unparsed = getUnparsedDocComment(e);
char[][] lines = TextBlockUtil.convertTextBlockToLines(unparsed);
char[][] contentLines = new char[lines.length][];
for (int i = 0; i < lines.length; i++) {
Expand Down Expand Up @@ -333,17 +341,13 @@ public String getDocComment(Element e) {
}
int textBlockIndent = TextBlockUtil.getWhitespacePrefix(contentLines);
char[] formatTextBlock = TextBlockUtil.formatTextBlock(contentLines, textBlockIndent);
StringBuilder sb = new StringBuilder();
sb.append(formatTextBlock);
return sb.toString();
return new String(formatTextBlock);
}
@Override
public DocCommentKind getDocCommentKind(Element e) {
char[] unparsed = getUnparsedDocComment(e);
if (unparsed == null)
return null;
String[] lines = new String(unparsed).split("\n"); //$NON-NLS-1$
Matcher delimiterMatcher = INITIAL_DELIMITER.matcher(lines[0]);
return (delimiterMatcher.find()) ? DocCommentKind.TRADITIONAL : DocCommentKind.END_OF_LINE;
return isTraditionalJavadoc(unparsed) ? DocCommentKind.TRADITIONAL : DocCommentKind.END_OF_LINE;
}
}
Loading