Archive for March, 2006

Structural search and replace

Friday, March 31st, 2006

Searching through a large project is always tiresome. Changing a large project is usually more tiresome even with all cool IDE features such as search by regular expressions, find usages, or automated refactoring.
For example, you may need to find all the classes that implement exactly two interfaces or find all methods that accept a parameter with a specific name and/or type. Finding usages or simple search may produce too long lists of results, especially if your project is really large.
The solution suggested by IntelliJ IDEA is Structural Search and Replace (SSR) where you can define the code pattern to narrow the search scope.

Let’s consider an example when you need to find all inner classes in your project. The search template will look as follows:

class $Class${
   class $InnerClass${}
}

Here $Class$ and $InnerClass$ can be any class names.
If you need to find an inner class that implements, let’s say, Runnable interface you can write the following:

class $Class$ {
   class $InnerClass$ implements Runnable{}
}

To find all the inner classes that implement any interface, it is enough to write this:

class $Class$ {
   class $InnerClass$ implements $Interface${}
}

If “any interface” is not what you need, it is possible to apply powerful constraints to the variable.
Of course, you can also use the templates for replacing the found code. For example, you may wish to convert all the found classes to become final. The screenshot shows how it looks in IntelliJ IDEA user interface.

”Screenshot”/

Once created, a template can be saved and then reused. And of course, IntelliJ IDEA provides a lot of predefined templates.
Get interested? Learn more about SSR in Structural Search and Replace: What, Why, and How-to written by Maxim Mossienko, one of the JetBrains developers and originator of the Structural Search and Replace feature.

Note   This tip was originally posted at www.javalobby.org.


Technorati tags: ,

JetBrains Team Server: public server launched

Wednesday, March 29th, 2006

We have recently announced the EAP for our new solution - JetBrains Team Server (codenamed “Albus”).

You don’t need to download and install Team Server to get an overview of its features set. Take a look at the features which we have already implemented at the public Team Server.

Team Server: Build Status Overview

Currently the following features are available:
•   running, pausing, and resuming builds of different projects
•   viewing the test results and the project status
•   displaying the build status before the build is complete
•   reordering the builds queue using drag-and-drop
•   taking responsibility for the build failure

More features will be delivered soon. They are now discussed at the Team Server forum. Participate in the discussion and post your wish list of Team Server features – the Early Access Program is still in progress.

Read the Team Server FAQ and installation and configuration instructions if you want to try Team Server with your project.

See the development roadmap and suggest features at the Team Server space in Jira, and we eagerly wait for your feedback in this blog as well.

Technorati tags: , , , ,

i18n support

Tuesday, March 28th, 2006

It is widely announced that the recently released version 5.1 of IntelliJ IDEA provides an “industry-leading i18n support”. But what does that mean? Well, this phrase covers not just one particular feature, but the whole set of enhancements, improvements, and new features for making internationalization faster and easier.

First of all, the “Hard coded strings” inspection helps you to quickly find all hard-coded string literals at once, instead of thoroughly scanning all files in the project.

With this inspection switched on, the literals are highlighted right in the editor. Also you can inspect the code and see the results in the devoted window.



When the hard-coded string is found, it may need internationalization, or it may represent some identifier that does not depend on localization (and that’s often the case). IntelliJ IDEA smartly handles both variants.

If you decide to internationalize the string, just use the intention action, and the string will be added to an existing .properties file.

i18nize action

IntelliJ IDEA also handles situations when a hard coded String literal is a part of a concatenated string. In this case, the generated property string will contain all necessary parameters.

i18nize concatenation action

For the strings that don’t need internationalization, there is a special intention action. With this action you can annotate strings as @NonNls and therefore exclude them from the internationalization process. It is possible to annotate a certain variable or class field as well as a whole method, class, or even package. Just don’t forget to add annotations.jar to your project or module classpath to make the annotation and related intention actions available.

non_nls annotation

Note that @NonNls annotation is not required for values representing property keys. IntelliJ IDEA recognizes them automatically.

Get interested? See i18n demo.

Note   This tip&trick was originally posted at www.javalobby.org.


Technorati tags: ,

Web Developers about IntelliJ IDEA

Monday, March 27th, 2006

Although IntelliJ IDEA is a Java IDE in the first place, it also has a strong support for Web and J2EE development. And it’s not just what we think about our product. It’s what our users think.

Here is a couple of reviews about HTML and JavaScript editing in IntelliJ IDEA:
1.   Teaching Mr. Rails a Lesson on Productivity
2.   JetBrains IntelliJ IDEA - Development Tool Review

Except for the warm words for IntelliJ IDEA, both reviews contain useful tips&tricks and examples. So, if you use IntelliJ IDEA for Web development, these articles might be helpful.

Detecting probable NPE’s

Sunday, March 26th, 2006

It is a well-known fact that IntelliJ IDEA provides developers with a huge number of automated code inspections and quick fixes for discovering and correcting a lot of real and potential problems.

One of them is called “Constant conditions & exceptions” and is capable of detecting expressions that are always true or false (potential dead code) as well as points out where a RuntimeException may be thrown.

IntelliJ IDEA designed two annotations that make this inspection even more powerful. These annotations allow you to specify method contracts formally, and then validate whether these contracts are actually followed.

The @Nullable annotation reminds you on necessity to introduce a null value check when:
•   calling methods that can return null
•   dereferencing variables (fields, local variables, parameters) that can be null

