c2nes / javalang

Pure Python Java parser and tools
MIT License
735 stars 160 forks source link

Can we use javalang to remove comments form java files? #91

Open Hareem-E-Sahar opened 3 years ago

Hareem-E-Sahar commented 3 years ago

I need just code, no inline or multiline comments, javadoc comments or copyright notices. How can I remove them? Tried regex but not very helpful since I have incomplete code / partial code.

lyriccoder commented 3 years ago

This framework does not provide opportunity to generate code from AST. A comment is a kind of AST node, it can be also a statement/expression, etc. I see that you need to remove/insert AST nodes () from/to AST tree and then generate the source code from it. It is not possible, this framework is too weak. It can only search for smth (for AST node). You need to find another framework, it's better to use java framework like JDT