Sample

Schnappinger/junit4/org.junit.validator.AnnotationsValidator

Human rating uses the original dataset scale.

Human3.2
Lines120

Scores

MethodScoreScaleDataset rank
(0–100)
Posnett00–1; higher is more readable
36.8Δ 3.5
Scalabrino0.4380–1; higher is more readable
5.5Δ 27.9
Dorn0.8210–1; higher is more readable
88.4Δ 55.1
Mi0.1010–1; higher is more readable
10.6Δ 22.8
LLOC38Logical lines; fewer is more readable
44.6Δ 11.2
DeepSeek V4 Pro15.670–20; mean of three runs
43.9Δ 10.6
GPT-6.1 Sol170–20; mean of three runs
55.3Δ 21.9
BTTF0.5920–1; higher is more readable
56.8Δ 23.4
Human3.21–4; original rating
33.3

Views

Source code

package org.junit.validator; import static java.util.Collections.singletonList; import java.lang.annotation.Annotation; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.junit.runners.model.Annotatable; import org.junit.runners.model.FrameworkField; import org.junit.runners.model.FrameworkMethod; import org.junit.runners.model.TestClass; /** * An {@code AnnotationsValidator} validates all annotations of a test class, * including its annotated fields and methods. * * @since 4.12 */ public final class AnnotationsValidator implements TestClassValidator { private static final List<AnnotatableValidator<?>> VALIDATORS = Arrays.<AnnotatableValidator<?>>asList( new ClassValidator(), new MethodValidator(), new FieldValidator()); /** * Validate all annotations of the specified test class that are be * annotated with {@link ValidateWith}. * * @param testClass * the {@link TestClass} that is validated. * @return the errors found by the validator. */ public List<Exception> validateTestClass(TestClass testClass) { List<Exception> validationErrors= new ArrayList<Exception>(); for (AnnotatableValidator<?> validator : VALIDATORS) { List<Exception> additionalErrors= validator .validateTestClass(testClass); validationErrors.addAll(additionalErrors); } return validationErrors; } private static abstract class AnnotatableValidator<T extends Annotatable> { private static final AnnotationValidatorFactory ANNOTATION_VALIDATOR_FACTORY = new AnnotationValidatorFactory(); abstract Iterable<T> getAnnotatablesForTestClass(TestClass testClass); abstract List<Exception> validateAnnotatable( AnnotationValidator validator, T annotatable); public List<Exception> validateTestClass(TestClass testClass) { List<Exception> validationErrors= new ArrayList<Exception>(); for (T annotatable : getAnnotatablesForTestClass(testClass)) { List<Exception> additionalErrors= validateAnnotatable(annotatable); validationErrors.addAll(additionalErrors); } return validationErrors; } private List<Exception> validateAnnotatable(T annotatable) { List<Exception> validationErrors= new ArrayList<Exception>(); for (Annotation annotation : annotatable.getAnnotations()) { Class<? extends Annotation> annotationType = annotation .annotationType(); ValidateWith validateWith = annotationType .getAnnotation(ValidateWith.class); if (validateWith != null) { AnnotationValidator annotationValidator = ANNOTATION_VALIDATOR_FACTORY .createAnnotationValidator(validateWith); List<Exception> errors= validateAnnotatable( annotationValidator, annotatable); validationErrors.addAll(errors); } } return validationErrors; } } private static class ClassValidator extends AnnotatableValidator<TestClass> { @Override Iterable<TestClass> getAnnotatablesForTestClass(TestClass testClass) { return singletonList(testClass); } @Override List<Exception> validateAnnotatable( AnnotationValidator validator, TestClass testClass) { return validator.validateAnnotatedClass(testClass); } } private static class MethodValidator extends AnnotatableValidator<FrameworkMethod> { @Override Iterable<FrameworkMethod> getAnnotatablesForTestClass( TestClass testClass) { return testClass.getAnnotatedMethods(); } @Override List<Exception> validateAnnotatable( AnnotationValidator validator, FrameworkMethod method) { return validator.validateAnnotatedMethod(method); } } private static class FieldValidator extends AnnotatableValidator<FrameworkField> { @Override Iterable<FrameworkField> getAnnotatablesForTestClass(TestClass testClass) { return testClass.getAnnotatedFields(); } @Override List<Exception> validateAnnotatable( AnnotationValidator validator, FrameworkField field) { return validator.validateAnnotatedField(field); } }; }

Loading feature diagnosis…

Source regions

Feature contributions

Feature contributions

