Scala Plugin for NetBeans - Rewrite in Scala #6: Refactoring Step Two - Rename

As I've done most code of Refactoring skeleton, it did not cost me too much time to get renaming feature working (2 hours about). Now, NetBeans' Scala plugin can rename class/method/val etc across project's source files.

Following snapshot shows class "Dog" is going to be renamed to "BigDog?". After the preview, press "Do Refactoring", all things done.

ScalaEditor-090903.png

  • Posted: 2009-09-02 09:00 (Updated: 2009-12-30 03:31)
  • Author: dcaoyuan
  • Categories: NetBeans

Comments

1. Andrew -- 2009-09-02 09:00

Caoyuan,

On just selecting an item in a tree (left part of refactoring preview) have got:

java.lang.NegativeArraySizeException?

at org.netbeans.modules.csl.spi.support.ModificationResult?.commit(ModificationResult?.java:193) at org.netbeans.modules.csl.spi.support.ModificationResult?.getResultingSource(ModificationResult?.java:342) at org.netbeans.modules.scala.editor.refactoring.DiffElement?.getNewFileContent(DiffElement?.scala:104) at org.netbeans.modules.refactoring.spi.AccessorImpl?.getNewFileContent(AccessorImpl?.java:73) at org.netbeans.modules.refactoring.spi.impl.PreviewManager?.refresh(PreviewManager?.java:121) at org.netbeans.modules.refactoring.spi.SimpleRefactoringElementImplementation?.showPreview(SimpleRefactoringElementImplementation?.java:119) at org.netbeans.modules.refactoring.spi.impl.CheckNodeListener?.openDiff(CheckNodeListener?.java:272) at org.netbeans.modules.refactoring.spi.impl.CheckNodeListener?.mouseClicked(CheckNodeListener?.java:163) at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:253) at java.awt.Component.processMouseEvent(Component.java:6266) at javax.swing.JComponent.processMouseEvent(JComponent.java:3267) at java.awt.Component.processEvent(Component.java:6028) at java.awt.Container.processEvent(Container.java:2041) at java.awt.Component.dispatchEventImpl(Component.java:4630) at java.awt.Container.dispatchEventImpl(Container.java:2099) at java.awt.Component.dispatchEvent(Component.java:4460) at java.awt.LightweightDispatcher?.retargetMouseEvent(Container.java:4574) at java.awt.LightweightDispatcher?.processMouseEvent(Container.java:4247) at java.awt.LightweightDispatcher?.dispatchEvent(Container.java:4168) at java.awt.Container.dispatchEventImpl(Container.java:2085) at java.awt.Window.dispatchEventImpl(Window.java:2475) at java.awt.Component.dispatchEvent(Component.java:4460)

[catch] at java.awt.EventQueue?.dispatchEvent(EventQueue?.java:599)

at org.netbeans.core.TimableEventQueue?.dispatchEvent(TimableEventQueue?.java:117) at java.awt.EventDispatchThread?.pumpOneEventForFilters(EventDispatchThread?.java:269) at java.awt.EventDispatchThread?.pumpEventsForFilter(EventDispatchThread?.java:184) at java.awt.EventDispatchThread?.pumpEventsForHierarchy(EventDispatchThread?.java:174) at java.awt.EventDispatchThread?.pumpEvents(EventDispatchThread?.java:169) at java.awt.EventDispatchThread?.pumpEvents(EventDispatchThread?.java:161) at java.awt.EventDispatchThread?.run(EventDispatchThread?.java:122)

BTW, are you going to expand both 'where used' and 'rename' to all dependent (wrt currently edited) projects?

2. Andrew -- 2009-09-02 09:00

Caoyuan,

On just selecting an item in a tree (left part of refactoring preview) have got:

java.lang.NegativeArraySizeException?

at org.netbeans.modules.csl.spi.support.ModificationResult?.commit(ModificationResult?.java:193) at org.netbeans.modules.csl.spi.support.ModificationResult?.getResultingSource(ModificationResult?.java:342) at org.netbeans.modules.scala.editor.refactoring.DiffElement?.getNewFileContent(DiffElement?.scala:104) at org.netbeans.modules.refactoring.spi.AccessorImpl?.getNewFileContent(AccessorImpl?.java:73) at org.netbeans.modules.refactoring.spi.impl.PreviewManager?.refresh(PreviewManager?.java:121) at org.netbeans.modules.refactoring.spi.SimpleRefactoringElementImplementation?.showPreview(SimpleRefactoringElementImplementation?.java:119) at org.netbeans.modules.refactoring.spi.impl.CheckNodeListener?.openDiff(CheckNodeListener?.java:272) at org.netbeans.modules.refactoring.spi.impl.CheckNodeListener?.mouseClicked(CheckNodeListener?.java:163) at ...

