Uploaded image for project: 'NetBeans'
  1. NetBeans
  2. NETBEANS-97

Improve java source reformatting of try and synchronized blocks with control structures

    XMLWordPrintableJSON

    Details

      Description

      This issue recreates https://netbeans.org/bugzilla/show_bug.cgi?id=269050 Netbeans bug 269050. New bug database, new hope for integration!

      Currently the java source reformatter (java.source.base org.netbeans.modules.java.source.save.Reformatter) does not treat try and synchronized blocks as blocks when it encounters them with control structures. So

      if (foo == bar) try {
         baz();
      } catch (Exception all) {
         log.(....);
      }
      

      is reformatted as :

      if (foo == bar) {
        try {
          baz();
        } catch (Exception all) {
          log.(....);
        }
      }
      

      The additional added basic block layer is not needed as the try is already a block. The same applies for a synchronized block as well.

      if (foo == bar) synchronized(quux) {
         baz();
      }
      

      is currently reformatted as :

      if (foo == bar) {
        synchronized(quux) {
          baz();
        }
      }
      

      In addition to "if/else" this formatting all affects other control structures such as "for", "for-each" and "while".

      Line breaks are preserved so existing source

      if (foo == bar) {
        synchronized(quux) {
          baz();
        }
      }
      

      will be reformatted with line breaks intact--only the braces will be removed

      if (foo == bar) 
        synchronized(quux) {
          baz();
        }
      

        Attachments

          Activity

            People

            • Assignee:
              bondolo mike duigou
              Reporter:
              bondolo mike duigou
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 3h 50m
                3h 50m