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 233529

Summary: Fix uses occasionally puts namespace statement after use statements (wrong and undesirable)
Product: php Reporter: icaine
Component: EditorAssignee: Ondrej Brejla <obrejla>
Status: REOPENED ---    
Severity: normal    
Priority: P4    
Version: 7.4   
Hardware: All   
OS: All   
Issue Type: DEFECT Exception Reporter:

Description icaine 2013-07-27 09:03:04 UTC
Fix uses occasionally puts namespace statement after use statements (wrong and undesirable) but unfortunately i cant reproduce it now.. When i run into it again i will try to update this issue..

//E.g.
<?

use NS1\NS2\SomeClass;
use NS2\NS2\SomeClass2;

namespace NS1;

//uses should be here

?>
Comment 1 Ondrej Brejla 2013-07-28 07:36:22 UTC
I can't reproduce it either.
Comment 2 icaine 2013-09-01 09:05:09 UTC
Hello, it occurred again on dev version Build 201308270001 with the option "remove unused uses" set on. It seems to me that the problem occurs when the option is set on because when it was set off i havent met the problem.

Anyway i am not able to reproduce it because when i reverted the code to the state before and used it again this time i didnt happen.
Comment 3 Ondrej Brejla 2013-09-04 08:42:05 UTC
Sorry, but I'm not able to reproduce that... P4 util we have a reproducible test case. Without that I'm not able to do anything.
Comment 4 icaine 2013-09-04 09:51:56 UTC
I understand.. Just wanted to point out that the bug exists in the latest versions too.
Comment 5 icaine 2013-10-15 14:15:37 UTC
step 1: http://i.imgur.com/vMUukEt.png
step 2: http://i.imgur.com/9549umd.png
step 3: http://i.imgur.com/sFa7NQ7.png
step 4: http://i.imgur.com/nlzGUqq.png

Product Version = NetBeans IDE Dev (Build 201310110001)
Operating System = Windows 8 version 6.2 running on x86
Java; VM; Vendor = 1.7.0_25
Runtime = Java HotSpot(TM) Client VM 23.25-b01
Comment 6 Ondrej Brejla 2013-10-15 14:24:47 UTC
Yep, I know where is the problem. The problem is in a place, where is the caret, when Fix Uses is invoked. In this case, it's outside of any class...at the and of a file. In the whitespace. And because PHP parser doesn't handle whitespaces (lexer ignores it), then the "place of invocation" is considered to be a default ns...(literally...it's invoked "nowhere"...from parser point of view the invoking place doesn't exist.)

And unfortunately it can't be simply fixed. There is a workaround for that, never invoke that action at the end of a file. Put the caret somewhere inside it.

Reproducible case:

file1.php
----
<?php

namespace Aaa;

class Foo {}

?>
----

file2.php
----
<?php

namespace Bbb;

class Bar extends Foo {}

^
?>

...and invoke Fix Uses on a ^ caret place.