Monday Dec 11, 2006

Another NetBeans+Ruby Preview

There have been several great releases lately, and I'm remiss in covering them. However, they've been covered in great detail elsewhere. First, NetBeans Visual Web Pack shipped on schedule, bringing Creator functionality to NetBeans, along with new support for Java EE 5. Second, Mustan... \^H\^H\^H\^H Java SE 6 shipped today. It's a great release. The number one reason I install it whenever I get to a new system is that I need the improved font aliasing built into Java2D - and of course, the gray-rect-fix. However, there's another reason I crave the release even when I'm on OSX: @Override. Yes, @Override has been there since Java SE 5, but in Mus... Java SE 6, you can use it to indicate that a method should implement an interface method, not only a method inherited from a super class. (Which arguably @Override should have meant all along.) Now if only Apple could ship an update to its dated September pre-release...

Anyway, I have an excuse for being late to blog. In addition to some work on JSR 273 which is coming along nicely, I've been coding away to get more Ruby tools support for NetBeans. Charles and Tom will be demoing JRuby 0.9.2 (which just shipped, congratulations!) at JavaPolis this week, and showing the NetBeans tooling in the process.

I thought I would share another screenshot with you at this point. This shows the new language embedding. Notice how there's Ruby inside string literals, rdoc tags inside comments, string escape codes highlighted specially, and so on.

This is all made possible by the new Lexer API in NetBeans. It's really nice to build on top of it; writing incremental lexers is a snap. This is part of NetBeans 6. If you've been using recent milestones, you might have noticed that all our javadoc is highlighted in your Java files. This is not done through hacks in the Java lexer - it's done through embedded sections where the Java comment tokens are then sub-tokenized by a Javadoc lexer. It's not just done for javadoc - if you look at your String literals you'll notice the same String-sequence highlighting that I'm showing for Ruby above. It only changes the font to bold, so it's a bit subtle. Perhaps something we should tweak before the release.

In Charles' pre-review of the Ruby support, he wrote some very nice things about me ("Tor Norbye is a programming machine", etc.) Thanks Charles! While it's nice to get all the credit, I really want to point out that this is all made possible because of the tremendous work on the editing infrastructure for NetBeans 6, by a number of great NetBeans engineers. Not just the Lexer, which I've described above, but all the other things I've relied on, such as the infrastructure for semantic highlighting, asynchronous parser task scheduling, and so on. I would love to give individual credit here, but I'm not sure exactly who to attribute all the work to, so I'd rather credit all of you rather than snub anybody. Not to mention the fact that I have an excellent Ruby AST to work with, thanks to JRuby!

Several of you asked after my last screenshot where or when you can download the code for this. It will show up in NetBeans soon, but since the work started in closed source, I have to follow the established open-sourcing process. It's in progress, but I can't make specific predictions about when it will be done.

Wednesday Nov 29, 2006

NetBeans + Ruby = True

Click on image for full size. Some things to notice: semantic highlighting (for example, parameters are shown in different colors than local variables), code completion, mark occurrences (other uses of the length method under the caret is highlighted), ...

You'll see more at JavaPolis... and on this blog!

Tuesday Sep 26, 2006

NetBeans Plugins I Use, Part 5: Build Monitor

(Parts 1, 2, 3, and 4.)

The Build Monitor plugin for NetBeans allows you to see the status of continuous builds, right from within the IDE. The Build Monitor works with several continuous build systems - CruiseControl, Hudson, and of course the NetBeans continous build. You can monitor multiple build sources - all you do is name your build and point to an RSS feed where the plugin can fetch the build status. Each build is then displayed right in the IDE status bar. You can set the polling frequency yourself; I've set mine to check every minute! Here's what this looks like:

This is obviously what you don't want to see - while the NetBeans continuous build is fine, the second continuous build is currently failing, as indicated by the red ball. In this case, just click on it to open the browser for the corresponding build status page - where you can for example click on the Console Log to see the build script output.

You can grab the Build Monitor plugin from the Beta Update Center, or from nbextras.org.

Yesterday, I set up a continuous build for the project I'm working on. It was really simple. All I had to do was download glassfish, run its setup script, download Hudson, and drop the hudson.war file into the autodeploy directory in Glassfish. Then I just went to localhost:8080/hudson and from there I could set up a build using a simple web interface. I just needed to point to my CVS server (Subversion is supported too) and my ant scripts, and voila - continuous builds. If you want to take a look at what Hudson looks like in action, visit this page where you can see Glassfish itself being built in a Hudson setup.

