Skip to content

Commit 9f9f849

Browse files
committed
Enhance Javadoc across analysis, introspection, and validation components for improved readability and clarity.
1 parent 6cde5a1 commit 9f9f849

6 files changed

Lines changed: 169 additions & 14 deletions

File tree

aether-datafixers-schema-tools/src/main/java/de/splatgames/aether/datafixers/schematools/analysis/CoverageGap.java

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,49 @@ public String description() {
121121
}
122122
}
123123

124+
/**
125+
* The type reference for which this coverage gap was detected.
126+
*/
124127
private final TypeReference type;
128+
129+
/**
130+
* The source version where the type change originated.
131+
*/
125132
private final DataVersion sourceVersion;
133+
134+
/**
135+
* The target version where the type change applies.
136+
*/
126137
private final DataVersion targetVersion;
138+
139+
/**
140+
* The reason why this gap exists (what kind of change has no fix).
141+
*/
127142
private final Reason reason;
143+
144+
/**
145+
* The specific field name involved, or {@code null} for type-level gaps.
146+
*/
128147
private final String fieldName;
148+
149+
/**
150+
* The detailed type diff showing what changed, or {@code null} if not available.
151+
*/
129152
private final TypeDiff typeDiff;
130153

154+
/**
155+
* Creates a new CoverageGap instance.
156+
*
157+
* <p>This constructor is private; use the factory methods
158+
* {@link #typeLevel} or {@link #fieldLevel} to create instances.</p>
159+
*
160+
* @param type the affected type, must not be {@code null}
161+
* @param sourceVersion the source version, must not be {@code null}
162+
* @param targetVersion the target version, must not be {@code null}
163+
* @param reason the gap reason, must not be {@code null}
164+
* @param fieldName the field name for field-level gaps, or {@code null}
165+
* @param typeDiff the type diff for context, or {@code null}
166+
*/
131167
private CoverageGap(
132168
@NotNull final TypeReference type,
133169
@NotNull final DataVersion sourceVersion,
@@ -284,6 +320,16 @@ public boolean isTypeLevel() {
284320
return this.fieldName == null;
285321
}
286322

323+
/**
324+
* Compares this coverage gap to another object for equality.
325+
*
326+
* <p>Two {@code CoverageGap} instances are equal if they have the same
327+
* type, source version, target version, reason, and field name. The
328+
* type diff is not included in the comparison since it is contextual.</p>
329+
*
330+
* @param obj the object to compare with, may be {@code null}
331+
* @return {@code true} if the objects are equal, {@code false} otherwise
332+
*/
287333
@Override
288334
public boolean equals(final Object obj) {
289335
if (this == obj) {
@@ -299,11 +345,28 @@ public boolean equals(final Object obj) {
299345
&& Objects.equals(this.fieldName, other.fieldName);
300346
}
301347

348+
/**
349+
* Returns a hash code value for this coverage gap.
350+
*
351+
* <p>The hash code is computed from the type, source version, target version,
352+
* reason, and field name to ensure consistency with {@link #equals(Object)}.</p>
353+
*
354+
* @return the hash code value for this coverage gap
355+
*/
302356
@Override
303357
public int hashCode() {
304358
return Objects.hash(this.type, this.sourceVersion, this.targetVersion, this.reason, this.fieldName);
305359
}
306360

361+
/**
362+
* Returns a human-readable string representation of this coverage gap.
363+
*
364+
* <p>The format includes the type name, optional field name, reason,
365+
* and version range. For example:</p>
366+
* <pre>{@code CoverageGap[player.health: FIELD_ADDED (v100 -> v110)]}</pre>
367+
*
368+
* @return a formatted string representation, never {@code null}
369+
*/
307370
@Override
308371
public String toString() {
309372
final StringBuilder sb = new StringBuilder();

aether-datafixers-schema-tools/src/main/java/de/splatgames/aether/datafixers/schematools/analysis/MigrationAnalyzer.java

Lines changed: 83 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,42 @@
8787
*/
8888
public final class MigrationAnalyzer {
8989

90+
/**
91+
* The registry containing all schema definitions.
92+
*/
9093
private final SchemaRegistry schemaRegistry;
94+
95+
/**
96+
* The registry containing all DataFix registrations.
97+
*/
9198
private final DataFixRegistry fixRegistry;
99+
100+
/**
101+
* The source version for analysis. Set via {@link #from(DataVersion)}.
102+
*/
92103
private DataVersion fromVersion;
104+
105+
/**
106+
* The target version for analysis. Set via {@link #to(DataVersion)}.
107+
*/
93108
private DataVersion toVersion;
109+
110+
/**
111+
* Flag controlling whether field-level analysis is included.
112+
* Defaults to {@code false} for performance.
113+
*/
94114
private boolean includeFieldLevel = false;
95115

116+
/**
117+
* Creates a new MigrationAnalyzer with the given registries.
118+
*
119+
* <p>This constructor is private; use {@link #forBootstrap} or
120+
* {@link #forRegistries} to create instances.</p>
121+
*
122+
* @param schemaRegistry the schema registry, must not be {@code null}
123+
* @param fixRegistry the fix registry, must not be {@code null}
124+
* @throws NullPointerException if any argument is {@code null}
125+
*/
96126
private MigrationAnalyzer(
97127
@NotNull final SchemaRegistry schemaRegistry,
98128
@NotNull final DataFixRegistry fixRegistry
@@ -251,7 +281,14 @@ public FixCoverage analyzeCoverage() {
251281
}
252282

253283
/**
254-
* Validates that version range is properly configured.
284+
* Validates that the version range is properly configured.
285+
*
286+
* <p>This method ensures both {@code fromVersion} and {@code toVersion}
287+
* have been set, and that {@code fromVersion} does not exceed
288+
* {@code toVersion}.</p>
289+
*
290+
* @throws IllegalStateException if from/to versions are not set
291+
* or if fromVersion > toVersion
255292
*/
256293
private void validateVersionRange() {
257294
Preconditions.checkState(this.fromVersion != null, "fromVersion must be set. Use from().");
@@ -263,7 +300,14 @@ private void validateVersionRange() {
263300
}
264301

265302
/**
266-
* Gets all schemas in the version range, sorted by version.
303+
* Retrieves all schemas within the configured version range.
304+
*
305+
* <p>Iterates through all schemas in the registry and filters those
306+
* with versions between {@code fromVersion} and {@code toVersion}
307+
* (inclusive). The resulting list is sorted by version number
308+
* in ascending order.</p>
309+
*
310+
* @return a mutable list of schemas sorted by version, never {@code null}
267311
*/
268312
@NotNull
269313
private List<Schema> getSchemasInRange() {
@@ -281,7 +325,19 @@ private List<Schema> getSchemasInRange() {
281325
}
282326

283327
/**
284-
* Analyzes a single migration step between two schemas.
328+
* Analyzes a single migration step between two consecutive schemas.
329+
*
330+
* <p>This method performs the following analysis:</p>
331+
* <ol>
332+
* <li>Computes the schema diff between source and target</li>
333+
* <li>Identifies all affected types (added, removed, or modified)</li>
334+
* <li>Looks up registered DataFixes for the version transition</li>
335+
* <li>Constructs a MigrationStep with the collected information</li>
336+
* </ol>
337+
*
338+
* @param sourceSchema the source schema, must not be {@code null}
339+
* @param targetSchema the target schema, must not be {@code null}
340+
* @return the analyzed migration step, never {@code null}
285341
*/
286342
@NotNull
287343
private MigrationStep analyzeStep(
@@ -329,7 +385,15 @@ private MigrationStep analyzeStep(
329385
}
330386

331387
/**
332-
* Analyzes coverage for a single step and adds gaps to the builder.
388+
* Analyzes fix coverage for a single migration step.
389+
*
390+
* <p>Examines the schema diff between versions and checks if each
391+
* change (added/removed/modified types) has a corresponding DataFix.
392+
* Missing fixes are recorded as coverage gaps in the builder.</p>
393+
*
394+
* @param sourceSchema the source schema, must not be {@code null}
395+
* @param targetSchema the target schema, must not be {@code null}
396+
* @param coverageBuilder the builder to accumulate gaps, must not be {@code null}
333397
*/
334398
private void analyzeStepCoverage(
335399
@NotNull final Schema sourceSchema,
@@ -376,7 +440,21 @@ private void analyzeStepCoverage(
376440
}
377441

378442
/**
379-
* Checks coverage for field-level changes in a type.
443+
* Checks fix coverage for field-level changes within a type.
444+
*
445+
* <p>If the type has field-level changes (added, removed, or modified fields)
446+
* but no DataFix is registered to handle the type at this version,
447+
* a coverage gap is recorded.</p>
448+
*
449+
* <p><b>Note:</b> This implementation checks for the presence of any fix
450+
* for the type. A more sophisticated implementation could verify that
451+
* the fix actually handles all specific field changes.</p>
452+
*
453+
* @param type the type being analyzed, must not be {@code null}
454+
* @param sourceSchema the source schema, must not be {@code null}
455+
* @param targetSchema the target schema, must not be {@code null}
456+
* @param typeDiff the detailed type diff, must not be {@code null}
457+
* @param coverageBuilder the builder to accumulate gaps, must not be {@code null}
380458
*/
381459
private void checkTypeDiffCoverage(
382460
@NotNull final TypeReference type,

aether-datafixers-schema-tools/src/main/java/de/splatgames/aether/datafixers/schematools/analysis/MigrationStep.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ public String toString() {
321321
* properties. Required properties (source and target versions) are provided
322322
* via {@link MigrationStep#builder(DataVersion, DataVersion)}.</p>
323323
*
324-
* <h3>Usage Example</h3>
324+
* <p><b>Usage Example:</b></p>
325325
* <pre>{@code
326326
* MigrationStep step = MigrationStep.builder(v1, v2)
327327
* .fix(myFix)

aether-datafixers-schema-tools/src/main/java/de/splatgames/aether/datafixers/schematools/introspection/TypeStructure.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ public String toString() {
367367
* <li>{@code children}: empty list</li>
368368
* </ul>
369369
*
370-
* <h3>Usage Example</h3>
370+
* <p><b>Usage Example:</b></p>
371371
* <pre>{@code
372372
* TypeStructure structure = TypeStructure.builder(TypeReference.of("player"))
373373
* .description("Player entity data")
@@ -376,8 +376,8 @@ public String toString() {
376376
* .build();
377377
* }</pre>
378378
*
379-
* <h3>Thread Safety</h3>
380-
* <p>Builders are not thread-safe and should not be shared between threads.</p>
379+
* <p><b>Thread Safety:</b>
380+
* Builders are not thread-safe and should not be shared between threads.</p>
381381
*
382382
* @author Erik Pfoertner
383383
* @since 0.3.0
@@ -423,7 +423,7 @@ private Builder(@NotNull final TypeReference reference) {
423423
* Sets the human-readable description for the type structure.
424424
*
425425
* <p>The description typically contains information about the type's
426-
* structure and purpose, such as the output of {@link Type#describe()}.</p>
426+
* structure and purpose, such as the output of the type's {@code describe()} method.</p>
427427
*
428428
* @param description the description text, must not be {@code null}
429429
* @return this builder for method chaining, never {@code null}

aether-datafixers-schema-tools/src/main/java/de/splatgames/aether/datafixers/schematools/validation/StructureValidator.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,21 @@ public static ValidationResult validateRegistry(@NotNull final SchemaRegistry re
158158
}
159159

160160
/**
161-
* Validates parent chain for cycles and version ordering.
161+
* Validates the parent chain for cycles and version ordering.
162+
*
163+
* <p>Traverses the parent chain starting from the given schema and checks:</p>
164+
* <ol>
165+
* <li>No cycles exist (a schema is not its own ancestor)</li>
166+
* <li>Parent versions are always less than child versions</li>
167+
* </ol>
168+
*
169+
* <p>Issues are added to the result builder with appropriate context
170+
* for debugging.</p>
171+
*
172+
* @param schema the schema whose parent chain to validate
173+
* @param registry the registry for parent lookup (may be {@code null})
174+
* @param result the builder to accumulate issues
175+
* @param location the location string for issue reporting
162176
*/
163177
private static void validateParentChain(
164178
@NotNull final Schema schema,

aether-datafixers-schema-tools/src/main/java/de/splatgames/aether/datafixers/schematools/validation/ValidationResult.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ public String toString() {
347347
* a validation operation. Issues can be added individually or in batches,
348348
* and convenience methods are provided for creating common issue types.</p>
349349
*
350-
* <h3>Usage Example</h3>
350+
* <p><b>Usage Example:</b></p>
351351
* <pre>{@code
352352
* ValidationResult result = ValidationResult.builder()
353353
* .error("STRUCT_001", "Missing required field")
@@ -356,8 +356,8 @@ public String toString() {
356356
* .build();
357357
* }</pre>
358358
*
359-
* <h3>Thread Safety</h3>
360-
* <p>Builders are not thread-safe and should not be shared between threads.</p>
359+
* <p><b>Thread Safety:</b>
360+
* Builders are not thread-safe and should not be shared between threads.</p>
361361
*
362362
* @author Erik Pfoertner
363363
* @since 0.3.0

0 commit comments

Comments
 (0)