Skip to content

Commit 15c6bc9

Browse files
Add Javadocs for graph builders, Java 25 fixtures, and HTML report helpers; remove stale parser configuration documentation
1 parent 978bfe6 commit 15c6bc9

5 files changed

Lines changed: 57 additions & 5 deletions

File tree

‎codebase-graph-builder/src/main/java/org/hjug/graphbuilder/graphbuilder/Java25ParserFactory.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
*/
2222
public final class Java25ParserFactory {
2323

24+
/** Prevents instantiation of this utility class. */
2425
private Java25ParserFactory() {
2526
// Utility class
2627
}

‎codebase-graph-builder/src/main/java/org/hjug/graphbuilder/graphbuilder/JavaSourceFileGraphBuilder.java‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
@Slf4j
4040
public class JavaSourceFileGraphBuilder implements SourceFileGraphBuilder {
4141

42+
/** Builds dependency graphs and metrics from the Java files under the supplied repository path. */
4243
@Override
4344
public CodebaseGraphDTO buildGraph(String repositoryPath, String repositoryRoot, GraphBuilderConfig config)
4445
throws IOException {
@@ -102,11 +103,6 @@ public CodebaseGraphDTO buildGraph(String repositoryPath, String repositoryRoot,
102103
* the Java 25 parser on its own whenever the runtime is 25+ and
103104
* {@code rewrite-java-25} is on the classpath.
104105
*
105-
* <p>The {@code config} parameter is retained for API stability but no
106-
* longer influences parser selection (the former force-flag escape hatch
107-
* was removed together with the reflection-based loading; parser selection
108-
* is now entirely runtime-driven).
109-
*
110106
* <p>Note: JEP 238 shadowing applies only to classes loaded from a jar.
111107
* In exploded-directory classpaths (e.g. unit tests against
112108
* {@code target/classes}) the base factory variant answers even on
@@ -120,6 +116,7 @@ static JavaParser createJavaParser() {
120116
});
121117
}
122118

119+
/** Finalizes collected metrics and assembles the Java codebase graph result. */
123120
static CodebaseGraphDTO finalizeDto(
124121
Graph<String, DefaultWeightedEdge> classReferencesGraph,
125122
Graph<String, DefaultWeightedEdge> packageReferencesGraph,
@@ -153,6 +150,7 @@ static CodebaseGraphDTO finalizeDto(
153150
getMethodDisharmonies(detector, metrics));
154151
}
155152

153+
/** Removes graph vertices whose packages were not discovered in the analyzed codebase. */
156154
static void removeClassesNotInCodebase(
157155
Set<String> packagesInCodebase, Graph<String, DefaultWeightedEdge> classReferencesGraph) {
158156
Set<String> classesToRemove = new HashSet<>();
@@ -164,6 +162,7 @@ static void removeClassesNotInCodebase(
164162
classReferencesGraph.removeAllVertices(classesToRemove);
165163
}
166164

165+
/** Removes package vertices that were not discovered in the analyzed codebase. */
167166
static void removePackagesNotInCodebase(
168167
Set<String> packagesInCodebase, Graph<String, DefaultWeightedEdge> packageReferencesGraph) {
169168
Set<String> packagesToRemove = new HashSet<>();
@@ -175,6 +174,7 @@ static void removePackagesNotInCodebase(
175174
packageReferencesGraph.removeAllVertices(packagesToRemove);
176175
}
177176

177+
/** Returns the package portion of a fully qualified class name. */
178178
static String getPackage(String fqn) {
179179
if (!fqn.contains(".")) {
180180
return "";
@@ -183,6 +183,7 @@ static String getPackage(String fqn) {
183183
return fqn.substring(0, lastIndex);
184184
}
185185

186+
/** Collects all method-level disharmonies detected for the supplied metrics. */
186187
private static List<MethodDisharmony> getMethodDisharmonies(
187188
DisharmonyDetector detector, Collection<ClassMetrics> metrics) {
188189
List<MethodDisharmony> methodDisharmonies = new ArrayList<>();
@@ -194,6 +195,7 @@ private static List<MethodDisharmony> getMethodDisharmonies(
194195
return methodDisharmonies;
195196
}
196197

198+
/** Collects class-level disharmonies, including Kotlin-specific findings when applicable. */
197199
static List<ClassDisharmony> getClassDisharmonies(
198200
DisharmonyDetector detector, Collection<ClassMetrics> metrics, boolean hasKotlinMetrics) {
199201
List<ClassDisharmony> classDisharmonies = new ArrayList<>();

‎codebase-graph-builder/src/main/java25/org/hjug/graphbuilder/graphbuilder/Java25ParserFactory.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public final class Java25ParserFactory {
2222
// annotation processing so the extra compile execution stays minimal.
2323
private static final Logger log = LoggerFactory.getLogger(Java25ParserFactory.class);
2424

25+
/** Prevents instantiation of this utility class. */
2526
private Java25ParserFactory() {
2627
// Utility class
2728
}

‎codebase-graph-builder/src/test/resources/java25SrcDirectory/com/example/java25/FlexibleConstructorBody.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ public class FlexibleConstructorBody {
99

1010
private final int value;
1111

12+
/**
13+
* Creates an instance after validating the constructor argument before delegation.
14+
*
15+
* @param raw the non-negative value to retain
16+
*/
1217
public FlexibleConstructorBody(int raw) {
1318
if (raw < 0) {
1419
throw new IllegalArgumentException("value must not be negative");
@@ -18,6 +23,7 @@ public FlexibleConstructorBody(int raw) {
1823
this.value = raw;
1924
}
2025

26+
/** Returns the value supplied at construction time. */
2127
public int getValue() {
2228
return value;
2329
}

‎report/src/main/java/org/hjug/refactorfirst/report/SimpleHtmlReport.java‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,12 +419,14 @@ public StringBuilder generateReport(
419419
return stringBuilder;
420420
}
421421

422+
/** Reads the repository's remote URL from the project Git metadata. */
422423
static String getRepoUrl(String projectBaseDir) throws Exception {
423424
try (GitLogReader glr = new GitLogReader(new File(projectBaseDir))) {
424425
return glr.getRepoUrl();
425426
}
426427
}
427428

429+
/** Builds the report navigation menu for the available graphs, findings, and cycles. */
428430
StringBuilder createMenu(
429431
List<DisharmonySpec> disharmonySpecs,
430432
Map<String, List<RankedDisharmony>> rankedDisharmoniesByAnchor,
@@ -478,10 +480,13 @@ StringBuilder createMenu(
478480
return menu;
479481
}
480482

483+
/** Extension hook for adding a class-map entry to the navigation menu. */
481484
void renderClassMapMenu(StringBuilder stringBuilder) {}
482485

486+
/** Extension hook for adding a package-map entry to the navigation menu. */
483487
void renderPackageMapMenu(StringBuilder stringBuilder) {}
484488

489+
/** Renders the class-cycle summary and the largest cycle's details. */
485490
private String renderCycles(List<RankedCycle> rankedCycles, String repoUrl, CodebaseGraphDTO codebaseGraphDTO) {
486491
StringBuilder stringBuilder = new StringBuilder();
487492
stringBuilder.append(renderClassCycleSummary(rankedCycles));
@@ -494,6 +499,7 @@ private String renderCycles(List<RankedCycle> rankedCycles, String repoUrl, Code
494499
return stringBuilder.toString();
495500
}
496501

502+
/** Renders the prioritized class relationships whose removal breaks cycles. */
497503
private String renderClassEdgeDisharmonies(
498504
List<RankedDisharmony> classRelationshipDisharmonies,
499505
List<RankedDisharmony> packageRelationshipDisharmonies,
@@ -548,6 +554,7 @@ private String renderClassEdgeDisharmonies(
548554
return stringBuilder.toString();
549555
}
550556

557+
/** Renders the prioritized package relationships whose removal breaks cycles. */
551558
private String renderPackageEdgeDisharmonies(
552559
List<RankedDisharmony> edgeDisharmonies, String repoUrl, CodebaseGraphDTO codebaseGraphDTO) {
553560
StringBuilder stringBuilder = new StringBuilder();
@@ -599,6 +606,7 @@ private String renderPackageEdgeDisharmonies(
599606
return stringBuilder.toString();
600607
}
601608

609+
/** Returns column headings for the class-relationship table. */
602610
private String[] getClassRelationshipDisharmonyTableHeadings() {
603611
return new String[] {
604612
"Class Relationship",
@@ -610,6 +618,7 @@ private String[] getClassRelationshipDisharmonyTableHeadings() {
610618
};
611619
}
612620

621+
/** Returns column headings for the package-relationship table. */
613622
private String[] getPackageRelationshipDisharmonyTableHeadings() {
614623
return new String[] {
615624
"Package Relationship",
@@ -656,6 +665,7 @@ String[] getPackageRelationshipDisharmony(
656665
};
657666
}
658667

668+
/** Renders summary rows for the ranked class cycles. */
659669
private String renderClassCycleSummary(List<RankedCycle> rankedCycles) {
660670
StringBuilder stringBuilder = new StringBuilder();
661671

@@ -704,6 +714,7 @@ String renderClassEdge(DefaultWeightedEdge edge) {
704714
.toString();
705715
}
706716

717+
/** Renders a weighted class edge with repository links and removal markers. */
707718
private String renderClassEdge(DefaultWeightedEdge edge, String repoUrl, CodebaseGraphDTO codebaseGraphDTO) {
708719
StringBuilder edgesToCut = new StringBuilder();
709720
String[] vertexes = extractVertexes(edge);
@@ -730,6 +741,7 @@ private String renderClassEdge(DefaultWeightedEdge edge, String repoUrl, Codebas
730741
.toString();
731742
}
732743

744+
/** Renders a weighted package edge with removal markers. */
733745
private String renderPackageEdge(DefaultWeightedEdge edge, String repoUrl, CodebaseGraphDTO codebaseGraphDTO) {
734746
StringBuilder edgesToCut = new StringBuilder();
735747
String[] vertexes = extractVertexes(edge);
@@ -756,6 +768,7 @@ private String renderPackageEdge(DefaultWeightedEdge edge, String repoUrl, Codeb
756768
.toString();
757769
}
758770

771+
/** Links a class label to its source file when a source-path mapping is available. */
759772
String hyperlinkClass(String className, String repoUrl, CodebaseGraphDTO codebaseGraphDTO) {
760773
String path = codebaseGraphDTO.getClassToSourceFilePathMapping().get(className);
761774
if (path == null || path.isBlank()) {
@@ -783,6 +796,7 @@ static String escapeHtmlAttribute(String value) {
783796
return escapeHtmlLabel(value).replace("\"", "&quot;").replace("'", "&#39;");
784797
}
785798

799+
/** Returns column headings for the class-cycle summary table. */
786800
private String[] getClassCycleSummaryTableHeadings() {
787801
return new String[] {"Cycle Name", "Priority", "Class Count", "Relationship Count"};
788802
}
@@ -798,6 +812,7 @@ String[] getRankedCycleSummaryData(RankedCycle rankedCycle) {
798812
};
799813
}
800814

815+
/** Renders the visualization and relationship table for one class cycle. */
801816
private String renderSingleCycle(RankedCycle cycle, String repoUrl, CodebaseGraphDTO codebaseGraphDTO) {
802817
StringBuilder stringBuilder = new StringBuilder();
803818

@@ -878,18 +893,22 @@ private String renderSingleCycle(RankedCycle cycle, String repoUrl, CodebaseGrap
878893
return stringBuilder.toString();
879894
}
880895

896+
/** Extension hook for rendering class-graph visuals. */
881897
public String renderClassGraphVisuals(String repoUrl, CodebaseGraphDTO codebaseGraphDTO) {
882898
return ""; // empty on purpose
883899
}
884900

901+
/** Extension hook for rendering package-graph visuals. */
885902
public String renderPackageGraphVisuals(String repoUrl, CodebaseGraphDTO codebaseGraphDTO) {
886903
return ""; // empty on purpose
887904
}
888905

906+
/** Extension hook for rendering a class-cycle visualization. */
889907
public String renderClassCycleVisuals(RankedCycle cycle, String repoUrl, CodebaseGraphDTO codebaseGraphDTO) {
890908
return ""; // empty on purpose
891909
}
892910

911+
/** Renders a table cell, right-aligning numeric and date-like values. */
893912
String drawTableCell(String rowData) {
894913
if (isNumber(rowData) || isDateTime(rowData)) {
895914
return "<td align=\"right\">" + rowData + "</td>\n";
@@ -898,30 +917,37 @@ String drawTableCell(String rowData) {
898917
}
899918
}
900919

920+
/** Reports whether a table value is a signed integer or decimal number. */
901921
boolean isNumber(String rowData) {
902922
return rowData.matches("-?\\d+(\\.\\d+)?");
903923
}
904924

925+
/** Reports whether a table value uses the localized date-time delimiter. */
905926
boolean isDateTime(String rowData) {
906927
return rowData.contains(", ");
907928
}
908929

930+
/** Extension hook for rendering the HTML title element. */
909931
public String printTitle(String projectName, String projectVersion) {
910932
return ""; // empty on purpose
911933
}
912934

935+
/** Extension hook for rendering additional HTML head content. */
913936
public String printHead() {
914937
return ""; // empty on purpose
915938
}
916939

940+
/** Extension hook for rendering script elements. */
917941
String printScripts() {
918942
return ""; // empty on purpose
919943
}
920944

945+
/** Returns the opening body tag used by the report page. */
921946
public String printOpenBodyTag() {
922947
return " <body class=\"composite\">\n";
923948
}
924949

950+
/** Returns the opening banner and breadcrumb markup. */
925951
public String printBreadcrumbs() {
926952
return """
927953
<div id="banner">
@@ -931,6 +957,7 @@ public String printBreadcrumbs() {
931957
""";
932958
}
933959

960+
/** Renders the project heading with links to RefactorFirst and the analyzed repository. */
934961
public String printProjectHeader(String projectName, String projectVersion, String projectBaseDir)
935962
throws Exception {
936963
String repoUrl = getRepoUrl(projectBaseDir);
@@ -945,6 +972,7 @@ public String printProjectHeader(String projectName, String projectVersion, Stri
945972
+ projectVersion + "</a></h1>\n";
946973
}
947974

975+
/** Renders the report footer with the current publication timestamp. */
948976
public String printProjectFooter() {
949977
return " <div class=\"clear\">\n" + " <hr/>\n" + " </div>\n"
950978
+ "<span id=\"publishDate\">Last Published: "
@@ -953,6 +981,7 @@ public String printProjectFooter() {
953981
+ " <hr/>\n" + " </div>\n" + "</span>";
954982
}
955983

984+
/** Renders links for common RefactorFirst GitHub actions. */
956985
String renderGithubButtons() {
957986
return """
958987
<div align="center">
@@ -965,6 +994,7 @@ String renderGithubButtons() {
965994
</div>""";
966995
}
967996

997+
/** Returns the base filename for the generated report. */
968998
String getOutputName() {
969999
// This report will generate simple-report.html when invoked in a project with `mvn site`
9701000
return "refactor-first-report";
@@ -1099,6 +1129,7 @@ public String renderDisharmonyInfo(
10991129
return sb.toString();
11001130
}
11011131

1132+
/** Removes package qualifiers and verbose generic bounds from a method signature. */
11021133
String getSimpleMethodSignature(String sig) {
11031134
if (sig == null) {
11041135
return null;
@@ -1149,6 +1180,7 @@ String getSimpleMethodSignature(String sig) {
11491180
// upWaitQueue(com.tonikelope.megabasterd.Transference) ↔
11501181
// TransferenceManager.downWaitQueue(com.tonikelope.megabasterd.Transference)
11511182
// should become upWaitQueue(Transference) ↔ TransferenceManager.downWaitQueue(Transference)
1183+
/** Simplifies fully qualified parameter types in a duplication-partner description. */
11521184
String simplifyDuplicatePartners(String duplicationPartners) {
11531185
if (duplicationPartners == null) {
11541186
return null;
@@ -1175,10 +1207,12 @@ String simplifyDuplicatePartners(String duplicationPartners) {
11751207
return String.join(" ↔ ", simplifiedParts);
11761208
}
11771209

1210+
/** Extension hook for rendering a chart for one disharmony category. */
11781211
String renderDisharmonyChart(String anchorId, String title, List<RankedDisharmony> ranked, int maxPriority) {
11791212
return ""; // empty on purpose; overridden in HtmlReport
11801213
}
11811214

1215+
/** Returns the simple class name from a fully qualified class name. */
11821216
String getClassName(String fqn) {
11831217
// handle no package
11841218
if (!fqn.contains(".")) {
@@ -1189,6 +1223,7 @@ String getClassName(String fqn) {
11891223
return fqn.substring(lastIndex + 1);
11901224
}
11911225

1226+
/** Extracts the source and target vertex labels from an edge's string representation. */
11921227
static String[] extractVertexes(DefaultWeightedEdge edge) {
11931228
return edge.toString().replace("(", "").replace(")", "").split(":");
11941229
}
@@ -1201,6 +1236,7 @@ static final class DisharmonySpec {
12011236
final String problem;
12021237
final String solution;
12031238

1239+
/** Creates the display metadata for one supported disharmony category. */
12041240
DisharmonySpec(
12051241
String type, String anchorId, String title, boolean methodLevel, String problem, String solution) {
12061242
this.type = type;
@@ -1211,26 +1247,32 @@ static final class DisharmonySpec {
12111247
this.solution = solution;
12121248
}
12131249

1250+
/** Returns the disharmony type identifier. */
12141251
String type() {
12151252
return type;
12161253
}
12171254

1255+
/** Returns the HTML anchor identifier. */
12181256
String anchorId() {
12191257
return anchorId;
12201258
}
12211259

1260+
/** Returns the display title. */
12221261
String title() {
12231262
return title;
12241263
}
12251264

1265+
/** Reports whether the disharmony describes methods rather than classes. */
12261266
boolean methodLevel() {
12271267
return methodLevel;
12281268
}
12291269

1270+
/** Returns the problem description. */
12301271
String problem() {
12311272
return problem;
12321273
}
12331274

1275+
/** Returns the recommended remediation. */
12341276
String solution() {
12351277
return solution;
12361278
}

0 commit comments

Comments
 (0)