JetBrains makes a high end IDE
called IntelliJ Idea,
usually called simply Intellij.
Jetbrains gave me a copy of Personal Intellij on 2006-02-20.
I have been using it as my only IDE ever since. I still use Visual SlickEdit for
quick edits since Idea takes so long to start. IntelliJ is reknowned for its
advanced editing and clever algorithms for factoring code. It is written in Java
Swing itself. It is also known for being faster than the competition. It has to
be quicker and better since its competitors like Eclipse, NetBeans and Oracle
are free. Has no GUI wizards though they are in beta. This is Chris Lamb’s
favourite IDE. It runs under Windows, Max OS X, and Linux.
Pricing
It comes in four versions:
-
for Open
Source developers.
-
for Academic
use.
-
for Personal
use.
-
for Commercial
use.
I believe the products themselves are identical. All but the free version come
bundled with unlimited email support. The support is fast, courteous and
generous. This is the advantage of using a commercial package.
Getting Started
To get started on your first project, you must manually navigate on hard disk to
find a JDK for it. At first, it looks as if it is broken, showing an empty list
of installed JDKs.
Like Eclipse, IntelliJ has its own vocabulary. Classes
are grouped into packages. Packages are grouped into directories.
Directories are grouped into modules. A module roughly
corresponds to one distributable executable. Each module can have its own
classpaths and libraries. Modules are grouped into projects.
All classes in a project must use a common code style, and common source level
1.3, 1.4, or 1.5 (oddly specified on the module configuration screen) and common
target level (specified as additional compiler options -target
1.4.) It is possible, however, for each module to use a different JVM.
To simplify things, you can have only one module per project. Then a project
becomes a group of related packages all compiled at the same source and target
level.
It is easy to muddle up projects, directories, modules, packages. I discovered
two tricks to help sort it out.
- Use a naming convention. E.g. end projects in p, and modules in m.
- If you don’t know if some node Intellij is showing you is a project or a
module or a directory, refactor and “threaten” to rename it.
IntelliJ will tell you what sort of beast you are about to rename.
Unfortunately IntelliJ will ask you to create packages and modules without
properly defining them. You will likely have to start from scratch once the
meanings come clear. The key place to define these terms should be the screens
displayed the first you are asked to name your project and module. Hint hint…
To allow one project to use the class files of another, you import not the
project, or the module, but the name of the classes directory into your module
settings.
I suggest experimenting with some small projects for a while to get the hang of
things before you commit to your overall structure.
Nice Stuff
- Like Eclipse, it instantly warns you of syntax errors as you type. They
disappear as soon as you fix the problem. You don’t need to invoke the
compiler to check out your corrections.
- The error messages are more intelligible than Eclipse’s.
- It warns you when override a method in the superclass with a tiny red arrow in
the margin, with a tooltip to explain what it means.
- It is quite easy to find things. Menus and dialogs go more or less directly to
what you want. Even on my first time out I did not get lost wandering around a
rabbit warren of nested dialogs. It is quick and easy to find thing in help. For
example, you click the wrench icon, and then laid out before are all icons for
all the different things you could possibly configure. You go right to what you
want, rather than playing rabbit in the warren of nested menus trying to find it.
- It has a built-in lint they call code
analysis.
- It is very similar to Eclipse. I had very little problem adjusting to the
differences.
- If IntelliJ were a person, you might describe it is polite, considerate or
thoughtful. It is sort of like the lady in a hotel who puts a little chocolate
on your pillow. There are considerate little touches, like telling you in the
default code templates where to look to modify them, rather than making you go
digging. Like the gracious Mrs. Prothero in Dylan Thomas’s A child’s
Christmas in Wales, IntelliJ offers you something interesting to read
while it is compiling.
- Back in the 70s IBM used to give away folding cardboard cheatsheets. The green
card, the blue card or the pink card neatly summarized all the information you
often had to look up in manuals. IntelliJ carries on this fine tradition
offering a PDF file that when you print it, turns into a folding cheat sheet
that shows all the keyboard short cuts. It is one sided. Perhaps there is a
backside for it.
Plug-Ins
IntelliJ Plug-ins come with no installation instructions. It turns out that
installing any plug-in, including the Rearranger, is a snap. You don’t
have to download or build anything. In IntelliJ, Click File ⇒
Settings ⇒ IDE Setting ⇒ Plug-ins.. You can then view the plug-ins
installed already and also what is available. Right click “the
Rearranger” (or whatever plug-in you want to install, then left
click Install. (Selecting the plug-in and hitting OK
does nothing, ditto reload.). You have to shut-down
and restart IntelliJ before you can start using the plug-in.
The
Rearranger
The ability to order your methods is not built-in as it is in Eclipse. Instead
you install a plug-in called the
Rearranger that does even more:
- rearranges (reorders) class and class member declarations according to a user-specified
order and/or method call hierarchy;
- generates section-marking comments
- provides several controls for spacing within and between methods and classes.
- permits the user to manually rearrange items. This is particularly useful for
related groups of constants or to manage initialisation order.
You must configure The Rearranger before use to tell it your preferred ordering.
To configure, go to File ⇒ Settings ⇒ IDE Settings ⇒
Rearranger. It gives you very fine
control. It is wise to save your Rearranger configuration to a file in case
you have to later reinstall.
It is clever in the way it arranges methods, and inserts comments to label the
groupings. It can put getters and setters next to the corresponding property. It
knows that the main method is the primary one and should come before the other static
public methods.
Here is the rearranger configuration I use.
Downsides
- IntelliJ is even slower than Eclipse’s 38 seconds to get started. You will
want leave it running. On my 512K machine, it takes 87 seconds to start up
before you can enter a keystroke. Even with my new 1 gig dual core machine, it
takes 17 seconds to get started. Intellij, when it is running, greatly slows
down everything else in the machine. It takes an annoying 14 seconds to shut
down on my new machine. For a Win2K or XP machine you need a gig of RAM, for
Vista 2 gigs.
- IntelliJ is less jittery about temporary errors in code, such as something not
defined yet, or is unused — it just changes colour. However, IntelliJ
annoys you by asking if you want to import anything it does not recognise. In
Eclipse, syntax errors generate a giant slew of messages, making it hard to deal
with anything else.
- It does not summarise your errors at the bottom of the screen the way Eclipse’s
problems panel does. At least it doesn’t by
default. You have to go looking for the little syntax error markings. I find
them easy to overlook and thus don’t find out about my errors until a full
compile. F2/Shift-F2 help you find them within a file fairly easily.
- Though it sometimes underlines errors in Javadoc, it does not pester you about
fixing them the way Eclipse does. I find it easy to overlook the errors. They
don’t count as compile errors or warnings. I don’t get them cleaned
up until an Inspector pass.
- If there are files in the library for a project that don’t belong, and you
delete them, it literally deletes the files. It does not simply remove them from
the project.
- If you want to access files you compiled outside IntelliJ, it is best to bundle
them up into jars and include the jars individually rather than try to provide a
classpath. If you use a classpath, you will either end up including far more
than you intended, or it will claim not be to able to see the directories you
did import.
- When you are working in Eclipse you are always aware instantly of the global
effect of your every keystroke. In IntelliJ, you focus on one class at a time.
You can only see one project at a time, and when you swap projects IntelliJ
frantically rescans the source. There is no equivalent of the workspace, a
collection of classes from various projects that you are working on right now in
concert.
- When you run the code inspector (lint), it often display the results from some
previous run. It saves old runs, something that is just confusing.
- Sometimes the message from a successful compilation gets lost. All works, but it
does not acknowledge.
- If you reconfigure which JDK to use for a project, IntelliJ hums away for what
seems an eternity. It is reindexing all the class files in all the jars and also
all the source code in the JDK. Just let it churn.
- You have very detailed ability to define your code formatting style. With a
single click you can pull an entire project into conformance. However, when you
save a configuration, it does not show up in C:\Users\user\.IntelliJIdea70\config\codestyles
until you exit IntelliJ. Further it fails to save unless you run IntelliJ as an
administrator. It is not enough to just log-on as administrator. You must
configure the icon to launch IntelliJ with run as administrator. To
restore, you must put the xml config file in C:\Users\user\.IntelliJIdea70\config\codestyles.
You can't load it from some other directory.
Tips
- Put your resources in the classes not the src
branch of your project.
- Use Help ⇒ Default Keymap to get a PDF cheat
sheet of all the keystrokes and print it out. There are commands there you won’t
find on the menus.
- Use Ctrl + Shift + Backspace to navigate back to
the previous edit location.
- Projects can only see files in the same project unless you configure otherwise.
You must add the module library of class files of some
other project as a dependency. Add the class files,
not the source. Then attach sources to the
corresponding class files. If you simply attach the source files, when you hit Ctrl-B
you will see decompiled class files, not the original source.
- When you add the content root (where the source and
other project files are) to a module, add the entire module directory not just module\src.
- TODOs are not hidden tags like breakpoints. They are ordinary comments of the
form . You can configure other text and
comments to be treated as TODOs. There is no special command to create them.
- Use the Analyse ⇒ Inspect feature. It does all
kinds of wonderful things like detect code of the form if
( expectedValue == expectedValue
) where you meant if ( actuaValue
== expectedValue ). It will tell you about variables
you never set but never use. It will add finals
appropriately. It will reduce scope. It detects missing periods in Javadoc. It
will reformulate boolean nests into simpler code. But best of all, it detects
when you used ==when you should have used equals.
- Use Alt + Enter to get light-bulb tips on how to
improve your code, such as converting concatenation to explicit StringBuilders
where you can add a proper length estimate.
- When the results of your find-all or find-uses disappear, you can bring them
back by clicking the find tab on the bottom left of
your screen.
- Turn off auto-scroll-from source to stop IntelliJ
from losing your place in the navigation window.
- Ctrl + Q on a method to see its Javadoc. It will
show you the up-to-the-second changes, not what was generated on the last
Javadoc utility run.
- Don’t delete the old version until you have used a new version for a week
or so, and are sure all the configurations are copied over into the new version.
IntelliJ does not install over top of the previous version.
- Don’t ever run the code reformatter unless you have a clean compile. It
will mess your code up so badly it will require a lot of manual tidying to get
it back in shape. Another reformat after recompile will not be sufficient to get
rid of dozens of unwanted newlines.
- Use the refactor ⇒ introduce constant carefully.
If you factor out the constant 4, all the 4s in the program will be replaced,
not just the ones in the particular context you refactored. This can create all
manner of hard-to-find bugs. Unless the numeric value of the String
is distinctive, you are best to do this manually.
Backup
Other than your source files make sure you back up the project description files,
the *.ipr and *.iws files.
Also back up your rearranger configuration and your codestyle configurations in C:\Users\
user\.IntelliJIdea70\config\codestyles. These files can take
hours to recreate from scratch.
Restoring the codestyle is a bit round about. You must create a new dummy
configuration, and save it, without the .xml extenstion.
Then, shut down IntelliJ and overwrite that file with the one from backup. There
is no menu command to restore.
Yet To Learn
I need to find way to trigger the light bulb suggestions for improvement. If I
don’t look at them right away, they disappear.
How to keep the Alt-F7 Usages Window from disappearing before I have finished
with it. You can get in back again with the tab. It might be nice to have them
in another window always visible, especially if you have a big screen.
IntelliJ has a CSS and HTML editor as well, complete with refactorings. I have
not yet used it. Perhaps it will do the various cleanups I thought I would have to write custom code to do.