While attempting to convert a Java file, JavaToCSharp crashed while parsing the following method parameter
struct is a keyword in C#, but not in Java. As such, JavaToCSharp.Declarations.MethodDeclarationVisitor.VisitInternal was crashing here
var paramSyntax = SyntaxFactory.Parameter(
attributeLists: [],
modifiers: modifiers,
type: TypeHelper.ConvertTypeSyntax(type, arrayLevel),
identifier: SyntaxFactory.ParseToken(identifier),
@default: null);
on the basis that the value passed to the identifier parameter was invalid. SyntaxFactory.ParseToken will produce a token of type SyntaxKind.StructKeyword in response to parsing struct rather than a simple identifier token. Earlier in VisitInternal the method TypeHelper.EscapeIdentifier is called, which prepends @ to several types of keywords. Not all keywords are listed here however, so I have updated the list to specify all standard keywords as defined here. There are additional contextual keywords in C# but these should not apply for the purposes of escaping an identifier.
While attempting to convert a Java file, JavaToCSharp crashed while parsing the following method parameter
structis a keyword in C#, but not in Java. As such,JavaToCSharp.Declarations.MethodDeclarationVisitor.VisitInternalwas crashing hereon the basis that the value passed to the
identifierparameter was invalid.SyntaxFactory.ParseTokenwill produce a token of typeSyntaxKind.StructKeywordin response to parsingstructrather than a simple identifier token. Earlier inVisitInternalthe methodTypeHelper.EscapeIdentifieris called, which prepends@to several types of keywords. Not all keywords are listed here however, so I have updated the list to specify all standard keywords as defined here. There are additional contextual keywords in C# but these should not apply for the purposes of escaping an identifier.