Consider the following Java
/**
* Some comments
*/
package foo;
import java.util.List;
...
CommentsHelper.AddPackageComments processes comments as follows
var (kind, pre, post) = GetCommentInfo(comment);
var commentTrivia = SyntaxFactory.SyntaxTrivia(kind, pre + comment.getContent() + post + Environment.NewLine);
GetCommentInfo has the following logic
private static (SyntaxKind kind, string? pre, string? post) GetCommentInfo(
JavaComments.Comment comment)
{
return comment switch
{
JavaComments.BlockComment => (SyntaxKind.MultiLineCommentTrivia, "/*", "*/"),
JavaComments.JavadocComment => (SyntaxKind.XmlComment, null, null),
_ => (SyntaxKind.SingleLineCommentTrivia, "//", null),
};
}
The comment is being detected as being a JavadocComment, and so XmlComment is returned. However, XmlComment is not a valid SyntaKind to pass to SyntaxFactory.SyntaxTrivia, so this crashes.
CommentsHelper.AddCommentsTrivia shows how other code paths handle the XmlComment kind
var (kind, pre, post) = GetCommentInfo(comment);
if (kind == SyntaxKind.XmlComment)
{
leadingTriviaList.AddRange(ConvertDocComment(comment, post));
}
else
{
var commentTrivia = SyntaxFactory.SyntaxTrivia(kind, pre + comment.getContent() + post);
I tried copying the pattern used by the AddCommentsTrivia method, but the result of that is a <summary> being applied above the first using with the line formatting messed up, which is incorrect
<summary>foo</summary> using java.List;
I got something sort of OK looking by doing this instead
var (kind, pre, post) = GetCommentInfo(comment);
if (kind == SyntaxKind.XmlComment)
{
kind = SyntaxKind.MultiLineCommentTrivia;
pre = "/*";
post = "*/";
}
var commentTrivia = SyntaxFactory.SyntaxTrivia(kind, pre + comment.getContent() + post + Environment.NewLine);
output:
/*
* foo
*
*
*/
using java.List;
I think the ideal output will be like this
/*
* foo
*/
using java.List;
AddPackageContents makes two calls to GetCommentInfo. I crashed on the second call, but I would say the first call may also need to be fixed up. Method AddUsingComments also has the same issue (which I also crashed on)
Consider the following Java
CommentsHelper.AddPackageCommentsprocesses comments as followsGetCommentInfohas the following logicThe comment is being detected as being a
JavadocComment, and soXmlCommentis returned. However,XmlCommentis not a validSyntaKindto pass toSyntaxFactory.SyntaxTrivia, so this crashes.CommentsHelper.AddCommentsTriviashows how other code paths handle theXmlCommentkindI tried copying the pattern used by the
AddCommentsTriviamethod, but the result of that is a<summary>being applied above the firstusingwith the line formatting messed up, which is incorrectI got something sort of OK looking by doing this instead
output:
I think the ideal output will be like this
AddPackageContentsmakes two calls toGetCommentInfo. I crashed on the second call, but I would say the first call may also need to be fixed up. MethodAddUsingCommentsalso has the same issue (which I also crashed on)