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 218144 - Automatically change class names when cut/pasting
Summary: Automatically change class names when cut/pasting
Status: NEW
Alias: None
Product: java
Classification: Unclassified
Component: Source (show other bugs)
Version: 7.3
Hardware: PC Windows 7
: P3 normal (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-09-11 14:33 UTC by kitfox
Modified: 2013-09-02 14:24 UTC (History)
1 user (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description kitfox 2012-09-11 14:33:37 UTC
Suppose you are editing a class named MyClass.  If you copy and paste code that contains a line of the form MyClass.class.getName() and paste it into another file called MyOtherClass, it would be convenient for the paste command to automatically substitute the name of the old class with the new class.  

This happens all the time when I'm copying code that includes a try/catch block from one class to another.  Most of the time I forget to alter the Logger code in the catch clause and this can occasionally cause problems:

        try {
            ...
        } catch (IOException ex)
        {
            Logger.getLogger(MyClass.class.getName()).log(Level.SEVERE, null, ex);
        }
Comment 1 Ralph Ruijs 2012-09-11 19:27:57 UTC
Reassigning to Java Source, as I think the current copy paste feature of fixing imports is similar and located there. Please reassign if needed.

For the RFE, I do not think this is something the majority of users want or should have. This requires knowledge about the intention of the use of Object.class.getName(), as other uses could break when changing the type name. In case of the logger, a pre-configured level of the logger would need to be changed as well.

You could change the logging line to getClass().getName(), but this could give problems as well. I think the best solution is to change the Object.class.getName() to a private constant, resulting in a compiler error when you do not update the target file. Maybe we should create a hint for that?