Scala on NetBeans Modules on Update Center Now
>>> Updated Feb 2, 2008:
There is an issue in auto-generated Scala project's ant build-impl.xml file, which get the scala.home property wrongly set. I just fixed it, please wait the new Scala Project module to be available on Update Center, which version should be 1.2.1.
======
I've added Scala modules to nightly build cluster, so, you can get/update these modules via NetBeans plugins update center from today.
Since these modules are experimental, I recommend you to download a nightly build version NetBeans before get these modules, you can get the latest nightly build NetBeans from: http://bits.netbeans.org/download/trunk/nightly/latest/
To get the Scala modules, open menu: [Tools]->[Plugins]</b>, check [Setting] to ensure "Last Development Build" is in the list of Update Centers, which with Url:
Then in the [Available Plugins] tab, you can find the "Scala" category, which currently contains 3 modules: Scala Console, Scala Editing, Scala Project (you may need to click [Reload Category]). Select them and click [Install]
Notes:
- Don't forget to set your <b>SCALA_HOME</b> environment first, and append -J-Dscala.home=scalahomepath (for Windows users, try to append -J-Dscala.home=%SCALA_HOME%) to the end of "netbeans_default_options" in your netbeans.conf file, where, scalahomepath is your Scala home's absolute path. For example: /Users/dcaoyuan/apps/scala/share/scala/ (which contains sub-directory: bin, lib etc). netbeans.conf is located at "pathToNetBeansInstallationDirectory/etc", in Mac OSX, it could be:
- /Applications/NetBeans/NetBeans\ 6.0.app/Contents/Resources/NetBeans/etc, or ~/SomePath/netbeans/etc
- The Scala Project supporting has been rewritten, so if you have Scala projects created by previous Scala plugin, you should recreate new Scala project, and copy source files to this new created project's src directory.
- Debugger module is not released yet.
Scala for NetBeans Screenshot#7: Working on Debug II
So, I've found the cause of that can't add breakpoints on context of object. By setting the enclosing class name of object as object's name + "$", I can now add breakpoints upon object.
To reach here, I have to write an EditorContextImpl? for Scala, which will get all compilation information from Scala semantic analyzer. But, to get all debugging features working, I have still to process a bit more conditions. After that, I'll release these modules for public trying.
Click on the picture to enlarge it
Scala for NetBeans Screenshot#6: Working on Debug
=== Updated Jan 30, 08: ==>
The cause of adding breakpoints to object context is relative to complilationInfo's CompilationUnit in java.source module, that the ComplilationInfo is set by JavaSource#moveToPhase after call Iterable extends CompilationUnitTree> trees = currentInfo.getJavacTask().parse(new JavaFileObject[] {currentInfo.jfo}), thus the returning CompilationUnitTree is generated by sun's java parser tool, it of course can not be parsed properly with "object" keyword.
To resolve it, I have to rewrite a scala.debug.projects module, which will be derived from debugger.jpda.projects module
===
=== Updated Jan 26, 08: ==>
Yes, I've got a better Scala project support, not only debug works on pure Scala or Scala+Java project, but also got an UI for defining Main class of the application. Actually, Scala project support is now almost same as J2SE project on NetBeans. The only problem is, if you add a breakpoint on statements of a Scala object, since the org.netbeans.api.java.source.TreeUtilities#scopeFor will return a scope of "COMPILATION_UNIT", which will return null when is called by scope.getEnclosingClass() in org.netbeans.modules.debugger.jpda.projects.EditorContextImpl#getClassName, so the breakpoint will be invalid. To get this fixed, EditorContextImpl needs to be patched.
According to Scala FAQ, Scala object gets compiled to 2 classes, for example:
object HelloObj { val f = "one field" val x = 3 }
We will get:
public final class HelloObj extends java.lang.Object{ public static final int $tag(); public static final int x(); public static final java.lang.String f(); } public final class HelloObj$ extends java.lang.Object implements scala.ScalaObject{ public static final HelloObj$ MODULE$; public static {}; public HelloObj$(); public int x(); public java.lang.String f(); public int $tag(); }
Writing “HelloObj.x()” in Scala is the same as writing “HelloObj$.MODULE$.x()”, but the former should probably be preferred for readability.
The problem here is, when you add breakpoint at val x = 3 in the source file, what will be the breakpoint's scope in these two compiled classes (which one?), why scope.getClassName() will return null? anyone know what's the magic here?
===
I'm working on debug feature for Scala on NetBeans. I copied a smallest set of classes from Java Debugger module, and hacked something to make debug working on a mixed project (a Java project with Scala source files). By default, NetBeans IDE will step through Scala source files that are called (see Greetjan's article: Stepping through Groovy in NetBeans IDE ), but you can't add breakpoints directly on Scala source file. So the first thing that I should work on is let the user can add/remove breakpoints in Scala Editor, and get NetBeans' debugger stopping at these breakpoints. After a full day hacking, I got this working.
To got mouse click on adding/removing breakpoints working, you can implement and register a MIMEType related "GlyphGutterActions" in layer.xml, so, org.netbeans.modules.editor.impl.GlyphGutterActionsProvider#getGlyphGutterActions(String mimeType) can lookup this action. GlyphGutterActionsProvider#getGlyphGutterActions will be invoked by org.netbeans.editor.GlyphGutter#GutterMouseListener#mouseClicked, that's it.
The screenshot shows a mixed Java/Scala project, the example code was copied from Fred Janon's blog, it's a pretty simple example. I added a breakpoint on Dog.scala's val sound="Woof woof!" and another breakpoint at function talk()'s println(hi + sound), then invoke debug, the execution stopped at these two breakpoints as I expected, and you can see the context, for example, the values of variable "sound" and "hi" on debugging windows (at the bottom)
Of course, you can step into, step to cursor line too.
I need to get the debug feature working on a pure Scala project, I have not tried yet, but it seems I need to get the Scala project module better before that.
Click on the picture to enlarge it
On Travel
I'm in Vancouver Airport right now, using the new free Wi-Fi service here. After four-day trip to San Francisco, I'll fly to China for the traditional Spring Festival.
I met friends in San Francisco, we are developing something using Erlang as I mentioned before. What we' are building is somehow a "switch" for content, we've successfully got a lot of different content sources to be "switched" to standard Atom/Rss etc, with a new designed template language (based in Erlang). Actually It's a pleasure to write these switching code in Erlang (Parse, Map, Mashup) with the pattern match syntax and xmerl lib.
Scala Supporting for NetBeans Updated#2 - 20080112
Warning:
Scala for NetBeans is still under development. All these releases are experimental, they may be unstable yet.
Change Log:
- Can be installed on NetBeans 6.0
- Fixed some syntax broken
- Various bugs fixes
- Syntax checking, highlighting, code folding, navigator, basic indent
- Basic completion, In-place refactoring, occurrences marks
- Interactive Scala shell. [Windows] -> [Interactive Scala Shell]
- Basic Scala project management with file locator for compile Errors
- Requires NetBeans 6.0 or newest NetBeans Nightly build (get from: http://bits.netbeans.org/download/trunk/nightly/latest/)
- Don't forget to set your SCALA_HOME environment first, or append "-J-Dscala.home=scalahomepath" to the end of "netbeans_default_options" in your netbeans.conf file, where, "scalahomepath" is your Scala home's absolute path. For example: /Users/dcaoyuan/apps/scala/share/scala/ (For Windows users, it's better to set both of them).
The netbeans.conf is located at "pathToNetBeansInstallationDirectory/etc", in Mac OSX, it could be:
/Applications/NetBeans/NetBeans\ 6.0.app/Contents/Resources/NetBeans/etc
Known Issues:
- Do not write old-style ForComprehension "for (val i <- ...)", instead, use "for(i <- ...)". Please see Scala Spec 2.6.0+
- Do not put infix/postfix operator at the beginning of new line even in a parenthesis expression
- When "<" is an operator, put a space after "<" to identify it from a xml element
Download:
- http://sourceforge.net/project/showfiles.php?group_id=192439&package_id=256544
Installation:
- Upzip to some where, there will be several *.nbm files
- Run NetBeans, install these *.nbm files via [Tools] -> [Plugins] -> "Downloaded"
Scala Supporting for NetBeans Updated#1 - 20080110
Features:
- Syntax checking, highlighting, code folding, navigator, basic indent
- Basic completion, In-place refactoring, occurrences marks
- Interactive Scala shell. [Windows] -> [Interactive Scala Shell]
- Basic Scala project management with file locator for compile Errors
- Requires newest NetBeans Nightly build (get from: http://bits.netbeans.org/download/trunk/nightly/latest/)
- Don't forget to set your SCALA_HOME environment first, or append "-J-Dscala.home=scalahomepath" to the end of "netbeans_default_options" in your netbeans.conf file, where, "scalahomepath" is your Scala home's absolute path. For example: /Users/dcaoyuan/apps/scala/share/scala/
The netbeans.conf is located at "pathToNetBeansInstallationDirectory/etc", in Mac OSX, it could be:
/Applications/NetBeans/NetBeans\ 6.0.app/Contents/Resources/NetBeans/etc
Known Issues:
- Do not write old-style ForComprehension "for (val i <- ...)", instead, use "for(i <- ...)". Please see Scala Spec 2.6.0+
- Do not put infix/postfix operator at the beginning of new line even in a parenthesis expression
- When "<" is an operator, put a space after "<" to identify it from a xml element
Download:
- http://sourceforge.net/project/showfiles.php?group_id=192439&package_id=256544
Installation:
- Upzip to some where, there will be several *.nbm files
- Run NetBeans, install these *.nbm files via [Tools] -> [Plugins] -> "Downloaded"
Scala for NetBeans Screenshot#5: In-Place Refactoring
I've got Scala's semantic analysis more tightly integrated into NetBeans' Schliemann module. The first benefit is In-Place Refactoring (Instant Rename).
On the following screenshots, first, you put caret on a variable name ("scope", for example), the occurrences of this variable will be hi-lighted. Then, press key Ctrl+R, the highlighting color will be changed with meaning of ready for rename.
Just type or modify the name to new one, then press Enter. The occurrences of "scope" will be changed to new name, for example: "scope1".
And, YES, the Erlang for NetBeans will also get this benefit.