indentation - How I can indent generated java code java? -
i work in small learning program generates java code picture. hold code in stringbuilder. wonder can give text normal java code indentation. use library, not format source code, string has generated java code. attention.
how following code:
import java.io.bytearrayinputstream; import com.github.javaparser.javaparser; import com.github.javaparser.parseexception; import com.github.javaparser.ast.compilationunit; public static void main(string[] args) throws parseexception { string java = new string("public class thisisanonwellformattedjavaclass {public static void main(string[] args){}}"); compilationunit cu = javaparser.parse(new bytearrayinputstream(java.getbytes())); system.out.println(cu.tostring()); }
it uses great java parser library called javaparser
Comments
Post a Comment