-
-
Notifications
You must be signed in to change notification settings - Fork 107
Description
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)