Tips:

  1. It's a bit tricky to configure the build monitor. The trick is to open the options, then go to the Advanced Options, locate the Build Monitor item, right click on it, choose new build monitor. Then set the RSS feed to the build failure (or all builds) feed you want to use - Hudson displays it right in the status page.
  2. I had to restart the IDE before the build monitors showed up in the Status Line. We should set the needs-restart property of the auto update bundle.
  3. I had problems using the most recent snapshot of Hudson so I grabbed a slightly older version and things were fine.

Thanks to Tom Ball and Jesse Glick for this plugin.

Friday Apr 28, 2006

NetBeans Plugins I Use, part 4: Auto Spell Check

I went to the Update Center and went checking for new features. On the nbextras site I found a new feature I instantly fell in love with.

This is a spell checker which lets you register dictionaries (the English ispell one is bundled), and then your javadoc comments are checked for spelling errors while you're editing, much like the java code is checked for parse errors. Any errors found are underlined - and there's even a quick tip which lets you instantly (Alt-Enter) replace the word with similar words in the dictionary.

After installing this, I opened a couple of files from the JSR 273 project (under development), and it instantly pointed me to several typos I then fixed! Here's one of them:

The plugin is also smart enough to not report typos for names following an @author tag, and so on. And the options panel lets you register additional dictionaries. It's easy to find many free ones for ispell on the web.

Very nice! Thanks Jan Lahoda. Now where's your blog? Actually never mind, don't let anything distract you from writing plugins in your spare time...

Monday Apr 24, 2006

Tabs Are Evil, Part 2: The Remedy

A while ago I argued that you should completely avoid Tab characters in your Java source files. Use spaces for indentation. I won't repeat those arguments here. But even those arguing in favor of tab-indented source files agree that mixing spaces and tabs is evil.

