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 187734 - Group Assignment Multiline Alignment doesn't work
Summary: Group Assignment Multiline Alignment doesn't work
Status: RESOLVED FIXED
Alias: None
Product: php
Classification: Unclassified
Component: Formatting & Indentation (show other bugs)
Version: 6.x
Hardware: All All
: P2 normal with 11 votes (vote)
Assignee: Petr Pisl
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-06-17 14:03 UTC by arnolem
Modified: 2017-03-24 14:13 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Previous post in ZIP format (723 bytes, application/zip)
2011-12-05 13:45 UTC, Raazy
Details

Note You need to log in before you can comment on or make changes to this bug.
Description arnolem 2010-06-17 14:03:06 UTC
Product Version = NetBeans IDE 6.9 (Build 201006111053)
Operating System = Windows XP version 5.1 running on x86
Java; VM; Vendor = 1.6.0_20
Runtime = Java HotSpot(TM) Client VM 16.3-b01
-----------------------------------------------------------------

Tools > Options > Editor > Formating > 

I Selecting "Language : PHP" and "Category : Alignement"
I check "Assignment" in "Multiline Alignment"

After, when I formating my code, "=" caracter doesn't align

Example :

<?php

$test = 'test1';
$param1 = 'test2';
$longParam = 'test2';

class test
{
    const TEST = 't';
    const LONG_CONST = 't';
}

?>
Comment 1 Petr Pisl 2010-06-18 09:40:47 UTC
Hmm, it looks like there is missing the rule in the formatter. I'm going to fix it.
Comment 2 Petr Pisl 2010-07-27 15:01:53 UTC
I think that, the rule which is now in the formatter should does something different. It should aligned the rest of expression under the '=' char. For example by the default the behavior should be:

$i =
        22 * 5;
$very_long_name =
        22 * 5;

So the expression that is placed on the new line is indented with 8 spaces (continual indentation).

When the option Multiline Alignment Assignment is swith on, then the expression should be indented on the position after = char, so the example should look like:

$i =
     22 * 5;
$very_long_name = 
                  22 * 5;

This doesn't work correctly now and should be fixed.

I think you expect that after formatting your code with Multiline Alignment Assignment option on the result should be:

<?php

$test      = 'test1';
$param1    = 'test2';
$longParam = 'test2';

class test
{
    const TEST       = 't';
    const LONG_CONST = 't';
}

?>

I'm right? But this is not very easy to do. At first, it has to be clear which lines should be affected with this. Like the following code should be:

$x      = 10;
$y      = 20;
$center = poin($x, $y);

$some_rectangle = Rectangle(1,1,2,2);

or 

$x              = 10;
$y              = 20;
$center         = poin($x, $y);

$some_rectangle = Rectangle(1,1,2,2);

So at first we have to define the behavior, which blog of lines will be aligned.
Comment 3 arnolem 2010-07-27 15:49:39 UTC
It's right.

I think the rule should be:

 - Align all signs equal to the first sign of each grouping.
 - A group is defined by a line break or comment.
 - If an equal sign is beyond what is defined for the group, he retains his position

Example :

//group 1
$foo = 10;
$x = 20;
//group 2
$foo2 = 20;
$y = 20;

will be formatted as

//group 1
$foo = 10;
$x   = 20;
//group 2
$foo2 = 20;
$y    = 20;

And

$x        = 10;
$y = 20;
$center = point($x, $y);
$some_rectangle = Rectangle(1,1,2,2);

will be formatted as

$x        = 10;
$y        = 20;
$center   = point($x, $y);
$some_rectangle = Rectangle(1,1,2,2);

This is a proposal but the ideal thing would be set based on user needs. Choose to align the first or the largest

Thanks


(In reply to comment #2)
> I think that, the rule which is now in the formatter should does something
> different. It should aligned the rest of expression under the '=' char. For
> example by the default the behavior should be:
> 
> $i =
>         22 * 5;
> $very_long_name =
>         22 * 5;
> 
> So the expression that is placed on the new line is indented with 8 spaces
> (continual indentation).
> 
> When the option Multiline Alignment Assignment is swith on, then the expression
> should be indented on the position after = char, so the example should look
> like:
> 
> $i =
>      22 * 5;
> $very_long_name = 
>                   22 * 5;
> 
> This doesn't work correctly now and should be fixed.
> 
> I think you expect that after formatting your code with Multiline Alignment
> Assignment option on the result should be:
> 
> <?php
> 
> $test      = 'test1';
> $param1    = 'test2';
> $longParam = 'test2';
> 
> class test
> {
>     const TEST       = 't';
>     const LONG_CONST = 't';
> }
> 
> ?>
> 
> I'm right? But this is not very easy to do. At first, it has to be clear which
> lines should be affected with this. Like the following code should be:
> 
> $x      = 10;
> $y      = 20;
> $center = poin($x, $y);
> 
> $some_rectangle = Rectangle(1,1,2,2);
> 
> or 
> 
> $x              = 10;
> $y              = 20;
> $center         = poin($x, $y);
> 
> $some_rectangle = Rectangle(1,1,2,2);
> 
> So at first we have to define the behavior, which blog of lines will be
> aligned.
Comment 4 bwaine 2010-07-28 11:36:45 UTC
Hi,

Our internal coding standards:

1) Equals signs should be alinged across multiple lines within groupings.
   - Groupings defined by line breaks
   - Alignment is to the longest paramter.

2) Array seperators should be aligned (=>) across multiple lines.
   - Alignment is to the longest paramter.

Hope this helps define a possible use case.

Thanks,

Ben 

