Exercise 1.2: Running a structural analysis code review
This exercise assumes you have completed Exercise 1.1: Importing the required resources. In Exercise 1.2 you read a user scenario first. Then you assume the role of the software architect described in the user scenario and use the project you imported in Exercise 1.1 to complete the exercise.
User scenario
To review newly written code to assess its quality, the architect wants to look for general anti-patterns. Anti-patterns are known problems that occur in code and do not follow best practices. While design patterns are good models to follow, anti-patterns are bad models that you should avoid. Some specific anti-patterns include the following types:
- Breakable: The object in the code has so many dependencies that it is likely to break when another object is changed.
- Cyclic dependency: A group of objects is so interconnected, often circular, that a change to any object could affect all of the others. Also referred to as a tangle.
- Hub: The object has both many dependencies and many dependents. It is affected when another object is changed. Likewise, when it is changed other objects are affected.
In the first exercise, the architect runs a code review to look for the anti-patterns described above.
Exercise
In this exercise you perform the following tasks:
- Select a code review to run.
- View the rules applied in the code review.
- Choose what code to run the review on.
- Run the code review.
- View the findings of the code review.
- Select a finding to see the following information for it:
- Source code.
- Description, examples, and solutions.
Selecting a code review
To select a structural analysis code review:
- On the toolbar in the Code Review view click the Manage Rules icon,
.

- In the Select Code Review list, click Structural Analysis Code Review.
- Expand the Structural Analysis folder and subfolders to see the rules applied in the code review, as shown below. Click OK.

Selecting a code base to review
To select the workspace as the code base to review:
- On the toolbar in the Code Review view click the Review icon (
) > Review Workspace.
Running the code review
Once you select the code base to review, the code review runs. You can track its status by checking the progress bar in the lower-right corner of the view.
Viewing the code review findings
When the code review is finished, the findings are shown in the Code Review view, as shown in the following screen capture:

The following information is provided in the Code Review view.
- Code review statistics: The line above the findings displays information about the most recent code review: name, scope, number of rules and files included, and number and severity of findings.
- Code review findings: The findings in the code review are listed in the Code Review view, within folders. Each folder name tells you the code review name and the category and number of findings.
Getting more information on a code review finding
To get more information on a finding in the code review:
- Expand the Structural Analysis: Cyclic Dependency folder. It contains four findings, as shown in the following screen capture:

Each finding is preceeded by an icon that indicates its severity level.

If an icon has a lightbulb next to it (
), that means that a quick fix exists for the finding. A quick fix is an automated, supplied solution for a specific finding. The quick fix icons are shown in the following illustration:

- Double-click the finding that begins with Event.java. Details about it appear in two places, as outlined in the following points and screen capture:
- Source code: Displays the code where the finding occurs and highlights the exact location of it.
- Code Review Details view: Describes the finding in more detail and provides examples and solutions to correct it. If the finding is a cyclic dependency, there is also a section on loop details.

You have completed Exercise 1.2: Running a structural analysis code review.
Leveraging the power of a code review
By proactively running a code review you are able to spot problems early so you can also correct them early, before they cause the following problems:
- Affect your application's performance, maintenance, or scalability.
- Cost your company money, time, and resources.
In Exercise 1.4, you build on the work you did in Exercise 1.2 by fixing a code review finding.
Wrapping up Exercise 1.2
You have completed Exercise 1.2: Running a structural analysis code review. In it you performed the following tasks:
- Selected a code review to run.
- Viewed rules applied in the code review.
- Chose a body of code to run the review on.
- Ran the code review.
- Viewed the findings of the code review.
- Selected a finding to see the following information for it:
- Source code.
- Description, examples, and solutions.
Now you are ready to begin Exercise 1.3: Defining an architectural control rule.