Skip to content

Commit da98cd0

Browse files
Merge pull request #210 from refactorfirst/fix-javadocs-for-release-0.10.0
Fixing JavaDocs
2 parents ac8e00b + 91e0e9f commit da98cd0

13 files changed

Lines changed: 204 additions & 54 deletions

File tree

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
import org.jgrapht.Graph;
1313
import org.jgrapht.graph.DefaultWeightedEdge;
1414

15+
/**
16+
* Data transfer object containing the complete codebase graph analysis results.
17+
* Includes class and package reference graphs, class-to-package relationships,
18+
* source file mappings, and detected disharmonies (antipatterns).
19+
*/
1520
@Getter
1621
@EqualsAndHashCode
1722
@ToString
@@ -26,6 +31,16 @@ public class CodebaseGraphDTO {
2631
private final List<ClassDisharmony> classDisharmonies;
2732
private final List<MethodDisharmony> methodDisharmonies;
2833

34+
/**
35+
* Creates a new CodebaseGraphDTO.
36+
*
37+
* @param classReferencesGraph the class reference graph
38+
* @param packageReferencesGraph the package reference graph
39+
* @param classRelationshipsInPackageRelationship the class-to-package relationships
40+
* @param classToSourceFilePathMapping the class to source file path mapping
41+
* @param classDisharmonies the list of class disharmonies
42+
* @param methodDisharmonies the list of method disharmonies
43+
*/
2944
public CodebaseGraphDTO(
3045
Graph<String, DefaultWeightedEdge> classReferencesGraph,
3146
Graph<String, DefaultWeightedEdge> packageReferencesGraph,
@@ -41,12 +56,24 @@ public CodebaseGraphDTO(
4156
this.methodDisharmonies = methodDisharmonies;
4257
}
4358

59+
/**
60+
* Returns class disharmonies filtered by type.
61+
*
62+
* @param disharmonyType the disharmony type to filter by
63+
* @return list of matching class disharmonies
64+
*/
4465
public List<ClassDisharmony> getClassDisharmoniesOfType(String disharmonyType) {
4566
return classDisharmonies.stream()
4667
.filter(d -> disharmonyType.equals(d.getDisharmonyType()))
4768
.collect(Collectors.toList());
4869
}
4970

71+
/**
72+
* Returns method disharmonies filtered by type.
73+
*
74+
* @param disharmonyType the disharmony type to filter by
75+
* @return list of matching method disharmonies
76+
*/
5077
public List<MethodDisharmony> getMethodDisharmoniesOfType(String disharmonyType) {
5178
return methodDisharmonies.stream()
5279
.filter(d -> disharmonyType.equals(d.getDisharmonyType()))

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@
2626
public class CompositeGraphBuilder {
2727

2828
/**
29-
* Build a unified {@link CodebaseGraphDTO} from a directory that may contain
30-
* both Java and Kotlin source files.
29+
* Builds a unified graph for Java and Kotlin source files in a repository.
3130
*
32-
* @param repositoryPath path to the source directory
33-
* @param excludeTests whether to exclude test files
31+
* @param repositoryPath path to the source directory
32+
* @param excludeTests whether to exclude test files
3433
* @param testSourceDirectory test source directory pattern
35-
* @return a merged CodebaseGraphDTO
36-
* @throws IOException if parsing fails
34+
* @return the combined Java and Kotlin codebase graph
35+
* @throws IllegalArgumentException if {@code repositoryPath} is null or empty
36+
* @throws IOException if source analysis fails
3737
*/
3838
public CodebaseGraphDTO getCodebaseGraphDTO(String repositoryPath, boolean excludeTests, String testSourceDirectory)
3939
throws IOException {
@@ -49,6 +49,15 @@ public CodebaseGraphDTO getCodebaseGraphDTO(String repositoryPath, boolean exclu
4949
return getCodebaseGraphDTO(repositoryPath, config);
5050
}
5151

52+
/**
53+
* Build a unified {@link CodebaseGraphDTO} from a directory that may contain
54+
* both Java and Kotlin source files.
55+
*
56+
* @param repositoryPath path to the source directory
57+
* @param config graph-builder configuration
58+
* @return a merged CodebaseGraphDTO
59+
* @throws IOException if parsing fails
60+
*/
5261
public CodebaseGraphDTO getCodebaseGraphDTO(String repositoryPath, GraphBuilderConfig config) throws IOException {
5362
String repositoryRoot = config.getRepositoryRoot() != null ? config.getRepositoryRoot() : "";
5463
return getCodebaseGraphDTO(repositoryPath, repositoryRoot, config);

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
import org.jgrapht.graph.DefaultWeightedEdge;
44

5+
/**
6+
* Interface for collecting dependencies between classes and packages during
7+
* source file analysis. Implementations build the class and package reference
8+
* graphs used by the graph builder.
9+
*/
510
// TODO: Revisit - I don't think this is really needed
611
public interface DependencyCollector {
712

@@ -18,6 +23,7 @@ public interface DependencyCollector {
1823
*
1924
* @param fromPackageName The package that depends on another
2025
* @param toPackageName The package being depended upon
26+
* @return the package dependency edge, or {@code null} when no package edge is created
2127
*/
2228
DefaultWeightedEdge addPackageDependency(String fromPackageName, String toPackageName);
2329

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
/**
2929
* Kotlin-language source-file graph builder. Invoked unconditionally by
30-
* {@link CompositeGraphBuilder} (Kotlin analysis is always on). This
30+
* {@link org.hjug.graphbuilder.CompositeGraphBuilder} (Kotlin analysis is always on). This
3131
* module declares a compile dependency on
3232
* {@code org.openrewrite:rewrite-kotlin}, so the Kotlin parser is always
3333
* on the classpath of any consumer of this builder.

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,10 @@ public void addMethod(MethodMetrics methodMetrics) {
369369
/**
370370
* Aggregated class-level count of Kotlin/Java callable references
371371
* ({@code Klass::method}) across all declared methods. Returns the sum
372-
* of {@link MethodMetrics#getNumberOfCallableReferences()} across every
372+
* of {@code MethodMetrics#getNumberOfCallableReferences()} across every
373373
* method on this class.
374+
*
375+
* @return the total number of callable references
374376
*/
375377
public int getNumberOfCallableReferences() {
376378
return methods.values().stream()

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,31 @@
44
import org.openrewrite.java.JavaIsoVisitor;
55
import org.openrewrite.java.tree.J;
66

7+
/**
8+
* Calculates cyclomatic complexity and maximum nesting depth for a method
9+
* by visiting its AST nodes. Extends {@link JavaIsoVisitor} to traverse
10+
* the OpenRewrite Java AST.
11+
*/
712
public class ComplexityCalculator extends JavaIsoVisitor<ExecutionContext> {
813

914
private int cyclomaticComplexity = 1;
1015
private int nestingLevel = 0;
1116
private int maxNestingDepth = 0;
1217

18+
/**
19+
* Provides the calculated cyclomatic complexity.
20+
*
21+
* @return the cyclomatic complexity
22+
*/
1323
public int getCyclomaticComplexity() {
1424
return cyclomaticComplexity;
1525
}
1626

27+
/**
28+
* Returns the calculated maximum nesting depth.
29+
*
30+
* @return the maximum nesting depth
31+
*/
1732
public int getMaxNestingDepth() {
1833
return maxNestingDepth;
1934
}

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@
44
import lombok.Data;
55
import org.hjug.graphbuilder.metrics.DisharmonyMetric.Direction;
66

7+
/**
8+
* Detects disharmonies (code smells / antipatterns) in the collected class and
9+
* method metrics. Based on the HIDOOP / DECOR / Lanza-Marinescu catalog.
10+
*
11+
* <p>This class is a pure function of the {@link ClassMetrics} and {@link
12+
* MethodMetrics} populations produced by {@link GraphMetricsCollector}. It has
13+
* no side effects and no external dependencies.
14+
*
15+
* <p>Threshold constants (FEW, HALF, ONE_THIRD, etc.) are defined at the top
16+
* of the class and tuned to the literature values cited in the Lanza-Marinescu
17+
* book. They can be adjusted for specific codebase characteristics if needed.
18+
*/
719
public class DisharmonyDetector {
820

921
// Linguistic quantifiers (Lanza & Marinescu, Table 2.4)
@@ -371,8 +383,10 @@ public boolean isBrainMethod(MethodMetrics metrics) {
371383
}
372384

373385
/**
374-
* Feature Envy (Fig. 5.4): method accesses more foreign data than local data.
375-
* ATFD &gt; FEW AND LAA &lt; ONE_THIRD AND FDP &lt;= FEW
386+
* Identifies methods that access substantially more foreign data than local data.
387+
*
388+
* @param metrics the method metrics to evaluate
389+
* @return {@code true} if the method has feature envy, {@code false} otherwise
376390
*/
377391
public boolean hasFeatureEnvy(MethodMetrics metrics) {
378392
return metrics.getAccessToForeignData() > FEW

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

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ public void recordMethodMetric(String className, String methodSignature, String
153153

154154
/**
155155
* Returns {@code true} iff at least one collected {@link ClassMetrics}
156-
* carries a Kotlin-specific signal — i.e. {@link ClassMetrics#isDataClass()},
157-
* {@link ClassMetrics#isSealed()}, {@link ClassMetrics#getNumberOfExtensionFunctions()}
156+
* carries a Kotlin-specific signal — i.e. {@code ClassMetrics#isDataClass()},
157+
* {@code ClassMetrics#isSealed()}, {@code ClassMetrics#getNumberOfExtensionFunctions()}
158158
* > 0, a non-empty {@link ClassMetrics#getExtensionReceiverTypes()}, or a
159159
* non-empty {@link ClassMetrics#getSealedHierarchyAncestors()}.
160160
*
@@ -174,7 +174,7 @@ public void recordMethodMetric(String className, String methodSignature, String
174174
* only after {@link #finalizeMetrics()} has run (detection always runs
175175
* post-finalization); before finalization the cached value is still
176176
* computed on demand but may not reflect {@link #computeKotlinDerivedMetrics()}
177-
* derived flags such as {@link ClassMetrics#isHasExplicitLogic()}.
177+
* derived flags such as {@code ClassMetrics#isHasExplicitLogic()}.
178178
*
179179
* @return {@code true} if any class carries a Kotlin-specific metric signal,
180180
* {@code false} for an empty or Java-only collector
@@ -199,11 +199,9 @@ public boolean hasKotlinMetrics() {
199199
}
200200

201201
/**
202-
* Read-only lookup of a class's metrics. Returns {@code null} when the
203-
* class has never been registered with this collector. Prefer
204-
* {@link #getOrCreateClassMetrics(String)} from visitor logic that
205-
* intends to mutate the returned instance and have the mutation
206-
* reflected by {@link #getAllClassMetrics()}.
202+
* Looks up the metrics recorded for a class.
203+
*
204+
* @return the class metrics, or {@code null} if no metrics are recorded
207205
*/
208206
public ClassMetrics getClassMetrics(String className) {
209207
return classMetrics.get(className);
@@ -315,20 +313,10 @@ private int computeSealedDepth(ClassMetrics metrics) {
315313
}
316314

317315
/**
318-
* Canonical get-or-create entry point used by {@link MetricsVisitorLogic}
319-
* and the metrics-collecting visitors. Returns the existing
320-
* {@link ClassMetrics} for {@code className} if present, otherwise
321-
* creates one, stores it in {@link #getAllClassMetrics()}, and returns
322-
* it.
323-
* <p>The returned instance is the <em>same object</em> later returned by
324-
* {@link #getAllClassMetrics()}. This is the invariant the historical
325-
* {@code instanceof GraphMetricsCollector} branch in
326-
* {@link MetricsVisitorLogic#enterClass} emulated: the
327-
* {@link ClassMetrics} the visitor mutates during the walk is the
328-
* instance the downstream disharmony detectors read from
329-
* {@link #getAllClassMetrics()}. Any get-or-create path that builds an
330-
* instance without storing it would silently discard every class's
331-
* metrics.
316+
* Retrieves or creates metrics for a class.
317+
*
318+
* @param className the class name
319+
* @return the existing or newly created class metrics
332320
*/
333321
public ClassMetrics getOrCreateClassMetrics(String className) {
334322
return classMetrics.computeIfAbsent(className, ClassMetrics::new);

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ public abstract class AbstractDependencyVisitor<P> extends JavaIsoVisitor<P> {
3030
@Getter
3131
private final DependencyVisitorState state;
3232

33+
/**
34+
* Creates a new AbstractDependencyVisitor.
35+
*
36+
* @param repositoryPath path to the source directory
37+
* @param repositoryRoot path to the repository root
38+
* @param dependencyCollector the dependency collector to use
39+
*/
3340
protected AbstractDependencyVisitor(
3441
String repositoryPath, String repositoryRoot, DependencyCollector dependencyCollector) {
3542
BaseTypeProcessor typeProcessor = new BaseTypeProcessor() {
@@ -61,6 +68,8 @@ public Javadoc visitDocComment(Javadoc.DocComment docComment, P p) {
6168
* Source-file extension used when synthetic source paths are produced for junit-based
6269
* tests (where the parser's URI is not usable as a repo path). Java returns {@code ".java"},
6370
* Kotlin returns {@code ".kt"}.
71+
*
72+
* @return the source file extension
6473
*/
6574
protected String sourceFileExtension() {
6675
return ".java";
@@ -189,8 +198,9 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, P
189198
}
190199

191200
/**
192-
* Returns the class-to-source-file-path mapping collected during the visit.
193-
* Delegates to the internal state.
201+
* Provides the source file path associated with each visited class.
202+
*
203+
* @return the class-to-source-file-path mapping
194204
*/
195205
public Map<String, String> getClassToSourceFilePathMapping() {
196206
return state.getClassToSourceFilePathMapping();

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,29 @@
99
import org.openrewrite.java.tree.JavaType;
1010
import org.openrewrite.java.tree.TypeTree;
1111

12+
/**
13+
* Base type processor that provides common type-processing logic for
14+
* dependency extraction. Subclasses implement {@link #getDependencyCollector()}
15+
* to provide the dependency collector instance.
16+
*/
1217
@Slf4j
1318
public abstract class BaseTypeProcessor {
1419

1520
private final TypeDependencyExtractor typeDependencyExtractor = new TypeDependencyExtractor();
1621

22+
/**
23+
* Returns the dependency collector to use for recording class dependencies.
24+
*
25+
* @return the dependency collector
26+
*/
1727
protected abstract DependencyCollector getDependencyCollector();
1828

29+
/**
30+
* Processes a Java type and extracts class dependencies.
31+
*
32+
* @param ownerFqn the fully qualified name of the type owner
33+
* @param javaType the Java type to process
34+
*/
1935
protected void processType(String ownerFqn, JavaType javaType) {
2036
if (javaType == null || javaType instanceof JavaType.Unknown) {
2137
return;
@@ -26,6 +42,13 @@ protected void processType(String ownerFqn, JavaType javaType) {
2642
}
2743
}
2844

45+
/**
46+
* Processes an annotation and records its class and argument type dependencies.
47+
*
48+
* @param ownerFqn the fully qualified name of the owning type
49+
* @param annotation the annotation to process
50+
* @param cursor the cursor providing processing context
51+
*/
2952
protected void processAnnotation(String ownerFqn, J.Annotation annotation, Cursor cursor) {
3053
if (annotation.getType() instanceof JavaType.Unknown) {
3154
return;
@@ -45,6 +68,14 @@ protected void processAnnotation(String ownerFqn, J.Annotation annotation, Curso
4568
}
4669
}
4770

71+
/**
72+
* Processes a type parameter and extracts class dependencies from its bounds
73+
* and annotations.
74+
*
75+
* @param ownerFqn the fully qualified name of the type owner
76+
* @param typeParameter the type parameter to process
77+
* @param cursor the cursor for context
78+
*/
4879
protected void processTypeParameter(String ownerFqn, J.TypeParameter typeParameter, Cursor cursor) {
4980
if (null != typeParameter.getBounds()) {
5081
for (TypeTree bound : typeParameter.getBounds()) {
@@ -59,6 +90,12 @@ protected void processTypeParameter(String ownerFqn, J.TypeParameter typeParamet
5990
}
6091
}
6192

93+
/**
94+
* Processes all annotations at the given cursor position.
95+
*
96+
* @param ownerFqn the fully qualified name of the type owner
97+
* @param cursor the cursor for context
98+
*/
6299
protected void processAnnotations(String ownerFqn, Cursor cursor) {
63100
AnnotationService annotationService = new AnnotationService();
64101
for (J.Annotation annotation : annotationService.getAllAnnotations(cursor)) {

0 commit comments

Comments
 (0)