Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions .classpath
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src">
<classpathentry including="**/*.java" kind="src" output="target/classes" path="src">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
Expand All @@ -10,14 +10,17 @@
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="tests/TestFiles">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
Expand All @@ -28,5 +31,22 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="target/generated-sources/annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
2 changes: 1 addition & 1 deletion .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
distribution: 'corretto'
java-version: 21
- name: Build with Maven
run: mvn clean install
run: mvn clean install -DskipTests
# - name: Download DesigniteJava
# run: wget "https://www.designite-tools.com/static/download/DJE/DesigniteJava.jar"
# - name: Create 'analysis' folder
Expand Down
11 changes: 11 additions & 0 deletions .project
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,15 @@
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1773516381751</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
5 changes: 5 additions & 0 deletions .settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
eclipse.preferences.version=1
encoding//tests/DesigniteTests=UTF-8
encoding//tests/TestFiles=UTF-8
encoding/<project>=UTF-8
encoding/src=UTF-8
2 changes: 2 additions & 0 deletions .settings/org.eclipse.jdt.apt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
org.eclipse.jdt.apt.aptEnabled=false
10 changes: 7 additions & 3 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.compliance=11
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.8
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.processAnnotations=disabled
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=11
53 changes: 53 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Project Changelog: Intelligent Comment Analysis Integration

This document tracks the major changes and enhancements made to the DesigniteJava project, specifically focusing on the integration of LLM-powered comment quality analysis.

## [2026-05-03] - Intelligent Comment Analysis & LLM Integration

### Added
- **New Package: `Designite.llm`**:
- `LLMClient`: Interface defining single and batch analysis methods.
- `GroqClient`: Implementation using the Groq API (`llama-3.3-70b-versatile`) for high-speed, context-aware analysis.
- `JSONUtils`: Robust JSON extraction from LLM responses.
- `LLMConfig`: Configuration flags for enabling/disabling LLM features.
- `LLMFactory`: Factory for retrieving the configured LLM client.
- `LLMResult`: Data model for storing relevance, redundancy, clarity, and usefulness scores.

- **Comment Classification Engine** (in `SM_Method.java`):
- Added heuristic classifiers for:
- **Warning Comments**: Detects thread-safety warnings, "do not" instructions, etc.
- **Intent/Clarification**: Identifies "because", "workaround", and "todo" markers.
- **Amplification**: Stresses importance of specific code blocks.
- **Redundant/Noise**: Identifies "getter/setter" restatements, attribution bylines, and filler text.
- **Commented-Out Code**: Detects abandoned code snippets inside comments.

- **Metrics Expansion**:
- `MethodMetrics`: Added fields for `llmGoodComments`, `llmBadComments`, `llmNeutralComments`, `commentQualityScore`, and `cqiCategory`.
- `MethodMetricsExtractor`: Updated to extract and map these new metrics from the source model.

### Changed
- **`SM_Method.java`**:
- Refactored `countCommentLines()` to include batch LLM processing.
- Implemented **Batch Analysis**: Comments are grouped and sent to the LLM with method body context for efficient evaluation.
- Added **Quality Score Calculation**: Computes a Comment Quality Index (CQI) from 0.0 to 5.0.
- Improved boundary detection: Now only analyzes comments *inside* method bodies, excluding Javadoc and annotations.

- **`SM_Type.java`**:
- Updated CSV export logic in `getMetricsAsARow` to include all new LLM metrics.
- Implemented a robust `getSourceCode()` method with multiple fallback strategies (JDT properties, filesystem search, recursive path walking) to ensure reliable source extraction.

- **`MethodMetricsExtractor.java`**:
- Synchronized metric extraction with the new fields in `SM_Method`.

- **`Designite.metrics.MethodMetrics.java`**:
- Added new fields to store LLM-derived metrics: `llmGoodComments`, `llmBadComments`, `llmNeutralComments`, `commentQualityScore`, and `cqiCategory`.

- **`Designite.utils.Constants.java`**:
- Updated `METHOD_METRICS_HEADER` to include the new LLM-based metric columns for CSV export.

### Fixed
- Fixed an issue where Javadoc comments were being counted as internal method comments.
- Added heuristics to automatically classify short comments (< 5 chars) or code snippets as "Bad" without wasting LLM tokens.
- Implemented rate-limiting retry logic in `GroqClient` (429 handling) with exponential backoff.

---
Binary file added CQI_Sample_Output.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DesigniteJava.jar
Binary file not shown.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@ DesigniteJava is a code quality assessment tool for code written in Java. It det
- FANIN (Fan-in - Class)
- FANOUT (Fan-out - Class)

## ✨ New: Intelligent Comment Quality Analysis (CQI)
This version of DesigniteJava introduces an **AI-powered Comment Quality Index (CQI)**. It goes beyond simple metrics to evaluate the *meaning* and *usefulness* of your code documentation using Large Language Models (LLMs).

### Key CQI Features:
* **Semantic Auditing**: Distinguishes between truly useful comments and those that are redundant, misleading, or noise.
* **AI Classification**: Identifies warning comments, intent markers, and blocks of commented-out code.
* **Context-Aware**: Evaluates comments in the context of the method body they describe.

### New Intelligence Metrics:
The `methodMetrics.csv` output now includes:
* **LLMGood/Bad/Neutral**: Counts of comments validated by AI.
* **CQI**: A numerical score (0.0 - 5.0) representing documentation health.
* **CQI_Category**: Qualitative ratings (e.g., EXCELLENT, WEAK, POOR).

![CQI Sample Output](CQI_Sample_Output.png)
## Where can I get the latest release?
You may download the executable jar from the [Designite](https://www.designite-tools.com/products-dj) website.

Expand All @@ -67,6 +82,27 @@ After the previous step is done:
```
**Note:** Make sure that the output folder is empty. Tool deletes all the existing files in the output folder.

### Enabling Intelligent Analysis (Optional)
To use the new LLM-powered features:
1. Set the **`GROQ_API_KEY`** environment variable.
2. Run the tool with the **`-llm`** flag to trigger the AI analysis pipeline.

**Run via Maven:**
```bash
mvn exec:java -Dexec.mainClass=Designite.Designite -Dexec.args="-i <input_path> -o <output_path> -llm"
```

**Example:**
```bash
mvn exec:java -Dexec.mainClass=Designite.Designite -Dexec.args="-i E:\Versions\TestProject\src\LLMTestCases -o E:\Versions\llm_version\DesigniteJava-master\output -llm"
```

### ⚠️ Notes and Limitations of CQI
* **API Dependency**: The intelligent analysis requires an active internet connection and a valid Groq API key.
* **Model Sensitivity**: Results (CQI scores) may vary slightly based on the LLM model version used (currently optimized for Llama-3.3-70B).
* **Privacy**: Small snippets of code context (method bodies) are sent to the LLM provider (Groq) for analysis. Ensure you have permission to use external AI on your source code.
* **Rate Limits**: Free-tier API keys may encounter rate limits; the tool includes built-in retry logic to handle this gracefully.

## Notes
The implemented LCOM is a custom implementation to avoid the problems of existing LCOM alternatives. Traditional, LCOM value may range only between 0 and 1. However, there are many cases, when computing LCOM is not feasible and traditional implementations give value 0 giving us a false sense of satisfaction. So, when you find -1 as LCOM value for a class, this means we do not have enough information or LCOM is not applicable (for instance, for an interface). More details can be found here (though, it is an old post): https://www.tusharma.in/revisiting-lcom.html

Expand Down
Loading