The @NotNull annotation is, actually, an explicit contrast declaring the following:
•   a method should not return null
•   a variable (like fields, local variables, and parameters) cannot hold the null value

For instance, let’s create a method where the parameter has the @NotNull annotation. Then call this method with a parameter that potentially can be null.

public class TestNullable {
  public void foo(@NotNull Object param) {
   int i = param.hashCode();
   //some code here
  }
  …
  public void callingNotNullMethod(ArrayList list) {
   //some code here
   if (list == null) otherMethod(list);
   foo(list);
  }
  …
}

IntelliJ IDEA highlights the problems “on-the-fly”, so you can see the inspection results right in the editor.

”Screenshot”/

Get interested? Learn more about @Nullable and @NotNull annotations in IntelliJ IDEA in Nullable How-To .

Note   This tip was originally posted at www.javalobby.org.

JetBrains at Russian JUG in Saint-Petersburg

Friday, March 24th, 2006

Tomorrow, March 25th, at 16.00, JetBrains will make presentations about IntelliJ IDEA and Team Server at Russian Java User Group in Saint-Petersburg. The JUG meeting will take place at “Rossiya” hotel. All the presentations will be in Russian.

Agenda:
1.   Dmitry Jemerov - “Team Server” (Сontinuous integration, release management, server-side code analysis)
2.   Mike Aizatsky - “Enterprise development in IntelliJ IDEA” (Covering version 6.0: EJB 3.0 support, migration from EJB 2.1 to 3.0, JSF visual designer, and more)

If you want to participate, visit www.jug.ru.

JetBrains also would like to remind you that if you belong to a Java User Group (doesn’t matter where), you can contact us and we’ll organize you give-aways to distibute at future JUG meetings. You will need to provide only the following info:

1.   URL of your JUG
2.   President/Organizer’s Name & Email
3.   Location/Country

Running JUnit 4 Tests in IntelliJ IDEA 5.1

Wednesday, March 22nd, 2006

Note: The tip was originally posted at t800t8.blogspot.com by t800t8



Although the full JUnit 4 support will be added only in IntelliJ IDEA 6.0, you can run JUnit 4 tests right now, in the 5.1 release. Just follow the instructions below.

Note: Of course, you need to add the JUnit 4 JAR file to the classpath first.

1.   Click Settings | File Templates.
2.   In the Templates tab, create new template and name it “JUnit 4 Test Class” or anything you like.
3.   Paste the following code fragment into the text box:

package ${PACKAGE_NAME};

   import org.junit.*;
   import junit.framework.JUnit4TestAdapter;

   #parse("File Header.java")
   public class ${Name} {
       public static junit.framework.Test suite() {
           return new JUnit4TestAdapter(${Name}.class);
       }

       @Before
       public void setUp() {
       }

       @After
       public void tearDown() {
       }

       @Test
       public void testSomething() {
       }
   }


You can see the results on the screenshot.



After you apply the chages, use this template to create JUnit 4 test classes. To run the tests, simply click Run.

Enjoy it and happy unit testing!

Technorati tags:

JetBrains Products Win Jolt Productivity Awards

Monday, March 20th, 2006

Once again JetBrains has been honored with new industry awards, this time at SD Magazine’s 16th Annual Jolt Product Excellence Awards. Two of our products received Productivity Awards in two categories:



   - IntelliJ IDEA 5.0 (Category: Development Environments)
   - ReSharper 1.5 (Category: Utilities)


(For details, please see http://www.sdmagazine.com/jolts/2006index.html)

The entire team here at JetBrains wishes to thank the judges, and especially our IntelliJ IDEA and ReSharper users who are instrumental to the success of our products.

Defining a Custom Quick List

Monday, March 20th, 2006

Contributed by: Etienne Studer

When you press let’s say Alt + F1 in the editor, you can see the so-called Quick List, that is actually a subset of commands that are nice to have “at your fingertips”.
In IntelliJ IDEA, you can create custom Quick Lists and fill them with the commands of your choice.
For example, a Quick List with the most frequently used commands of your Version Control (e.g. Perforce) can be of a great help.

To define a custom Quick List:

1.   Click IDE Settings | KeyMap.
2.   In the Quick lists area, click Add.



3.   Choose commands you want to add to the Quick List.



4.   Now your list is added to the list of actions in the keymap, and you can assign a shortcut to it (just don’t forget to create your own copy of the default schema).



When you press Alt + F2 in the editor, you can see the Quick List of the Perforce commands.

Open a file system view for the current file/folder selected in IntelliJ IDEA

Friday, March 17th, 2006

Contributed by: Etienne Studer

Note: The tip is valid only for MS Windows OS.

If you often need to locate a file or folder in your file system, you can configure Explorer to be opened right from IntelliJ IDEA.

1.   Click IDE Settings | External Tools, and then click the Add button.
2.   Specify the tool as shown on the screenshot below.
 

3.   You can also assign a keyboard shortcut to this tool.
   a.   Click IDE Settings | Keymap.
   b.   Select External Tools | Explorer, and click Add Keyboard Shortcut. For example, assign F10 key.

Note:   The default keymap schema cannot be modified. So, if you use the default keymap, just copy it to have your own.



Voila! Now if you press F10 in the Project or Hierarchy view, or just when you edit the file in the code editor, it will be located in Explorer.
And of course, you can attach any other external tool (let’s say MS Word) the same way.