IntelliJ 8: Even smarter code completion!

Erik Pragt

Smart code completion has been improved in IntelliJ 8. In the new version of JetBrains' IDE 'even smarter' code completion is added. But first I'll explain what smart code completion is! Basically, it's code completion on steroids, which takes the type of the variable into account too which the new value is assigned to. So, if your assigning a value to a variable of type String, smart code completion will only display methods which are compatible with a String type, and filters the list of methods accordingly. It does even a lot more than this, which you can read about here

The 'even smarter' code completion extends this smart behiour to objects two steps away. This best explained with some code samples:

public class Person {
   private Address address;

   // getters & setters
}

public class Address {
   private StreetName streetName;

   // getters & setters
}

public class StreetName {
   private String name;
}

And you type the following:

StreetName streetName = person.

When pressing Ctrl+Shift+Space once, nothing will happen, since no methods on person exists which are compatible with the StreetName type. However, pressing it twice will automatically find the getStreetName in the Address class, so the final result will look like this, which is a real timesaver, especially in an environment with loads of domain classes (instead of using Strings for names, etc). The final result is shown below!

StreetName streetName = person.getAddress().getStreetName()

Comments (1)

  1. Matt - Reply

    November 12, 2008 at 9:42 pm

    I'm not an IntelliJ user, but that looks pretty cool. A good IDE should work hard to guess what we might mean (and I've certainly wished that Eclipse would put in more effort.)

    Whoever came up with the "Law of Demeter" is probably rolling in their grave, though!

Add a Comment