Wednesday, November 4, 2009

IDEA









































Prev don't be afraid of buying books Next






























IDEA




with Bryan Dollery






I've asked Bryan to
talk about IDEA IDE from IntelliJ. Bryan is a well-known consultant
in New Zealand and an outspoken IDEA user and advocate.





IDEA[URL 33] has many features that will help
with practicing TDD; in this section we will look at several of
them.



If I use a class that hasn't yet been imported,
IDEA will use a tool-tip to tell me, and offer to import it for me
— very simple, very fast. Once the class is imported its
methods and attributes are available to me for code completion.



If I use a class that doesn't exist, something
that we all do at first with TDD, then IDEA puts a lightbulb in the
gutter which, if I click on it, offers me a number of code
generation options, including the option to create the class for
me.




If I have an object and attempt to call a
method that doesn't exist, IDEA will use the lightbulb again to
tell me that it can help out. Clicking on it gives me the option to
create the method. Here is where IDEA starts to show its real
intelligence. When generating a method, IDEA has to make certain
assumptions: the return type, the parameter types, and their
names.



If I have started with:




fragment.doSomething("name");






within fragment's class, IDEA can generate:




void doSomething(String s) {
}






It will then put a red box (a live template
query) around void, with my cursor in it. It's telling me that void
was an assumption, and that I need to either accept it by pressing
enter or tab, or change it. Once I'm happy with the return type, I
can press enter to move to the next assumption, the type for the
parameter. The final assumption here is the name for the parameter,
which I don't like, so I can change it. Of course, if I provide it
with more information, say, by assigning the return type to a
variable, then IDEA will make better assumptions.



To run the tests I have a few choices available
to me. I can compile, test, run, or debug, at a class level or a
method level. If I right-click on a method then it assumes that I'm
interested in that method and offers choices based on the method,
but if I right-click on the class name (or a gap between methods)
then I'll be offered these choices for the whole class (which is
what I usually want). I can also choose to run all the tests within
a given package.



To run or debug I don't need a main method, only
the test methods. Being able to debug at a test-method level is
very useful. I don't have to play around getting to the method I
really want to test; it's all done for me.



The integration with JUnit is very tight. If the
GUI runner shows a stack trace I can double-click on a line of the
trace and be taken straight to that line in the editor. Fix the
error, recompile, and alt-tab back to the GUI runner to rerun the
tests. I can also choose to run the text-runner, the output of
which appears in IDEA's messages window.



However, refactoring is the jewel in the crown
for IDEA. Look at your current editor right now, and open the
refactoring menu. If it's not at least half the size of your screen
then you're really missing out.



There are 22 refactorings listed on its menu,
but some of those are multirefactorings. Take, for example, the
rename refactoring. It works on variables of any scope, methods,
classes, and packages — that makes it four similar
refactorings in one. When it renames a class, it also renames the
file it's in, and when it renames a package it'll rename the
directory and ensure that the change is recorded in CVS — this
is a very bright tool, nothing is left unfinished.



One of my favorites is Change Signature — I
can use it to add, remove, reorder, and rename parameters to a
method — all at once. If I change a parameter's name it'll do
a rename refactoring automatically for me, before it does the rest
of the changes. If I add a parameter it asks for a default value.
If I reorder the parameters it'll ensure that the method is called
correctly throughout my project.



IDEA attempts to transparently automate
repetitive and common tasks. It leaves nothing undone, and asks for
clarification when it's guessing. It's highly polished, looks
great, and will probably speed up your coding significantly.















































Amazon






No comments:

Post a Comment