leibnitz27 / cfr

This is the public repository for the CFR Java decompiler
https://www.benf.org/other/cfr
MIT License
1.93k stars 249 forks source link

Patch formatting #293

Closed nbauma109 closed 2 years ago

nbauma109 commented 2 years ago

Format try/catch/finally as follows:

try {

} catch (Exception e) {

} finally {

}

rather than:

try {

}
catch (Exception e) {

}
finally {

}

It's not just for esthetics and conventions, it makes the output more ready for line number realignment. In Enhanced Class Decompiler (ECD) plugin for Eclipse, the output is reworked for line number realignment and it doesn't look nice. This will help produce a nicer output.

Example of the current messy output of ECD:

/*    */          public class Test {
/*    */              public static void main(String[] args) {
/*    */                  try {
/*  5 */                      System.out.println("try");
/*  6 */                      if (args.length == 0) {
/*  7 */                          System.out.println("no args");
/*    */                      } else {
/*  9 */                          System.out.println(args.length + " args");                     }
/* 10 */                      if (args.length == 1) {
/* 11 */                          System.out.println("1 arg");                     }
/* 12 */                      if (args.length == 2) {
/* 13 */                          System.out.println("2 args");
/*    */                      }                 }                 catch (Exception e) {
/* 15 */                      System.out.println("catch ex");
/*    */                  }                 catch (Error e) {
/* 17 */                      System.out.println("catch err");
/*    */                  }                 finally {
/* 19 */                      System.out.println("finally");
/*    */                  }
/*    */              }
/*    */          }

I have thought of doing that directly in ECD, because I have the same issue with Procyon, but as it's also the java standard, I think the decompiler can produce that output directly.

leibnitz27 commented 2 years ago

Was going to go off on a little rant about style guides being subjective, but you win on points because this IS actually in the official sun style guide (which was last published in 1999 ;) ) https://www.oracle.com/java/technologies/javase/codeconventions-contents.html