List all keywords in TypeHelper.EscapeIdentifier by lordmilko · Pull Request #142 · paulirwin/JavaToCSharp

#147

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.