Skip to content

Commit 46a90c6

Browse files
committed
fix source file path searching
1 parent 70a1175 commit 46a90c6

File tree

4 files changed

+55
-4
lines changed

4 files changed

+55
-4
lines changed

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,27 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.3.2] - 2025-06-02
9+
10+
### 🐛 Critical Bug Fix - Inner Class Source Resolution
11+
- **Fixed SOURCE_FILE_NOT_FOUND for Inner Classes**: Major fix for source file detection of inner classes
12+
- **Problem**: Classes like `org.apache.commons.cli.HelpFormatter.Builder` were causing SOURCE_FILE_NOT_FOUND errors
13+
- **Root Cause**: Method was searching for `org/apache/commons/cli/HelpFormatter/Builder.java` instead of `org/apache/commons/cli/HelpFormatter.java`
14+
- **Solution**: Enhanced `getSourceFilePathForClass()` to detect inner classes and map them to their outer class source files
15+
- **Impact**: Dramatically reduces SOURCE_FILE_NOT_FOUND errors in projects with inner classes
16+
17+
### 🔧 Technical Improvements
18+
- **Smart Inner Class Detection**: Added logic to identify inner classes by uppercase naming patterns
19+
- **Outer Class Mapping**: Automatically strips inner class portions to find the correct source file
20+
- **Enhanced Debug Logging**: Added detailed logging for source file resolution process
21+
22+
### 🧪 Verification
23+
- **commons-cli Project**: Tested on Apache Commons CLI project - eliminated most SOURCE_FILE_NOT_FOUND errors
24+
- **Before**: Multiple SOURCE_FILE_NOT_FOUND errors for `HelpFormatter.Builder` methods
25+
- **After**: All inner class methods now correctly resolve to their source files
26+
27+
This fix significantly improves analysis accuracy for projects using inner classes, which are common in Java projects.
28+
829
## [1.3.1] - 2025-06-02
930

1031
### 🐛 Bug Fixes - Windows Path Compatibility

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ application {
1717
}
1818

1919
group = 'edu.stevens'
20-
version = '1.3.1'
20+
version = '1.3.2'
2121

2222
dependencies {
2323
// Use JitPack dependency for release builds

src/main/java/edu/stevens/swe/research/java/cli/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import edu.stevens.swe.research.java.cli.analyzer.ResultFormatter;
1717
import edu.stevens.swe.research.java.cli.analyzer.LogData;
1818

19-
@Command(name = "analyzer", mixinStandardHelpOptions = true, version = "Analyzer CLI 1.3.1",
19+
@Command(name = "analyzer", mixinStandardHelpOptions = true, version = "Analyzer CLI 1.3.2",
2020
description = "Analyzes Java source code based on specified tasks.")
2121
public class Main implements Callable<Integer> {
2222

src/main/java/edu/stevens/swe/research/java/cli/analyzer/core/TestCaseAnalyzer.java

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,36 @@ private boolean isTestCode(String filePath) {
405405
// Utility from old MethodAnalyzer to find source file for a class.
406406
// This might need to be made more robust or use ProjectCtx information.
407407
public String getSourceFilePathForClass(String className, String sourceRootPath) {
408-
String classPath = className.replace('.', File.separatorChar) + ".java";
408+
// Handle inner classes: for inner classes like "com.example.Outer.Inner",
409+
// we need to find the file for "com.example.Outer.java"
410+
String outerClassName = className;
411+
if (className.contains(".") && Character.isUpperCase(className.charAt(className.lastIndexOf('.') + 1))) {
412+
// This might be an inner class. Find the outer class.
413+
// Look for pattern like "package.Class.InnerClass" where the last part starts with uppercase
414+
String[] parts = className.split("\\.");
415+
StringBuilder outerClassBuilder = new StringBuilder();
416+
417+
for (int i = 0; i < parts.length; i++) {
418+
if (i > 0 && Character.isUpperCase(parts[i].charAt(0))) {
419+
// Found first part that starts with uppercase, this might be the start of class names
420+
// Check if we already have a class name (outer class)
421+
if (outerClassBuilder.length() > 0 && Character.isUpperCase(parts[i-1].charAt(0))) {
422+
// Previous part was also a class name, so current part is inner class
423+
break;
424+
}
425+
}
426+
427+
if (outerClassBuilder.length() > 0) {
428+
outerClassBuilder.append(".");
429+
}
430+
outerClassBuilder.append(parts[i]);
431+
}
432+
outerClassName = outerClassBuilder.toString();
433+
}
434+
435+
System.out.println("DEBUG: Looking for source file - Original class: " + className + ", Outer class: " + outerClassName);
436+
437+
String classPath = outerClassName.replace('.', File.separatorChar) + ".java";
409438
Path effectiveSourceRoot = Paths.get(sourceRootPath);
410439

411440
// Attempt to find in standard main/java or test/java if sourceRootPath is project root
@@ -434,13 +463,14 @@ public String getSourceFilePathForClass(String className, String sourceRootPath)
434463
.collect(Collectors.toList());
435464
if (!foundPaths.isEmpty()) {
436465
// Prefer paths that match more closely or handle multiple matches if necessary
466+
System.out.println("DEBUG: Found source file: " + foundPaths.get(0).toString());
437467
return foundPaths.get(0).toString();
438468
}
439469
} catch (IOException e) {
440470
System.err.println("Error walking path: " + root + " : " + e.getMessage());
441471
}
442472
}
443-
System.err.println("Warning: Source file not found for class " + className + " under roots: " + potentialSourceRoots);
473+
System.err.println("Warning: Source file not found for class " + className + " (searched as " + outerClassName + ") under roots: " + potentialSourceRoots);
444474
return null;
445475
}
446476

0 commit comments

Comments
 (0)