Sample

int-7f6e4d6d6c09-I01

Remove line comments, block comments, and Javadoc

Matched original source

Lines159

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.1250–1; higher is more readable
Dorn0.0350–1; higher is more readable
Mi0.0760–1; higher is more readable
LLOC49Logical lines; fewer is more readable
DeepSeek V4 Pro13.670–20; mean of three runs
GPT-6.1 Sol150–20; mean of three runs
BTTF0.340–1; higher is more readable

Views

Source code

package org.springframework.test.context.bean.override.convention; import java.lang.annotation.Annotation; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Collection; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; import java.util.stream.Collectors; import org.springframework.core.MethodIntrospector; import org.springframework.core.ResolvableType; import org.springframework.test.context.TestContextAnnotationUtils; import org.springframework.test.context.bean.override.BeanOverrideProcessor; import org.springframework.test.context.bean.override.BeanOverrideStrategy; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; import org.springframework.util.ReflectionUtils.MethodFilter; import static org.springframework.test.context.bean.override.BeanOverrideStrategy.REPLACE; import static org.springframework.test.context.bean.override.BeanOverrideStrategy.REPLACE_OR_CREATE; class TestBeanOverrideProcessor implements BeanOverrideProcessor { @Override public TestBeanOverrideHandler createHandler(Annotation overrideAnnotation, Class<?> testClass, Field field) { if (!(overrideAnnotation instanceof TestBean testBean)) { throw new IllegalStateException("Invalid annotation passed to %s: expected @TestBean on field %s.%s" .formatted(getClass().getSimpleName(), field.getDeclaringClass().getName(), field.getName())); } String beanName = (!testBean.name().isBlank() ? testBean.name() : null); String methodName = testBean.methodName(); BeanOverrideStrategy strategy = (testBean.enforceOverride() ? REPLACE : REPLACE_OR_CREATE); Method factoryMethod; if (!methodName.isBlank()) { factoryMethod = findTestBeanFactoryMethod(field.getDeclaringClass(), field.getType(), methodName); } else { List<String> candidateMethodNames = new ArrayList<>(); candidateMethodNames.add(field.getName()); if (beanName != null) { candidateMethodNames.add(beanName); } factoryMethod = findTestBeanFactoryMethod(field.getDeclaringClass(), field.getType(), candidateMethodNames); } return new TestBeanOverrideHandler( field, ResolvableType.forField(field, testClass), beanName, testBean.contextName(), strategy, factoryMethod); } Method findTestBeanFactoryMethod(Class<?> clazz, Class<?> methodReturnType, String... methodNames) { return findTestBeanFactoryMethod(clazz, methodReturnType, List.of(methodNames)); } Method findTestBeanFactoryMethod(Class<?> clazz, Class<?> methodReturnType, Collection<String> methodNames) { Assert.notEmpty(methodNames, "At least one candidate method name is required"); Set<Method> methods = new LinkedHashSet<>(); Set<String> originalNames = new LinkedHashSet<>(methodNames); for (String methodName : methodNames) { int indexOfHash = methodName.lastIndexOf('#'); if (indexOfHash != -1) { String className = methodName.substring(0, indexOfHash).trim(); Assert.hasText(className, () -> "No class name present in fully-qualified method name: " + methodName); String methodNameToUse = methodName.substring(indexOfHash + 1).trim(); Assert.hasText(methodNameToUse, () -> "No method name present in fully-qualified method name: " + methodName); Class<?> declaringClass; try { declaringClass = ClassUtils.forName(className, getClass().getClassLoader()); } catch (ClassNotFoundException | LinkageError ex) { throw new IllegalStateException( "Failed to load class for fully-qualified method name: " + methodName, ex); } Method externalMethod = ReflectionUtils.findMethod(declaringClass, methodNameToUse); Assert.state(externalMethod != null && Modifier.isStatic(externalMethod.getModifiers()) && methodReturnType.isAssignableFrom(externalMethod.getReturnType()), () -> "No static method found named %s in %s with return type %s".formatted( methodNameToUse, className, methodReturnType.getName())); methods.add(externalMethod); originalNames.remove(methodName); } } Set<String> supportedNames = new LinkedHashSet<>(originalNames); MethodFilter methodFilter = method -> (Modifier.isStatic(method.getModifiers()) && supportedNames.contains(method.getName()) && methodReturnType.isAssignableFrom(method.getReturnType())); findMethods(methods, clazz, methodFilter); String methodNamesDescription = supportedNames.stream() .map(name -> name + "()").collect(Collectors.joining(" or ")); Assert.state(!methods.isEmpty(), () -> "No static method found named %s in %s with return type %s".formatted( methodNamesDescription, clazz.getName(), methodReturnType.getName())); long uniqueMethodNameCount = methods.stream().map(Method::getName).distinct().count(); Assert.state(uniqueMethodNameCount == 1, () -> "Found %d competing static methods named %s in %s with return type %s".formatted( uniqueMethodNameCount, methodNamesDescription, clazz.getName(), methodReturnType.getName())); return methods.iterator().next(); } private static Set<Method> findMethods(Set<Method> methods, Class<?> clazz, MethodFilter methodFilter) { methods.addAll(MethodIntrospector.selectMethods(clazz, methodFilter)); if (methods.isEmpty() && TestContextAnnotationUtils.searchEnclosingClass(clazz)) { findMethods(methods, clazz.getEnclosingClass(), methodFilter); } return methods; } }

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.7651.854−252.511
Source linesThe number of non-empty source lines.159+63.6
Byte entropyHow varied the bytes in the source text are. Repeated bytes give a lower value; a more even mixture gives a higher value.5.077−7.616

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

