This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 249716 - Code formatted in very confusing/incorrect way when assigning to field instead of local to override run()
Summary: Code formatted in very confusing/incorrect way when assigning to field instea...
Status: VERIFIED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Editor (show other bugs)
Version: 8.0.1
Hardware: Other Linux
: P2 normal (vote)
Assignee: Dusan Balek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-01-09 13:17 UTC by naquada
Modified: 2015-02-26 10:51 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Editor preferences (675 bytes, application/x-zip-compressed)
2015-02-06 12:53 UTC, naquada
Details
Editor preferences (second attempt) (127.91 KB, application/x-zip-compressed)
2015-02-06 15:04 UTC, naquada
Details

Note You need to log in before you can comment on or make changes to this bug.
Description naquada 2015-01-09 13:17:08 UTC
When instantiating a Thread and overriding run(), if the new Thread is assigned to a local variable, the formatting is fine.  If it is assigned to a field in the class, the formatting treats it as if it is a top-level definition in the file, and not part of the override-at-instantiation.  

Even in the version that is "better", the opening brace is still not placed in a good position.

I have my preferences set for Braces Placement as follows:
  Class: new line
  Method: new line
  Other: same line

When an assignment/initialization of an instance includes definition members of the instance, I would like it formatted as if the first column of the assignment (whether it's a variable or a type) is treated as the "first" column, and the definition of its members formatted the same way as anything that's top level.

To reproduce, use the sample code below and format the editor buffer with margins wide enough so that nothing wraps.


public class NewClass_1
    extends Thread
{
  Thread t;
  String status;

  @Override
  public void run()
  {
    status = "make them all like this, but offset appropriately";
  }

  public void notAsBad()
  {
    Thread t = new Thread()
       {
         @Override
         public void run()
         {
           status = "Realign this so opening brace is under the 'T' in 'Thread'";
         }

    };
  }

  public void veryBad()
  {
    t = new Thread()
{
  @Override
  public void run()
  {
    status =
    "This should be just like the previous, except that opening brace should be under 't' in the assignment";
  }
    };
  }
}
Comment 1 Dusan Balek 2015-02-06 09:21:21 UTC
Not sure what is wrong. The samle code got formatted as follows:

public class NewClass_1
        extends Thread
{

  Thread t;
  String status;

  @Override
  public void run()
  {
    status = "make them all like this, but offset appropriately";
  }

  public void notAsBad()
  {
    Thread t = new Thread()
    {
      @Override
      public void run()
      {
        status = "Realign this so opening brace is under the 'T' in 'Thread'";
      }

    };
  }

  public void veryBad()
  {
    t = new Thread()
    {
      @Override
      public void run()
      {
        status
                = "This should be just like the previous, except that opening brace should be under 't' in the assignment";
      }
    };
  }
}
Comment 2 naquada 2015-02-06 12:53:07 UTC
Created attachment 151858 [details]
Editor preferences
Comment 3 naquada 2015-02-06 12:55:39 UTC
I've attached an export of the editor preferences.  It seems to have something to do with Continuation Indentation Size.  If I set it to 4 (as I have it now), I get the strange formatting.  If I set it to 0, the formatting of the nested/overridden method definitions is much better, but now the "extends", "implements" keywords aren't indented (as you'd expect).
Comment 4 Dusan Balek 2015-02-06 14:54:33 UTC
Don't know what is wrong but the attached file doesn't contain editor preferences.
Comment 5 naquada 2015-02-06 15:04:22 UTC
Created attachment 151863 [details]
Editor preferences (second attempt)

Sorry. Tried the attachment again.  When I unzip this one, it looks to have everything in it.  Don't know what happened the first time.

Also, thank you for taking another look at this.
Comment 6 Dusan Balek 2015-02-06 17:03:22 UTC
Fixed in jet-main.

http://hg.netbeans.org/jet-main/rev/ccc9a04e6d3a
Comment 7 Quality Engineering 2015-02-07 05:41:10 UTC
Integrated into 'main-silver', will be available in build *201502070001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/ccc9a04e6d3a
User: Dusan Balek <dbalek@netbeans.org>
Log: Issue #249716: Code formatted in very confusing/incorrect way when assigning to field instead of local to override run() - fixed.
Comment 8 Marian Mirilovic 2015-02-24 13:48:01 UTC
This is a candidate for NB 8.0.2 Patch 1 , so please integrate the bugfix into releases/release801 branch today by 10pm CET, for more information see 
http://wiki.netbeans.org/NetBeansPatchesProcess
Comment 9 Dusan Balek 2015-02-24 15:56:09 UTC
Integrated into 'release801' branch.
Comment 10 Jiri Prox 2015-02-25 09:06:24 UTC
verified in trunk