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 176453 - [formatting ]wrong formatting of anonymous functions
Summary: [formatting ]wrong formatting of anonymous functions
Status: VERIFIED FIXED
Alias: None
Product: php
Classification: Unclassified
Component: Formatting & Indentation (show other bugs)
Version: 6.x
Hardware: PC Linux
: P1 normal (vote)
Assignee: Tomasz Slota
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-11-10 13:16 UTC by Filip Zamboj
Modified: 2009-11-23 05:09 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Filip Zamboj 2009-11-10 13:16:14 UTC
Product Version: NetBeans IDE Dev (Build 091110-1c3b2021de36)
Java: 1.6.0_16; Java HotSpot(TM) 64-Bit Server VM 14.2-b01

for more info about anonymous functions see http://us2.php.net/manual/en/functions.anonymous.php

code: 
<?php

echo preg_replace_callback('~-([a-z])~', function ($match) {
    return strtoupper($match[1]);
}, 'hello-world');
// outputs helloWorld
?>

results into: 
<?php

echo preg_replace_callback('~-([a-z])~', function ($match) {
    return strtoupper($match[1]);
}
, 'hello-world');
// outputs helloWorld
?>

code 
<?php
$greet = function($name)
{
    printf("Hello %s\r\n", $name);
};

$greet('World');
$greet('PHP');
?>

results into 
<?php
$greet = function($name) {
        printf("Hello %s\r\n", $name);
    }
;

$greet('World');
$greet('PHP');
?>
Comment 1 Tomasz Slota 2009-11-11 05:52:35 UTC
I understand that the problem is about the unwanted breaks between '}' and ','
Comment 2 Filip Zamboj 2009-11-11 05:56:23 UTC
the first example has problem with new line after '}' followed by ','

the second example has problem with new line after '}' followed by ';' as well as with closing bracket that is not formatted correctly. Should be below $greet I guess.
Comment 3 Tomasz Slota 2009-11-19 09:12:40 UTC
Fixed.

http://hg.netbeans.org/web-main/rev/16b27b89909a
Comment 4 Filip Zamboj 2009-11-19 16:23:14 UTC
verified 

Product Version: NetBeans IDE Dev (Build 091119-840bbe3ddcb3)
Java: 1.5.0_17-ea; Java HotSpot(TM) 64-Bit Server VM 1.5.0_17-ea-b01
Comment 5 Quality Engineering 2009-11-20 03:11:06 UTC
Integrated into 'main-golden', will be available in build *200911200201* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main/rev/16b27b89909a
User: Tomasz Slota <tslota@netbeans.org>
Log: #176453 - [formatting ]wrong formatting of anonymous functions
Comment 6 Marek Fukala 2009-11-20 11:11:26 UTC
I've been asked for a code review.

http://hg.netbeans.org/web-main/rev/16b27b89909a

    1.24 +                        if (tokenSequence.token().id() == PHPTokenId.WHITESPACE){
    1.25 +                            tokenSequence.moveNext();
    1.26 +                        }
    1.27 +
    1.28 +                        PHPTokenId id = tokenSequence.token().id();

the code is potentially errorneous - if the condition on 1.24 is true and then tokenSequence.moveNext() returns false, the subsequent code on 1.28 may fail.

I let the decision whether a subsequent fix if necessary or not no Tomasz, but as the fix is now, I CANNOT approve it.
Comment 7 Tomasz Slota 2009-11-23 05:09:07 UTC
I can actually tell that in this case tokenSequence.moveNext() will be always true, but you are right, an explicit check will make the maintenance easier.. I will commit it right away