views:

50

answers:

1

[I've decided to give IntelliJ another go (to replace Eclipse), since its Groovy support is supposed to be the best. But back to Java...]

I have an Interface that defines a constant

public static final int CHANNEL_IN = 1;

and about 20 classes in my Module that implement that interface. I've decided that this constant was a bad idea so I did what I do in Eclipse: I deleted the entire line. This should cause the Project tree to light up like a Christmas tree and all classes that implement that interface and use that constant to break. Instead, this is not happening. If I don't actually double-click on the relevant classes -- which I find using grep -- the module even builds correctly (using Build -> Make Module). If I double-click on a relevant class, the error is shown both in the Project Tree and in the Editor.

I am not able to replicate this behavior in small tests, but in large modules it works (incorrectly) this way. Is there some relevant setting in IntelliJ for this?

+2  A: 

What you have here is an interaction between a standard java issue and a standard IDEA behavior. Constant expressions like this are inlined in the class compilation (as per the Java Language Specification), so in fact the class referencing this constant did not change just because you removed the line (obviously) and there is no recorded dependency between the constant and the class anymore since it was inlined. This causes the compilation to not fail (the class wouldn't fail at runtime either if that was the only change - it will only fail when you do a clean build).

One way around that in IDEA is to do a Build->Rebuild Project when you have such a change. The other is in Settings->Compiler there is an Honor Dependencies on "Compile" command. This can adversely affect performance in large projects (hence it is disabled by default), but is supposed to solve this kind of problem.

The other part of this problem is that IDEA does not automatically recalculate all inspections on a change like that. It recalculates when you open a file. I'm not aware of a setting that makes IDEA do that. When you rebuild any problems found will get highlighted (up to where the compiler gave up), but the highlight won't go away until you open the class or recompile as well.

Yishai
Informative and interesting stuff, +1. I still don't understand why Eclipse does notice this change and does it FAST. For this problem, anyway, the answer is to reduce projects down to just one module each, because there is no "rebuild module." Thanks again for your answer.
Yar
@yar, if you rebuild the project it rebuilds all modules, so you can have as many modules as you want, you just can't rebuild from scratch just one module (there can be some edge cases that would make that problematic). As for how Eclipse does it, I'm not that familiar with eclipse, but what I suspect is that it doesn't do all of its code inspections as one group, and probably divides them into compilation issues and other issues and only reevaluates the compilation issues, or it leverages the fact that it has its own custom built compiler.
Yishai