Can your IDE do this?

So I’m tapping out a test method in my favorite tool for developing mobile software and it looks like this:

View errorMessage = errorDialog.findViewById(findIdForStringIdentifier(ERROR_MESSAGE_TEXT));
assertTrue("Expecting a TextView field", errorMessage instanceof TextView);

Then I notice… no, scratch that I don’t even notice that auto-complete has sprung into action and is offering me the proper completion at the top of the list, “getText()”. It happens in the most subtle way as my subconscious mind already knows what it wanted to do and it directs my fingers to accept the completion. What I end up with is:

View errorMessage = errorDialog.findViewById(findIdForStringIdentifier(ERROR_MESSAGE_TEXT));
assertTrue("Expecting a TextView field", errorMessage instanceof TextView);
((TextView) errorMessage).getText()

Hi, I’m Cliff. You’re here because your IDE doesn’t do what my IDE does. I’m here because I’m ecstatic over what I’ve learned in the last 10 minutes. Look again at the above code snippets, both before and after and follow what happened in between. The important part is where the 1st line establishes a local variable of type “View”. To my amazement auto complete picked up and inferred it was a type of TextView when I started keying the 3rd line and it offered me not just any random or alphabetized list of suggestions but a preferred suggestion that matched exactly what was being conjured up in my grey matter. (For those unfamiliar with Android programming, a view does NOT include a “getText()” method.) And while I didn’t have to futz with the usual, “oh… I have to either declare my local type as a TextView or add a cast” my IDE does this inference then later performs the cast on my behalf keeping my cursor within the proper context so I can continue adding logic. It happened so “matter of fact” like and so quickly that I didn’t catch on until I had completed typing the line at which point I had to do a double take.

How does it know I need a TextView? Is it because of the preceding assert with the “instanceof” comparison? Does it just naturally assume most views will need to be eventually cast to a “TextView” type because that’s all most Android devs know how to use anyway? Is it reading through the xml layout and determining the type based on the integer id returned from my custom “findIdForStringIdentifier” that is taking a String constant id? Has Jetbrains quietly figured out how to read brainwaves over my Mac’s wifi antenna? I don’t know and I don’t really care!

I had done similar programming in other IDEs (Eclipse, Netbeans, X-Code, Visual Studio) but never have I ever had such an experience where an IDE literally read my mind, did the excessive back-spacing, parenthesis wrapping, casting, and continuation of thought for me. It’s these little nuggets that I keep finding in IntelliJ Idea that keep me addicted. I could go on for days on how wonderful this one… read it… ONE experience, out of hundreds of similar experiences, made my life today but I won’t. I’ve argued the merits of Idea to plenty of developers over the years but until you actually experience how do they put it…? “Development with pleasure” Until you actually live out a few of these scenarios you will continue to grind out code the usual way, hitting refresh/rebuild project to clear the red squiggles that really shouldn’t be there, dealing with arbitrary auto-complete suggestions, not truly being able to refactor code effectively as you could otherwise.

IntelliJ Android Test java.lang.NoClassDefFoundError: junit/textui/ResultPrinter

A short post for those who are wondering if I’m still alive. I got an error trying to run unit tests in an Android project under IntelliJ Idea and I got stumped. After a few minutes of Googling it dawned on me that I had chosen to run the test using a JUnit run configuration instead of an Android run configuration. That is when I right clicked the test method, my mind insisted on chosing the more familiar white window-looking icon with the red and green arrows instead of the Android icon, also with red and green arrows. I was associating the android icon with execute apk and not run tests. I now notice the little chevron-looking arrows and realize they refers to the red, green, refactor life cycle of development.. duh!

Idea OSX And Maven

So I got a custom install of Maven because I’m trying to share configs with other people in my company. And I use multiple machines which all have the custom Maven install in a different path. It’s on a C drive for windows, under a java-apps folder on OSX, and under ~/Programs/JavaApps on Linux. Everytime I open the same project from different machines I have to set the location of Maven’s home folder. so then I accidentally run a Maven goal without setting the home folder one day under the later Idea build and it prompts me to either set the home folder for Maven in the config dialog or set a M2_HOME environment variable. (It never prompted in the earlier 7.x- releases, mind you.) Cool! I set the env var in Windows and Linux and forget completely about Mac because I mostly use XCode there. Tonight I attempted to point my Mac to an ‘.ipr’ on a network drive since my Linux box was cuttin’ up and it hits me again. But wait! How do I set the env var on OSX? (In Windows/Linux IU cheated and edited the ides batch/shell scripts.) I browse the Info.plist in the ‘.app’ bundle to no avail. Then I turn to Google. I found a tip that explains that you can set global env vars in OS X by creating/editing an environment.plist file under ~/.MacOSX. Using classing plist XML speak you describe key/string tags which become the environment variables when you log out and log in again. Here’s what I have in ~/.MacOSX/environment.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "">
<plist version="1.0">

