Open jrmuizel opened 4 years ago
Hello @jrmuizel
That's true for line comments but not for JavaDoc comments.
If my memory is correct, Javac AST does not provide line comments so there is unfortunately no way to transpile them.
Please close this if this answers your question.
A possible solution I can think of so far would be to create a Java source code preprocessor (for example with JFlex) that would replace all inlined comments with $insert
JSweet macros. For example:
int i = 0; // initialize i
Would be preprocessed to give (would generate in turn the expected TypeScript code):
int i = 0; $insert("// initialize i");
It would not work as is for comments inserted within expressions such as:
int i = /* zero */ 0;
But, maybe if we extend the $insert
macro to insert code around existing expressions it could work...
int i = $insertBefore("/* zero */ ", 0);
Would using something like http://javaparser.org/ instead of the javac AST help?
When I started JSweet, JavaParser was a small project and the AST was too simple to be actually useful for JSweet. Especially, there was no typing (attribution). I can see that the project has evolved a lot and it might be interesting to take a closer look again now. However, I can foresee several potential pitfalls:
Given
The "Hello" comment is dropped in the translation.