BTW, are you going to expand both 'where used' and 'rename' to all dependent (wrt currently edited) projects?

3. Andrew -- 2009-09-02 09:00

Caoyuan,

On just selecting an item in a tree (left part of refactoring preview) have got:

java.lang.NegativeArraySizeException?

at org.netbeans.modules.csl.spi.support.ModificationResult?.commit(ModificationResult?.java:193) at org.netbeans.modules.csl.spi.support.ModificationResult?.getResultingSource(ModificationResult?.java:342) at org.netbeans.modules.scala.editor.refactoring.DiffElement?.getNewFileContent(DiffElement?.scala:104) at org.netbeans.modules.refactoring.spi.AccessorImpl?.getNewFileContent(AccessorImpl?.java:73)...

BTW, are you going to expand both 'where used' and 'rename' to all dependent (wrt currently edited) projects?

4. ogrisel -- 2009-09-02 09:00

Thank you very much for your work on the scala nb plugin. I am updating it every day to track you progress.

The only real thing that I miss right now is the ability to profile a scala program using the netbeans built-in profiler: when I dynamically attach a profiler in CPU mode to a running scala program (using the maven exec integration in netbeans). However while the memory monitoring work, I can only see java method calls and not a single scala method call.

I have just created a new issue to track this on netbeans.org: <a href=" http://www.netbeans.org/issues/show_bug.cgi?id=171388>[171388]</a>

5. Caoyuan -- 2009-09-02 09:00

@Andrew, have you tried to clean and build all scala related plugins? I changed a trait in scala.editor, which makes a need to re-compile, build all related classes even not in same project.

I do have plan to support refactoring across all opened projects.

@ogrisel, for profiler, I use it to track potential memory leak of scala plugin itself one week ago. It's not a easy work to map all JVM instance/variable names to scala one. I mean "not easy" that it needs lots code typing.

6. Andrew -- 2009-09-02 09:00

Caoyuan,

Yes, I have: every time I build the plugin, I use

ant scala-clean scala-nbm

Then I remove

modules update update_tracking

dirs from user dir, start NB (ignoring exception), redownload all nbms from scala.kit/build, install them and restart the IDE.

Probably there is shorter way :-)

Have I missed something?

As for exception - it arises on few tree items only, not on all ones.

I hope, I have rev 15617 - it was 2 hour ago, and I don't see any new changes in /contrib since last plugin build.

7. Steve Thompson -- 2009-09-02 09:00

First I wanted to say thanks for all your hard work. It has been a pleasure to watch your plug-in gain so many features in such a short time. As a fellow developer, I salute you!

8. Stuart Roebuck -- 2009-09-03 09:00

I'm trying to get the plugin up and running with a simple example out of the box Lift project.

My first problem was that although I set SCALA_HOME, I didn't launch my NetBeans from the command line, so NetBeans wasn't picking this up. That's solved.

However, I'm getting the following error displayed in the editor: <pre>net.liftweb.mapper.MetaMegaProtoUser? does not take type parameters</pre> which isn't a genuine error. The project compiles quite successfully under Maven within NetBeans.

Any thoughts?

P.S. Many thanks for this great Plugin.

9. Steve Thompson -- 2009-09-03 09:00

FYI - Just noticed that in the latest version of the ScalaKit/Editor?, the ANT property for the Scala Sources had changed from src.dir to src.scala.dir. I had to change the cleanup section in build-impl.xml to get things working again.

10. Andrew -- 2009-09-03 09:00

It seems, I also see more spread error messages against correct code now. Up to date Scala and plugin are in use.

11. Caoyuan -- 2009-09-03 09:00

@Stuart, for the liftweb code, did you has all relative dependent jars built upon Scala-2.8.0? I have not tried to explore liftweb yet, so I have no idea why this happened, it will be great if you can find the cause.

@everybody, if editor shows odd error messages, you can try to reset compiler by right-click in editor window, choose "Reset Scala Compiler" in popup menu.

12. Andrew -- 2009-09-03 09:00

Caoyuan,

"Reset Scala Compiler" has not visible effect at all few cases I have tried.

13. Caoyuan -- 2009-09-04 09:00

@Andrew, which version of 2.8.0 snapshot are you using? maybe I need to upgrade the one that NetBeans's plugin uses itself.

14. Andrew -- 2009-09-04 09:00

Caoyuan, it's 2.8.0.r18644. Of course, I don't run all my test with every trunk revision, but, at least, all my projects compilable.

15. Stuart Roebuck -- 2009-09-04 09:00

@Caoyuan, I downloaded the latest liftweb sources and used these compiled with Scala 2.8. This resulted in a consistency between the errors in NetBeans and compiling through Maven. Now I just need to figure out what's changed and why! :-)

Cheers.

16. Sakuraba -- 2009-09-07 09:00

Thank you for your hard work on this. It is greatly appreciated.