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 222820 - Add fixable hint which renames the current file to match the classname
Summary: Add fixable hint which renames the current file to match the classname
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 7.3
Hardware: PC Windows 7
: P3 normal (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-11-27 13:11 UTC by markiewb
Modified: 2016-01-10 19:45 UTC (History)
0 users

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments
Shows the current error (50.31 KB, image/png)
2012-11-27 13:12 UTC, markiewb
Details
Proposed patch v1 (19.06 KB, patch)
2013-04-22 22:00 UTC, markiewb
Details | Diff
Shows the patch in action (10.54 KB, image/png)
2013-04-22 22:05 UTC, markiewb
Details

Note You need to log in before you can comment on or make changes to this bug.
Description markiewb 2012-11-27 13:11:49 UTC
[ BUILD # : 201211260002 ]
[ JDK VERSION : 1.7.0_09 ]

Missing fixable hint which renames the current file to match the class name

Steps:
* you have a public java class named "Foo" within file "Foo.java"
* now you change the class name to "Bar" within the editor (file name is still
Foo.java) --> the error "class Bar is public, should be declared in a file
named Bar.java" is shown 

ACTUAL: no fixable hint
EXPECTED: fixable hint "Rename file to Bar.java"

See screenshot for current behaviour
Comment 1 markiewb 2012-11-27 13:12:20 UTC
Created attachment 128455 [details]
Shows the current error
Comment 2 markiewb 2013-04-22 22:00:08 UTC
Created attachment 133682 [details]
Proposed patch v1

@Jan: I like to propose the following patch to solve this RFE. Please review! 

The patch introduces two fixable hints (Rename type to ..., Rename file to ...) See the unit test for 'living' examples.

There is one problem I couldn't solve by myself: A modified, but non-saved document has to be saved before applying the fixes. Else there'll be exceptions. But I didn't find out how to. See the TODO markers in the source code. Can you help out?
Comment 3 markiewb 2013-04-22 22:05:06 UTC
Created attachment 133683 [details]
Shows the patch in action
Comment 4 Jan Lahoda 2013-04-23 15:30:36 UTC
(In reply to comment #2)
> Created attachment 133682 [details]
> Proposed patch v1
> 
> @Jan: I like to propose the following patch to solve this RFE. Please review! 

Actually, I added the change filename fix almost three weeks ago:
http://hg.netbeans.org/jet-main/rev/aca3b1c24bb8

No idea why the automatic note was not added to the report - probably some glitch during the infrastructure conversion (or a mistake in the changeset message, although I don't see any).

> 
> The patch introduces two fixable hints (Rename type to ..., Rename file to ...)
> See the unit test for 'living' examples.
> 
> There is one problem I couldn't solve by myself: A modified, but non-saved
> document has to be saved before applying the fixes. Else there'll be
> exceptions. But I didn't find out how to. See the TODO markers in the source
> code. Can you help out?

Regarding renaming/moving the file, this cannot really be done using FileObjects, DataObjects need to be used (see the patch above).

Regarding changing the class' name, I did not see the exceptions, so I have no idea about their possible cause. However, I tend to believe the rename refactoring should be brought up (so that if there is another class that uses the broken one, the usage is renamed alongside with the broken class). But I was not able to make this work with reasonable effort, IIRC.

In any case, please don't parse the diagnostic messages unless absolutely necessary (which it's not in this case - using the information from the file&tree is actually easier in this case, IMO).
Comment 5 markiewb 2013-04-23 21:24:41 UTC
(In reply to comment #4)
> Actually, I added the change filename fix almost three weeks ago:
> http://hg.netbeans.org/jet-main/rev/aca3b1c24bb8
> 
> No idea why the automatic note was not added to the report - probably some
> glitch during the infrastructure conversion (or a mistake in the changeset
> message, although I don't see any).

Oh, I see. The issue was still open and I don't fetch the repo very often, because the hints can be developed in isolation. It's OK.

I guess it isn't synced because this issue isn't marked as closed/fixed. Do you like to close it?

> 
> Regarding renaming/moving the file, this cannot really be done using
> FileObjects, DataObjects need to be used (see the patch above).
> 
Good to know for the future.

> However, I tend to believe the rename
> refactoring should be brought up (so that if there is another class that uses
> the broken one, the usage is renamed alongside with the broken class). But I
> was not able to make this work with reasonable effort, IIRC.
Yes that would be the best solution, but I also had no time and concentration to look at this. Let's keep this for a future RFE, if someone will ever report such an issue.

> In any case, please don't parse the diagnostic messages unless absolutely
> necessary (which it's not in this case - using the information from the
> file&tree is actually easier in this case, IMO).

I will keep this in my mind too. I'm glad to have you as a reviewer to learn the best practices. Thanks. Benno
Comment 6 markiewb 2016-01-10 19:45:35 UTC
(In reply to Jan Lahoda from comment #4)
> Actually, I added the change filename fix almost three weeks ago:
> http://hg.netbeans.org/jet-main/rev/aca3b1c24bb8

So resolving as fixed