willcodejavaforfood.com

Variable Usage Plugin

A class can be described as a collection of variables (attributes) and methods (operations) which use these variables to fulfill the purpose of the class. A well designed class should only have a single responsibility (SRP) and all methods and variables are related to this purpose. When work is done on a class and there is no refactoring done the technical debt increases and the class might end up with more than one responsibility. When this happens one way to find these different responsibilities would be to look at the relationship between variables and methods. Variable Usage Plugin will show several views of just that.

Download

File Version Platform
com.willcodejavaforfood.VariableUsage_0.0.2.jar 0.0.2 Eclipse Plugin

Installation

After downloading the plugin you need to put it into the plugin folder of your Eclipse installation. Once that is done restart Eclipse and open the Windows->Show Views->Other->Refactoring->Variable Usage View. This will open a new view in your workspace and once you have selected a java class in the package explorer it will be populated with the relationship between instance variables and methods.

Note that if you have a previous version installed you need to manually delete it from the plugin folder.

Instructions

Once the plugin has been installed all you need to do is select a Java file in the package explorer and Variable Usage View will be updated. There will be four nodes visible in the plugin view: Fields, Methods, Connected Methods and Ignored Methods.

The Fields node will contain a list of all fields from the class. Each field node will have all the methods that makes use of it as a child.

The Methods node will contain a list of all methods from the class. This will not include methods that are deemed to be getters/setters. Getters and setters will be placed in the Ignored Methods node. It is possible to move methods between the two nodes by right-clicking on a method and choose the appropriate ignore/unignore option. Each method node will have all the fields that it makes use of as a child.

The Connected Method node is probably a good place to start when you are looking to break up a large class into smaller classes. This node will contain sets of methods that are deemed appropriate for being moved into their own class. All methods in each set are connected through which fields they are using either directly or indirectly. Consider the following example:

  • Method A
    • Field A
  • Method B
    • Field B
  • Method C
    • Field A
    • Field B

As you can see Method A and Method B does not share any variables but they will belong to the same set anyway thanks to sharing variables with Method C.

The last view is a table showing how many variables two methods have in common.