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 269707

Summary: Anonymous class and complex string syntax causes misformatting of entire file
Product: php Reporter: WebSmithery
Component: Formatting & IndentationAssignee: junichi11
Status: RESOLVED FIXED    
Severity: normal CC: junichi11, tmysik
Priority: P2    
Version: 8.2   
Hardware: All   
OS: All   
Issue Type: DEFECT Exception Reporter:
Attachments: An example original file prior to formatting
The test file after formatting; indents are no more!

Description WebSmithery 2017-02-01 12:28:33 UTC
Created attachment 163534 [details]
An example original file prior to formatting

If there is a method which includes an anonymous class and somewhere in another method in the same file the curly bracket complex string syntax is used, then the NetBeans format command sometimes misformats the entire file, in the most extreme case removing all indents and aligning every line to the left margin.

If the complex string syntax is not used e.g. by moving the method in curly brackets outside the double quotes and concatenating then the problem does not occur, so it would seem that NetBeans is getting confused by the different functions and uses of curly brackets.
Comment 1 WebSmithery 2017-02-01 12:30:42 UTC
Created attachment 163535 [details]
The test file after formatting; indents are no more!
Comment 2 Tomas Mysik 2017-03-24 14:33:01 UTC
Reproducible.

@junichi11: Junichi, please, would you be interested in this issue? I was able to find the cause [1]; please note that the file is even incorrectly colored (and basically no editor feature works). If you remove [1] from the source, coloring and formatting is OK.

Thanks.
[1] {$person->getName()}

Product Version: NetBeans IDE Dev (Build 20170324-9934c9984ca5)
Java: 1.8.0_121; Java HotSpot(TM) 64-Bit Server VM 25.121-b13
Runtime: Java(TM) SE Runtime Environment 1.8.0_121-b13
System: Linux version 4.8.0-42-generic running on amd64; UTF-8; cs_CZ (nb)
Comment 3 junichi11 2017-03-26 00:35:04 UTC
(In reply to Tomas Mysik from comment #2)
> Reproducible.
> 
> @junichi11: Junichi, please, would you be interested in this issue?

I'll look at it. Thanks for reporting!
Comment 4 Tomas Mysik 2017-03-27 12:01:50 UTC
(In reply to junichi11 from comment #3)
> I'll look at it.

Thanks a lot, Junichi!
Comment 5 junichi11 2017-03-30 11:17:09 UTC
Fixed. The cause was not the formatter but the lexer. (The bracket for "{$" was not counted.)

http://hg.netbeans.org/web-main/rev/5ea1abc19d09

Thanks!
Comment 6 Quality Engineering 2017-03-31 01:50:14 UTC
Integrated into 'main-silver', will be available in build *201703310002* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/5ea1abc19d09
User: Junichi Yamamoto <junichi11@netbeans.org>
Log: #269707 - Anonymous class and complex string syntax causes misformatting of entire file
Comment 7 Tomas Mysik 2017-03-31 04:41:18 UTC
Perfect job, Junichi. Thank you!