BTW, that tip probably just saved you 32 hours of dev time which, at your salary, is the equivalent of my stuffing over $640 in your shirt pocket… your welcome!

Idea Maven Drama

Ain’t got much time to speak on it but here’s what happening. Just upgraded to Idea 7.0.3… upgrading Idea always feels like Christmas… anyhowz…

Went thru some pain getting my Maven projects hooked up right. This was on my Mac. I have an install of Idea on four or five machines here. The one on my Mac was a little dated since I’ve been doing all this mobile dev which requires Windows. So I had to pull down my projects from Svn and do a little refreshing. Mid way through I ended up deleting and re-adding modules in my project. First surprise was the new “I’ve decided to remove all of your other projects from the Maven structure while adding this new one” dialog. I didn’t know how to respond. The dialog apparently had interest in undoing all of the work I did to create my project and asked me if I wanted to further trash my project by removing the modules from my project structure as well. I figured since it already started the delete process it would be a bad idea to keep things half done. So I was like “go ahead, delete. I’ll re-add the modules since you didn’t quite understand my intentions Mr. IDE.” Another dialog asking if I wanted to remove the VCS root of these projects as well. I knew this dialog from being bit in the past on an earlier build of Idea. Apparently if you don’t agree with this nasty dialog you’re left with a project “.ipr” that can no longer link previously deleted modules with the VCS provider they were associated with. So then I’m like, “aww crap… go ahead and completely clear my project so I can add this one module thank you.” That’s just what I wanted to do. Create a brand new project around one sily module. Well after being bossed around by those mean ol’ dialogs I eventually got everything reimported when I got another surprise.

Maven support is wonderful in Idea. So wonderfule you set your clock by it. So great you invite your friends and grandfolks over to admire and discuss its features. Of course the old-folks don’t really grok the tech talk. Hell, they don’t even grok “grok”. They’re just happy to have conversation with the grandkids and get out of the old folks home once in a while so they’ll happily listen to practically anything you mumble to them while feigning interest. That’s the nice thing about grandfolks. Just like grandfolks Maven support is nice. However, when it breaks it leaves no clue as to what went wrong. So I’m trying to import this one module and I noticed they fixed one crappy hidden problem explanation. If I don’t mount the network drive where our shared install of Maven is hosted it used to pretend that there were no maven projects in any folder. Now I get an error dialog stating that it can’t find the mapped drive or something like that. The next nasty problem starts with a pom that doesn’t define a group id. You see, I’m pulling modules in from another project I worked on a while ago with a whole new parent structure that no longer exists. So I went and removed the parent tag because I was being nagged about the parent pom not being found. I never thought about how I inherited the group id. So now Idea starts giving me nasty NullPonterExceptions after I’ve imported and thought I’d successfully set everything up. This happens everytime I synch the project. Then it happens even worse when I recreate the project from scratch trying to pull the errant module in. I just keep getting NPE and scratching holes in my scalp. I’m well over my word limit for a quick post that started with “I ain’t got time to splain much…” Hit me up people…

You get the big Idea?

Developers tend to stick with particular tools, unless you’re the daring type. Once they learn and familiarize with something it’s hard to get them to change. I’m a believer in constant change. Always look for the new and improved. Keep your eye on what’s out there even if it costs you some downtime to relearn or experiment with a familiar way of doing something. In case you didn’t realize, I’m beginning another raving post about my favorite software package under the sun… IntelliJ Idea. I rate this software above any other software on the market. That includes operating systems, graphic editors, Spreadsheet apps, word processors, everything! It doesn’t include all of those features but as far as software quality and direction the guys (and gals) on the Jet Brains team get it. They understand me. They understand you (if you write Java code). They understand us better than we understand us. Where else will you get software that adapts to your working style while teaching you how to better do your job? I could rave about Idea for years (and I will). That’s all… no “buts”. Just a frank expression of how I can and will rave about Idea for years.

If you’re an Eclipse user you’re missing out. Sure Eclipse does everything and plugs into everything from your Python or C++ project to your Easybake oven. But when it comes to heads down Java development I firmly believe Idea will always have a slight edge. (Eclipse is a nice tool and all but it is slightly edge out in some areas.) Consistency and fluency is the biggest edge that Idea has. Everything can be done in such a consistent fluent way. Whether you’re editing a Swing GUI or and XSLT template or some Javascript embedded in HTML embedded in JSP with Struts or JSTL, or just hashing out some quick and dirty Ruby or Groovy code. The same consistent key strokes give you the same feel across all editing environments. Also everything is mapped out for efficiency so you don’t need to mouse the hell around for options. Rave! I rave about the tools. then there’s this plug-in contest which, in my mind, is the most brilliant way to improve your overall product. Throw a carrot in front of a bunch of devoted programmers that love your product and ask them to fill in the missing pieces. Release their work to the community for instant feedback and viola you get this self churning machine that gives you the beauties of better Maven support, my old favorite XSLT/XPath support, PHP refactorings, RelaxNG, and Google translate. Life just doesn’t get better for the lay person looking for an easy fix to something that’s been bothering him.

