Overview of Code Quality and Using Eclipse Plugins for Static Analysis
This article introduces five key aspects of Java code quality—coding standards, duplicate code, test coverage, dependency analysis, and complexity analysis—and demonstrates how Eclipse plugins such as CheckStyle, PMD, EclEmma, JDepend, and Metrics can be configured and used to assess and improve each aspect.
How can you tell whether a project's code is well‑written or poor? This article provides a brief introduction to code quality, covering five essential dimensions: coding standards, code duplication, test coverage, dependency analysis, and complexity analysis.
For each dimension, the article lists Eclipse plugins that help address the issues: CheckStyle for coding standards, PMD's CPD for duplicate code detection, EclEmma for measuring test coverage, JDepend for analyzing package dependencies, and the Metrics plugin for assessing code complexity.
Coding Standards (CheckStyle) – After installing the CheckStyle plugin, a simple POJO class is examined, revealing warnings such as missing package‑info.java , missing Javadoc comments, and style violations. The article explains how to customize the CheckStyle configuration by importing an external XML file, disabling unwanted rules, and adjusting settings for package‑info, Javadoc, and final modifiers.
Duplicate Code (PMD CPD) – PMD’s Copy‑Paste Detector (CPD) identifies duplicated code fragments in a project; the results can be inspected and refactored into shared methods or components.
Test Coverage (EclEmma) – By running JUnit tests with the Coverage As → JUnit Test option, EclEmma reports the percentage of code exercised by tests, highlighting uncovered areas that may represent quality blind spots.
Dependency Analysis (JDepend) – JDepend evaluates package and class dependencies, providing metrics such as number of classes (CC), abstract classes (AC), afferent couplings (Ca), efferent couplings (Ce), abstractness (A), instability (I), distance (D), and cycles, helping developers identify unstable or overly coupled packages.
Complexity Analysis (Metrics) – The Metrics view, once enabled, displays complexity indicators for classes and methods, allowing developers to pinpoint overly complex code and guide refactoring efforts.
In summary, the article emphasizes that improving code quality involves configuring appropriate static‑analysis rules, addressing warnings that matter to the project, and integrating local checks with continuous‑integration tools such as Hudson.
Qunar Tech Salon
Qunar Tech Salon is a learning and exchange platform for Qunar engineers and industry peers. We share cutting-edge technology trends and topics, providing a free platform for mid-to-senior technical professionals to exchange and learn.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.