I generate .java files from a PrintWriter class. These generated files contain many nested for loops. To properly indent everything, I am currently using something like:
for(int j = 0; j < i + 2; j++)
{
    pw.print("    ");
}
pw.println("{");
Just to properly indent the single parentheses.
Obviously, I could just make a method to do this. I'm more wondering if there's a library that 开发者_开发技巧will handle indention and such of outputted code.
I think you might be better off not doing that in your code ( I dont know of any library that formats PrintWriter.out statements ) and instead relying on some formatters after your Java program has completed generating your .java files.
Here's some formatters
http://mindprod.com/jgloss/beautifier.html
Jacobe -- is command-line driven and the personal edition is free.
you can either use javaparser to parse the output generated after parsing will be with standard indentation
With Javaparser printing a source code (with default pretty printer) is as simple as that.
CompilationUnit cu = StaticJavaParser.parse(<path to source file>);
System.ou.println(cu.toString());
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论