Why am I writing this?
I found yet another gem in Idea that just jumped right out and tickled me. I have this custom-self-made template for generating Java source code that I keep registered as a plain text file. I frequently make changes in the template, which is essentially Java source with Ant place-holder markers and I’ve been getting annoyed that I can’t auto complete symbols in the file. Well this morning I was calling a method on a variable that had been declared on an earlier line in the template and I blindly decided to try the ol’ Ctrl+Space (or option space on my Mac) combo. There was know way for Idea to know what methods were available on the reference. There was no way for Idea to know it was a reference because I had told Idea that I was editing plain text. There’s no variables, symbols, or references in plain text! However… lo and behold… I get the popup with all the available methods for the variable’s declared type! Unbelievable! That might not make much sense to many of you out there. It waas one of those developer moments that you just had to live to appreciate. You know the feeling like when you fix that long standing bug that finally allows a colon to show on a GUI widget label? And then after you fix it you run around poking everyone in the office pointing out a colon on a widget label like it’s the coming of the new millennium? And then that frustrated feeling of “they don’t appreciate what I just done did” forces you into the long-winded explanation of some core logic that nobody but your compiler understands? Yeah that’s the feeling I have right now explaining this to you all. In my mind Idea just found the cure to Alzheimer’s and y’all just ain’t recognizin’!

That’s what I’m talking about!!!

Every so often I get myself into a jam. Typically it involves some deadline, a low-ball estimate I gave, or inaccurate progress reported against an individual assignment. When I get into these tight situations sometimes I pray. Sometimes I cheat, and sometimes I just bang my head and look stoopid. Then there are those times when I reach into my Idea bag of tricks and pull out something so wild that I amaze myself. Actually I don’t amaze anybody, its Idea that continues to amaze me…

What’s up? The name’s Cliff and your here because you terminate your line statements with a semicolon while enclosing the majority of your bright ideas in curly braces “{” and “}”. Today’s discussion involves what we do when we’re asked the impossible. Common requests to consider are things like, “I want you to rename all of your class and package names to include the initials J.D.E. and pay tribute to the CEO of the company” or “can you delete half of your source base and still have a functional app?” requests like these sometimes come from well meaning but heavily pressured project stakeholders or management and other times come from an innocent misuse of potentially offensive English. (I recall a scenario where racial terms “master” and “slave” proliferated our entire source base and needed to be cleaned up at the eleventh hour.)

Today I was saved by Idea’s dependency management elegance. You see I have the unfortunate task of cleaning up duplicated effort in the codebase (hereafter referred to as the fork) which resulted from two well meaning developers mis communicating with one another. (I was one of the guilty with a major problem in communication.) The fork (hereafter referred to as “the day the developer went dark”) consisted of duplicate classes residing in differing packages providing identical but incompatible functionality. There was supposed to be a “merge” (will now be aliased as a “best of both worlds”) after our last sprint wherein both coding efforts were to be reconciled into one common mixture of great ideas. Midway through my analysis of “the day the developer went dark” I realized that there would be a great deal of effort involved, much more than grabbing classes from one package and using them in another. It then became an exercise of re-inventing the ideas the were reinvented from other ideas that came from a port of yet further ideas. In short I had to recode some logic.

Idea to the rescue
This time I knew it was there. It was one of those features that caught my eye about a month ago when I said, “Wow that menu option look like it’s worth exploring. I’ll have to play with it soon because I feel a need coming on.” And right when I said that I tucked the location to the option away in the left-rear corner of my brain. (I lost sleep that night because it’s hard to relax when you’re lying on a nugget.) So when I started puzzling over how I was going to track down all the related objects and references to one branch of the day the developer went dark I needed only to cycle through the main file menus until I tripped over what resembled the familiar option. Analyze Dependency Matrix was the title. It sounded real cool too. Matrix, like I was gonna bend over backwards and doge bullets in slow-mo possibly catching one in the corner of my shiny black ankle length leather overcoat. I took the option and lo and behold! What I saw was a visual graph. It was a little intimidating at first but a quick gander at Idea’s help docs cleared things immediately. I could easily click and highlight either packages or invidividual classes to bring up color cues of what was tied to them and what was calling into them. Within ten minutes I had the entire branch cleaned. Comparing that to a more traditional approach of find-usages or even a more cave-man like file search in project paints a vivid picture of why IntelliJ Idea should be spinning along on every Java developer’s hard drive.

Keep it locked on this post because I want to put a screen-shot of the Matrix up but I also want to hit publish before lunch is over so I don’t have time right now.