Completion Improvements in Leda

Hi,
thanks for making code completion even better. I'm currently doing a lot of coaching for TDD and I am wondering if there were some way to improve code completion for that use case.

The problem is that there are a lot of duplicate names in that problem domain:

  • JUnit has an assertThat statement (org.junit.Assert.assertThat)
  • Hamcrest has an assertThat statement (org.hamcrest.MatcherAssert.assertThat)

If you use Hamcrest, you'll want to use the second version but not the first one. This can be solved by excluding the one you don't want to use from auto completion. I would probably even suggest that if you use Hamcrest it is a coding error to use the standard JUnit assertThat statement and it should be flagged by code analysis.

It's getting even more messy with matchers. not(Matcher<T>) can be from:

  • org.hamcrest.CoreMatchers
  • org.hamcrest.Matchers
  • org.hamcrest.core.IsNot


This is quite tedious to exclude all those variants. It's getting even more complicated when you have different projects because the import settings is not project specific. There could be one project that uses Hamcrest, but another that doesn't (or maybe even uses FEST instead – which has another assertThat() statement).

Having to import things really disturbs the flow. Suppose, I have written something like that:
assertThat("description", actual, equalTo(expected));
Then I have to do two imports, sometimes even need to navigate to the right place to trigger the import intention. This makes me loose my programming flow a lot. It gets a lot better once imports are in place within the class but still, it's botherin me enough to make me write this post...

It's my experience that especially beginners have a lot of trouble figuring out which to use when. They get confused quite easily if they choose a wrong import because of all those weird error messages. You can't use smart templates for that because imports are optimized away immerdiately, if they're not used.

Also, there's method names where I do not want to create the method but import an existing one in 99,9% of all cases (e.g. assertThat()). However, the intetion always offers to create the method as first entry. Maybe that there could be some learning based on the name to determine the ordering in the popup.

I find it to be very difficult to create feature requests that describes what I want the behavior to be, that's why I'm hoping to get feedback from the forum: How do others handle this situation? Do you see any way to make this less messy? I know that this is more a framework problem than really an IDEA problem. But that import nightmare is the messiest part of TDD by far.

1 comment
Comment actions Permalink

First of all, you can disable "Optimize imports on the fly" in Editor | Auto Import settings and the unused imports of the correct package won't be removed.
You can just remove the unneeded dependencies from your classpath. Or you can configure "Illegal package dependencies" inspection for your use cases. Then the illegal imports will be highlighted red.

0

Please sign in to leave a comment.