Using: Netbeans (PHP v6.9)
Comment 5 Petr Pisl 2011-09-27 09:34:45 UTC
Still I have not had time to do it. :(
Comment 6 semanticeffect 2011-09-30 17:00:44 UTC
Our development agency would benefit hugely from an implementation of bwaine@netbeans.org's suggestion:

1) Equals signs should be alinged across multiple lines within groupings.
   - Groupings defined by line breaks
   - Alignment is to the longest paramter.

2) Array seperators should be aligned (=>) across multiple lines.
   - Alignment is to the longest paramter.


If I could get this one piece implemented then my entire team could begin using the formatter before all checkins, and thusly making everyone's life a bit easier.

Thank you in advance for implementing such a useful feature.
Comment 7 Petr Pisl 2011-11-03 09:43:22 UTC
This bug can not be P1. It doesn't prevent to use the feature.
Comment 8 Petr Pisl 2011-11-04 09:55:19 UTC
I have added new "Group Mulitline Alignment" group of options. There are two options: Assignment and Array Initializer. The Assignment switches on/off the group alignment for assignments, fields inisializers, constant declarations. 

The group of line is limited to a block and empty lines as suggested. 

By default these options are switch off, so you have to switch on in the options.

Please test it, whether it works ok. Thanks.

The change
http://hg.netbeans.org/web-main/rev/9023a454e522
Comment 9 Quality Engineering 2011-11-05 02:59:44 UTC
Integrated into 'main-golden'
Changeset: http://hg.netbeans.org/main-golden/rev/9023a454e522
User: Petr Pisl <ppisl@netbeans.org>
Log: #187734 - Group Assignment Multiline Alignment doesn't work
Comment 10 roti 2011-11-14 21:30:53 UTC
can we also have it for java code formatting?
Comment 11 Ondrej Brejla 2011-11-15 08:59:30 UTC
You have to ask "Java" component.
Comment 12 Raazy 2011-12-05 13:41:48 UTC
Product Version: NetBeans IDE Dev (Build 2011-12-04_18-04-28 )
Java: 1.6.0_29; Java HotSpot(TM) Client VM 20.4-b02
System: Windows 7 version 6.1 running on x86; Cp1250; cs_CZ (nb)


This is something what I am getting after code format:

ORIGINAL:
class Foo {

	public function getStylesheets() {
		$e = "\n";
		$t = "\t";
		$cond = null;
		$styleSheetsHTML = $e;
		for($i = 0; $i < sizeof($this->stylesheets); $i++) {
			//
		}
	}

}

FORMATTED:
class Foo {

	public function getStylesheets() {
		$e			   = "\n";
		$t			   = "\t";
		$cond			= null;
		$styleSheetsHTML = $e;
		for($i			   = 0; $i < sizeof($this->stylesheets); $i++) {
			//
		}
	}

}



Is does not seems correctly formatted and I am seeing big problem about formatting inside FOR parenthesis.
This should be left intact by Group Multiline Alignment.
Hoewer, it can be "solved" by leaving empty line above FOR, but i think this is should be formatted by Category->Spaces->Around Operators aftewards.
I have option Category->Spaces->Around Operators->Assignment Operator set to TRUE.
So I think, that Group Multiline Alignment should not be applied as the last formatter.
Comment 13 Raazy 2011-12-05 13:45:45 UTC
Created attachment 113821 [details]
Previous post in ZIP format

Sorry, here is an attachment with above post, because is wrong represented by these web pages.
Comment 14 Petr Pisl 2011-12-05 15:52:51 UTC
@Raazy: it's a bug, it would be better to open new issues and keep this closed. It should be easy to fix.
Comment 15 Marian Mirilovic 2012-02-23 08:56:32 UTC
10 votes ... P2
Comment 16 Petr Pisl 2012-02-23 09:27:56 UTC
The votes were there to implement this feature. As I wrote this issue should be closed (the feature is implemented) and the cases, where it doesn't work properly, there should be new issues.
Comment 17 Ondrej Brejla 2012-03-01 09:16:48 UTC
As Petr wrote, closing this "implemented" issue. New one for a bug is tracked here #209030
Comment 18 jenifferhomes 2012-06-21 11:49:36 UTC
Happens to me reliably immediately after IDE is started. 9 duplicates so far.

http://www.worldphoto.org/profile/RobertPattinson/
http://pinterest.com/googleclone/samsung-galaxy-note-cases/
http://director-ee.com/profile/cyberworldltd
Comment 19 harunaga 2017-03-15 04:55:35 UTC
I have the following code block after formatted:
class A extends B
{

     protected $arr  = ['a'  => 1,
           'aa'   => 2,
           'aaa'  => 3,
           'aaaa' => 4,]

     protected $arr1 = ['a' => [1,
            2,
            3,
            4,],
        'b' => ['b',],];
}

in PHPStorm it will becomes

class A extends B
{

     protected $arr  = ['a'    => 1,
                        'aa'   => 2,
                        'aaa'  => 3,
                        'aaaa' => 4,]

     protected $arr1 = ['a'  => [1,
                                 2,
                                 3,
                                 4,],
                        'ab' => ['b',],];
}

It looks much more smarter.
How to do with Netbeans. I try some search but no luck. Does Netbeans support that ? It would be appreciated.
Comment 20 Tomas Mysik 2017-03-24 14:13:19 UTC
@harunaga: Please, do not reopen fixed issues. Simply report a new one, provide information which NetBeans and JDK version you have, provide exact steps to reproduce and do not forget to attach your IDE log [1] once you reproduce your problem.

Thanks.
[1] http://wiki.netbeans.org/FaqLogMessagesFile