Comment Converter from C# to Java

C# XML comments and Javadoc comments have a large overlap in semantic functionality but annoyingly use a very different syntax. C# XML comments are usually introduced by three slashes /// on each line and use XML elements for semantic information, whereas Javadoc employs standard comment blocks starting with /** (also optionally supported by C# but rarely used) and custom tags starting with @, with or without surrounding curly braces.

The required translation when porting from C# to Java is mostly mechanical but quite tiresome. So I wrote a small Java command-line utility that automates much of the process: Comment Converter. The linked page contains a download package with source code, a detailed description of the conversion process, and an input/output sample. I’ve been using the utility on some real-world files and it seems to work quite well. Let me know if you find any bugs or would like to see new features.

2017-01-12: Version 1.0.1 now also translates some common C# exception class names into their closest Java equivalents. The home page shows a table with the new translation pairs.

2018-04-29: Version 1.0.2 automatically falls back to ISO-8859-1 when inputs fail to decode as UTF-8, and also fixes a bug where translating ArgumentException would cause an infinite loop.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.