Score0.125

Feature contributions

FeatureValueContribution
(log-odds)
Indentation frequencyHow rapidly indentation changes from line to line.159+4.763
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.160−4.629
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.159−3.228
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.158.896+1.811
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.113.956−1.162
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.0−0.804
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.112−0.151

Intercept 0.07 + feature contributions = -3.33 (log-odds).
Score = sigmoid(-3.33) = 0.035.

Score0.076
Score49
Run 1

The code is generally readable but has significant issues with its structure and length. The main method `findTestBeanFactoryMethod` is overly long, mixing multiple concerns like parsing qualified names, validating method signatures, and finding candidates. This reduces clarity and action granularity. Nesting is moderate but becomes deep in conditional blocks. The reading flow is disrupted by scattered blank lines and dense expressions. Some parts are clear, such as the initial annotation conversion and the use of descriptive assertions. However, the logic for handling method names and filtering is tangled, making intent harder to follow. The recursive helper `findMethods` is concise and clear, but the longer method overwhelms the overall readability. More extraction into smaller, focused methods would improve the score significantly.

Run 2

The code shows moderate readability. The class has a clear single responsibility (processing @TestBean overrides) and methods are logically organized. However, the findTestBeanFactoryMethod method is complex with multiple nested conditionals and lengthy validation logic, making it harder to follow. The method handles multiple concerns: parsing fully-qualified names, finding methods, validation of uniqueness, and error messaging. Some lines are very long with chained boolean conditions (>100 chars), reducing scanability. Action granularity is mixed - some lines do multiple things with && chains in conditions. The blank comments (empty comment blocks) add clutter. While naming is generally descriptive and the intent is understandable, the two similar method overloads and dense method body create nesting that could be flattened. The code would benefit from extracting smaller helper methods for validation and name parsing to improve clarity.

Run 3

The code has a clear overall structure with sensible method separation and consistent naming. However, readability suffers from several issues: the main 'findTestBeanFactoryMethod' is overly long and handles multiple responsibilities (resolving fully-qualified names, validating static methods, filtering candidates). There is deep nesting in the for-loop with multiple try-catch blocks and conditional assertions. The method uses a mutable 'originalNames' set that is modified during iteration, making intent harder to trace. The large gaps of blank lines break reading flow without adding clarity. Multiple assertion statements with complex boolean conditions reduce clarity of intent. While the parameterized helper methods and use of 'MethodFilter' show good abstraction, the overall granularity and length of the main method make it hard to quickly understand the logic.

Run 1

Code Structure: Handler creation, factory-method lookup, and recursive discovery are logically separated, though the main lookup method combines several responsibilities. Nesting: Mostly shallow, with moderate nesting in the loop handling qualified method names and its try/catch. Clarity of intent: Descriptive names, explicit validation, and informative error messages make the purpose clear; reflection and mutable candidate sets require closer attention. Code length: Generally purposeful, but excessive blank lines and a lengthy lookup method reduce concision. Action granularity: Most lines perform one action; compound predicates and chained stream operations are denser but conventional. Reading flow: Processing follows a natural sequence from annotation validation to method discovery and handler construction, although large whitespace gaps and multiline assertions interrupt scanning.

Run 2

Code Structure: Responsibilities are logically separated into handler creation, factory-method resolution, and recursive lookup, though the main resolution method handles several concerns. Nesting: Mostly shallow, with moderate nesting in the loop that resolves fully qualified names and its try/catch. Clarity of intent: Descriptive identifiers, explicit validation, and informative error messages communicate purpose well; reflection and method-selection rules require closer reading. Code length: Generally economical, but excessive blank lines inflate the listing, and the resolution method could benefit from extracting external-method lookup. Action granularity: Most statements perform one action; compound predicates and stream chains remain reasonably readable. Reading flow: Execution follows a natural progression from configuration through discovery and validation to handler construction, but irregular whitespace and wrapped assertions interrupt scanning.

Run 3

Code Structure: Responsibilities are logically separated into handler creation, factory-method lookup, and recursive discovery, though the main lookup method combines several concerns. Nesting: Mostly shallow, with moderate nesting in the loop handling fully qualified method names and its try/catch. Clarity of intent: Descriptive identifiers, explicit validation, and informative error messages make the purpose clear; reflection and mutable candidate sets require closer reading. Code length: Generally economical, but excessive blank lines and a lengthy lookup method reduce readability. Action granularity: Most statements perform one action, although compound predicates and chained stream operations pack several checks or transformations together. Reading flow: Processing follows a natural sequence from annotation validation to method selection and handler construction, but large whitespace gaps and wrapped assertions interrupt scanning.