Posts Tagged ‘code analysis’

Analyzing Dataflow with IntelliJ IDEA

Wednesday, August 5th, 2009

Upcoming IntelliJ IDEA version, Maia brings you an improved version of the Dataflow to this feature and the completely new Dataflow from this.

Here I am describing how these features work and how they can help you the Code Archeologists better understand your code.

I am using Apache Tomcat source code as an example.
Let’s have a look at the SingleSignOnMessage class and its obscure String authType field.

(more…)

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

Quick Code Cleanup

Thursday, March 19th, 2009

With IntelliJ IDEA you can quickly clean up your legacy code. If a problem occurs multiple times in a file, you do not need to manually apply a quick-fix every time — use the Fix all intention to repair them all at once.

Quick Class Hierarchy View Using UML

Tuesday, March 17th, 2009

IntelliJ IDEA 8.1.1 will support Show Class Hierarchy action that displays class hierarchy of a selected type. Just place the caret at any type in the code editor and press Ctrl+Alt+U.