Posts Tagged ‘code inspections’

Upgrading Event Listeners to GWT 1.6

Friday, July 10th, 2009

Google Web Toolkit 1.6 replaces EventListener class with EventHandler, so the existing code base needs an upgrade. In most cases IntelliJ IDEA can do this automatically — all you need to do is to press Alt+Enter on a highlighted listener and select Replace quick-fix.


IntelliJ IDEA will then upgrade your code:


This feature is available in Maia builds that you can download from EAP.

Global unused declaration inspection

Monday, April 27th, 2009

Thanks to improvements in the internal indexes behind the Intellij IDEA code insight engine, Maia will be able to instantly highlight some java classes, methods and fields which are unused across the entire project.

To use the feature, enable the Unused declarations inspection.

unused members

Of course, all sorts of JEE @Inject annotations, test code entry points
and other implicit dependencies configured in the Unused declarations inspection
are deeply respected.

WebBeans Inspections in Maia

Thursday, April 23rd, 2009

IntelliJ IDEA code analyzer will be extended with WebBeans-specific inspections in the upcoming Maia release:



Here’s the example of how they work:

Avoiding Assert Statements with Constant Conditions

Thursday, April 2nd, 2009

Though assert statements are very useful when it comes to checking runtime assumptions, using them to verify conditions that are constant is not so wise. Assert conditions that always evaluate to true are particularly unnecessary because they will never throw an error and can only serve to use up the CPU resources.
Here is an example from com.sun.java.swing.plaf.gtk.GTKDefaultEngine:

Assert condition true is a constant

IntelliJ IDEA 9 will bring you the assert statement condition is constant inspection, which will detect such assert statements, except for boolean literal false, because it is often used in code which is known or supposed to be unreachable.

Towards Side Effectless Assert Statements

Friday, March 27th, 2009

It is a well known rule that assert statements should cause no changes in state outside of them (aka side effects). Until now, you could only check if this rule was followed by visually inspecting the code. In IntelliJ IDEA 9 a new assert statement with side effects inspection will be available to help you keep assert statements free of side effects.

'assert' has side effects warning

The inspection will warn about modification of variables and fields inside of the assert statement. The assert statement will also be reported if a method called by it modifies any fields.

No More Missing TestNG Tests

Wednesday, March 25th, 2009

I often forget to add newly created tests to the testng.xml, which is used in our TeamCity build, and by the time I realize that they don’t run something is surely went wrong. What a bummer! Not any more, fortunately — IntelliJ IDEA makes sure no tests are missing. All it takes is to enable the Undeclared test inspection under TestNG in the Errors section of the Settings dialog.
Undeclared Test Warning