FeatureValueContribution
(log-odds)
Halstead volumeHow much symbolic information the code contains. It combines the total number of operators and values with the number of distinct ones.3659.592−120.767
Source linesThe number of non-empty source lines.120+48
Byte entropyHow varied the bytes in the source text are. Repeated bytes give a lower value; a more even mixture gives a higher value.4.409−6.614

Intercept 8.87 + feature contributions = -70.51 (log-odds).
Score = sigmoid(-70.51) = 0.

Score0.438

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.121−3.248
Indentation frequencyHow rapidly indentation changes from line to line.108+2.998
Identifier layout (horizontal)How rapidly the visual pattern of identifier characters changes from left to right. It measures spatial frequency, not the meaning of the names.119.992−1.417
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.119.901+1.266
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.119.967+1.131
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.1+0.398
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.064+0.322

Intercept 0.07 + feature contributions = 1.52 (log-odds).
Score = sigmoid(1.52) = 0.821.

Score0.101
Score38
Run 1

The code demonstrates good structure with clear separation of concerns via class hierarchy and follows the single responsibility principle. However, the private static methods introduce nesting and parameter passing that could be simplified. The code uses a factory pattern and generics appropriately but has minor inconsistencies (spacing before '=', unnecessary fully qualified type in Arrays.asList). Method names are descriptive, but the indirection between validateAnnotatable(T) and validateAnnotatable(AnnotationValidator, T) adds cognitive overhead. Overall, readable but with room for simplification.

Run 2

The code is well-structured with clear separation of concerns via a template method pattern. The use of generics and abstract classes adds clarity but also some cognitive overhead. Nesting is minimal (max 3 levels), and each method has a single responsibility. Variable names are descriptive, and the flow from top-level validator to specific annotatable validators is logical. Minor issues: slight inconsistency in spacing (e.g., 'validationErrors= new'), redundant local variable in validateTestClass, and some line breaks that feel forced. The code is concise but could benefit from small refactors like extracting a helper to add errors. Overall, it is highly readable for experienced Java developers.

Run 3

The code is well-structured, using an interface, abstract class, and subclasses to separate validation concerns by element type (class, method, field). This keeps methods flat and focused. Naming is generally clear, and actions are mostly one per line. However, readability is slightly reduced by some verbose formatting (line-wrapped assignments), a stray semicolon after the FieldValidator class, and repetitive validation-loop logic across methods. The abstract class centralizes shared logic well, but the double validateAnnotatable overloads could be slightly confusing. Overall, the code is readable and maintainable but not perfectly concise.

Run 1

Code Structure: Well organized around a shared generic validator and three focused specializations, separating common logic from class-, method-, and field-specific behavior. Nesting: Shallow overall, with only a conditional inside the annotation loop. Clarity of intent: Descriptive names and documentation clearly communicate annotation validation and error collection; overloaded validation methods and generics add modest cognitive overhead. Code length: Reasonably concise for the functionality, though repeated error-aggregation patterns and adapter classes introduce some boilerplate. Action granularity: Statements generally perform one action each, with intermediate variables making operations explicit. Reading flow: Progresses naturally from the public entry point through shared processing to specialized implementations. Awkward line wrapping, inconsistent spacing around assignments, a documentation typo, and the unnecessary final semicolon slightly detract from readability.

Run 2

Code Structure: Well-organized, with a shared generic validator and small class-, method-, and field-specific implementations. Nesting: Shallow control flow; the deepest logic is an if inside a loop, though nested classes add some conceptual depth. Clarity of intent: Descriptive names and documentation clearly communicate annotation validation and error collection; overloaded validateAnnotatable methods require slight attention. Code length: Reasonably concise through reuse, although repeated error-collection patterns and verbose generic declarations add boilerplate. Action granularity: Statements generally perform one action each, making operations easy to follow. Reading flow: Validation proceeds naturally from the test class to its elements and annotations, but frequent line wrapping, inconsistent spacing around assignments, a documentation typo, and an unnecessary trailing semicolon slightly reduce polish.

Run 3

Code Structure: Well organized around a shared generic validator with focused class, method, and field implementations. Nesting: Shallow loops and a single conditional keep control flow manageable, although nested classes introduce some structural depth. Clarity of intent: Descriptive names and documentation clearly communicate annotation validation and error collection; overloaded validateAnnotatable methods require minor extra attention. Code length: Reasonably concise, with some repetitive error aggregation and subclass boilerplate. Action granularity: Statements generally perform one action per line; wrapped expressions remain understandable. Reading flow: Proceeds naturally from orchestration to shared logic and specialized implementations. Inconsistent assignment spacing, awkward line wrapping, a documentation typo, and an unnecessary trailing semicolon slightly reduce polish.