The problem is that sometimes you're not aware that you're working on source with mixed tabs and spaces. This can happen easily if you edit the source files with an editor that has the wrong (as far as you're concerned) handling of Tabs.

To help avoid this you can use a simple NetBeans module I just committed into CVS, under contrib/fixtabs. You can grab the NBM file here and install via Tools | Update Center. I'll submit it to nbextras.org soon so you can get it there later.

Here's what the module looks like in action. If you for example open the JDK JTable class and look at the constructor, you'll see something like this (click for full size):

Ewwww!

When you encounter files like this, you can go to the edit menu and select the action to convert the tabs to spaces. You can also turn off Tab highlighting here.

(Update 4/28/06: I changed this such that the "checkbox" toggle is now in the View menu, along with other view states you can enable and disable, and I moved the Convert action to the Source menu along with other source transformation actions.)

The module is similar to one of my favorite modules (which I guess I haven't described yet) - the "stripwhitespace" module. That module highlights trailing whitespace in the current source file, and lets you remove these. Not only is the fixtabs module similar - it's heavily based on the same source code.

Let me know if you encounter any bugs.

Wednesday Apr 12, 2006

NetBeans plugins I use, part 3: Quick File Chooser

Don't get me wrong: I generally love the OSX user interface. But the one thing I can't stand is the file chooser. On other platforms, you can usually type the path you want to go to, but on the Mac, you have to drill down, with a mouse\*, from one of the "root" directories - e.g. home, Desktop or Documents. Yuck.

If you're a keyboard guy like me, there is a solution: The Quick File Chooser. This plugin registers an alternate file chooser with the IDE, which is then used everywhere a filechooser is used.

The plugin is named the "Quick" file chooser for a good reason. Not only can I type in a path to a place I want to go more quickly than I can drill down to it with a file chooser (especially in directories with lots of files, such that I have to scroll to find the next intermediate folder to click on). But it also has additional shortcuts.

First, I can press the Tab key to force automatic completion. This works the same way as in modern Unix command line shells. If I've typed "P", and the only file in this directory that begins with a "P" is named "Projects", pressing Tab will update the path to "Projects". When there are multiple matches it will expand as far as possible.

Second, I can use environment variables again! Yipee!! I've really missed this feature. I used to do all my navigation with environment variables when I was an avid Emacs user. I had defined important directory locations with environment variables. For example, $D would point to the main debugger source directory; $E the editor, and so on. I could simply hit C-x C-f to open a file, and enter the path as $D/Breakpoint.cc to open the Breakpoint class. With the Quick File Chooser, you can again embed environment variables within the path, and everything is substituted correctly.

Here's a screenshot of the plugin in action. As you can see I've typed in an environment variable to jump to my NetBeans source tree, and I've started typing a path - and all the files are filtered down to the possible matches so far:

Thank you, Jesse and Tim!

If you want to get this module, go get it from nbextras.org/. The instructions for how to connect to it via the NetBeans Update Center are here.


\*: There is an unintuitive way to jump to an arbitrary directory, in some applications, by going to the Search field and starting to type a path. Provided the first character is "/", this will cause a dialog to pop up where you can type the directory. But this is not a decent workaround, because it only works for absolute paths, there's no tab completion etc. And worse yet, many applications (including NetBeans) don't include a Search button next to the directory dropdown.

Friday Mar 24, 2006

A Tale of Two Splashscreens

Earlier this week, somebody got a picture of SWT creator Steve Northover "embracing" NetBeans. This promply made it into the Eclipse splash screen for nightly builds (along with a bugreport...). Here's the splash screen:

Via Roman I just learned that the NetBeans nightly build also has an "unusual" splash screen. Sure enough:

RCS file: /cvs/ide/branding/core/startup/src/org/netbeans/core/startup/splash_nb.gif,v
Working file: ./ide/branding/core/startup/src/org/netbeans/core/startup/splash_nb.gif
head: 1.5
branch:
locks: strict 
access list:
keyword substitution: b
total revisions: 15;    selected revisions: 15
description: 
----------------------------
revision 1.5
date: 2006/03/23 23:37:22;  author: tboudreau;  state: Exp;  lines: +531 -379
A fitting response to
https://bugs.eclipse.org/bugs/show_bug.cgi?id=132773
to be rolled back after the next nightly build :-)

If my eyes don't deceive me, the person on the right is the same Steve Northover, this time playing guitar with NetBeans developer and evangelist Tim Boudreau.

Things are getting very friendly between the two camps. Tim Cramer, head of tools at Sun, appeared at Eclipsecon this week and spoke on the Matisse integration into MyEclipse.

Competition is good for Java developers - and friendly competition is in my opinion even better.

Monday Mar 13, 2006

Refactoring Reloaded!

Jackpot is finally available.... well, as an alpha that is. But hey, I love to live on the bleeding edge - I always run with the latest and greatest bits I can get my hands on.

Here's the announcement, sent only to the NetBeans development mailing list. At this stage, the UI is not ready, but developers can start playing with the concepts and start writing refactoring scripts. Refactoring scripts, what's that you say?

Jackpot really is a new approach to refactoring. Sure, there are builtin refactorings - code transformations that are coded as direct AST manipulation. However, Jackpot also lets you write your own Rule files, using a special but obvious rule language. Rather than describe it here, just go check out the tutorial.

Unfortunately, there are no screenshots in the tutorial. And for any new software, the first thing I look for are screenshots. So, below follows a few screenshots to hopefully whet your appetite. It's exciting to see so many new innovations going into the NetBeans IDE!

Here's the first thing I did. I applied the "Add Override Annotations" transform. This goes and looks for all methods that are currently overriding another, and adds the new JDK 5 @Override annotation to all these methods. I've recently started using this annotation in my code, but I've added them haphazardly, so it's nice to be able to do this in one shot. When you run the transformer, you get a results window with diffs before you apply the change:

As I mentioned, you can write your own rule files too. This is the real big deal about Jackpot. It allows you to write your own, simple source substitutions - with full accuracy on types. The below shows some code cleanup rules. There are many many other rule files too, and more deprecated uses ones should be written.

Here's the current queries menu - queries simply list results, but doesn't actually change the code:

Here's the current transforms menu:

Note that it's very easy to add to these menus. Create your own rule files, open up the Command Manager and add a reference to your rule file (what, did you think "Tor's Test Rules" at the end of the menu above was part of the Jackpot distribution?). It then shows up in the menu and you can run it. Developers can then share these rule files. If you come up with some good rules, PLEASE please share them!

P.S. Remember it's an alpha so don't start complaining if you get exceptions, if the UI isn't Right(tm), etc.

Sunday Jan 29, 2006

Mark Occurrences

Sandip "Plugin" Chitale has published yet another NetBeans module. This one adds a toggle button to the toolbar, which when enabled, causes occurrences to be highlighted in the editor. For example, if you put the caret on a field, all uses of that field in the file are highlighted. As another example, if you place the caret on a method declaration, then all exit points from that method (return statements, throw statements) are highlighted. And so on and so forth. Read the full description with screenshots and take it for a spin. Works like a charm with NetBeans 5.0 RC2.

Here's a sample screenshot from his blog showing what happens if you put the caret on a formal parameter in a method declaration (unfortunately the blinking caret didn't show up in the screenshot but imagine that it's on the highlighted parameter):

Monday Jan 23, 2006

NetBeans Extras

Andrei Badea, Petr Hrebejk, and Trung Duc Tran have set up their own web site, http://www.nbextras.org, which has one primary feature:

  • It's an Auto Update site for additional plugin modules for NetBeans.
Users can contribute modules for NetBeans, and these are then made available on the update center. Here's how you can add the update center to your own NetBeans installation.

The thinking behind this is that NetBeans itself tries to provide a very coherent and clean user interface, with all the different parts working seamlessly together. However, there's a growing number of useful plugins that may not yet be ready for inclusion into the standard distribution. This site tries to make it easy to share these. And of course the site also provides a blog interface so it's easy to track new additions, and discuss plugins you're using with others. I've seen lots of useful plugins, and use several myself (such as this, this, this, and others) that I build from source in the NetBeans source tree's contrib CVS module. Here's to hoping these will all be provided in binary form on the nbextras site soon. (Yeah I know, it's a volunteer effort, perhaps I should upload them myself!)

Go check it out, and contribute in any way you can - with your own plugin modules, or with useful feedback on what's there.

Thursday Dec 01, 2005

Performance profiler - now for the Mac!

Milestone 11 of the NetBeans Performance Profiler was released today. It's mostly a bug fix release, but it sports one big new feature: Support for Apple OSX! This is a big deal. The NetBeans Profiler is based on JFluid, a new approach to performance profiling. Rather than using the standard JVM performance interface, it used a special modification of the VM to do its profiling more accurately. Because of this, you had to download special VMs to run your application - and of course, those modified VMs did not include OSX (where the VM is provided by Apple rather than Sun).

The JFluid hotspot modifications have been integrated into the JDK. As of JDK 5 update 4 (or thereabouts) you can use a standard JDK with the profiler and everything works beautifully. And I guess Apple's recent update to JDK 5 must have synced up to the codebase which includes the JFluid modifications, since the profiler now works.

The "What's New" document describes this feature as experimental - so of course I had to try it! It seemed to work well on my test case. I created a sample project (the Anagram sample that ships with NetBeans), then invoked the Profiler. After calibrating the timers I needed to restart profiling. From there everything went smoothly; I hit the GUI button a bunch of times, then clicked on the Take Snapshot button in the profiling panel. Voila! The result screen pops up letting me drill into both the hotspots and the overall cumulative time view.

Click on the screenshot for full size. And check out the Profiler Screenshots off the profiler main page; as you can see there are various telemetry views and other goodies there.

Very promising. If you're a Mac Java user, be sure to try it out and provide feedback and bug reports to the profiler team such that this feature is stabilized as quickly as possible!


Wednesday Sep 28, 2005

NetBeans 5.0 Beta

NetBeans 5.0 Beta is now out. In my blog entry yesterday I wrote how easy the new plugin support made it to add my own favorite debugging function to the debugger. There's a long list of big improvements over 4.1. Click on the image to go to the "What's New" page and see descriptions with screenshots of the new goodies!


Monday Aug 29, 2005

Copyright Folding

Most source files have copyrights on them. When opening a file you have to scroll past the copyright, and the import statements, before you get to the interesting part - the class javadoc comment. Most IDEs now have a way to have the import section automatically folded. But what about the copyright section? It's often quite large - in Apache source code for example the copyright is 50 lines long - that's more than a full editor page. Code folding to the rescue!

NetBeans has support for user-defined folds. In Creator, we use this to hide the bean getters and setters, since that segment of code is never interesting to a user, but nevertheless should be part of the source file and discoverable and editable by expert users.

You can use this facility yourself to create arbitrary folds around code. One obviously place to do this is around your copyright sections. These are ideally suited because a copyright is a piece of static text which is replicated in each and every source file. Just change your copyright template once, and from now on all new files will have folded copyrights. In the Creator source base we have marker tokens in the copyrights such that we can update the copyright sections in an automated yet safe way.

(Note: In NetBeans 4.2 you can set an option to have the first comment in the document automatically folded. This will also achieve copyright folding if it's the first comment in the document. Of course, you can apply folding to other logical portions in your document too - there's nothing comment-specific about user folds.)

Here's how user-defined folds work: Simply add two Java line comments (//), one to indicate the start of the fold, and one to indicate the end. The comment itself has an XML-like syntax:

  // <editor-fold defaultstate="collapsed" desc="Your Fold Comment">

You can leave out the defaultstate attribute if you don't want the fold to default to a folded state when the file is opened. Obviously the desc field is used to supply a description which is shown when the section is folded. Note that the comment isn't truly in XML format in the sense that you cannot reorder these attributes.

Let's see how this works in practice. Here's one of my source files, using the short copyright version. Most other file licenses I've seen have a much larger copyright than this, so the folding payoff is higher.

First I simply add the begin and end folding comments as described above around the code I want folded.

Now, when I open the file (or collapse the file by clicking on the - in the margin), the copyright takes up just a single line, and the fold description is displayed instead:

Finally, note that you don't have to expand a fold to see what's inside - simply hover the mouse over the folding box and the contents are displayed as shown here:

About

Tor Norbye

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today