Sample

int-f113d2b1010d-I10

Remove about 40% of line-break groups while retaining structure

Matched original source

Lines115

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.0630–1; higher is more readable
Dorn0.0090–1; higher is more readable
Mi00–1; higher is more readable
LLOC49Logical lines; fewer is more readable
DeepSeek V4 Pro5.330–20; mean of three runs
GPT-6.1 Sol100–20; mean of three runs
BTTF0.2110–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; /** * {@link BeanOverrideProcessor} implementation for {@link TestBean @TestBean} * support, which creates a {@link TestBeanOverrideHandler} for annotated * fields in a given class and ensures that a corresponding static factory method * exists, according to the {@linkplain TestBean documented conventions}. * * @author Simon Baslé * @author Sam Brannen * @author Stephane Nicoll * @since 6.2 */ 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()) { // If the user specified an explicit method name, search for that. factoryMethod = findTestBeanFactoryMethod(field.getDeclaringClass(), field.getType(), methodName); } else { // Otherwise, search for candidate factory methods whose names match either // the field name or the explicit bean name (if any). 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); } /** * Find a test bean factory {@link Method} for the given {@link Class}. * <p>Delegates to {@link #findTestBeanFactoryMethod(Class, Class, Collection)}. */ Method findTestBeanFactoryMethod(Class<?> clazz, Class<?> methodReturnType, String... methodNames) { return findTestBeanFactoryMethod(clazz, methodReturnType, List.of(methodNames)); } /** * Find a test bean factory {@link Method} for the given {@link Class}, which * meets the following criteria. * <ul> * <li>The method is static.</li> * <li>The method does not accept any arguments.</li> * <li>The method's return type matches the supplied {@code methodReturnType}.</li> * <li>The method's name is one of the supplied {@code methodNames}.</li> * </ul> * <p>This method traverses up the type hierarchy of the given class in search * of the factory method, beginning with the class itself and then searching * implemented interfaces and superclasses. If a factory method is not found * in the type hierarchy, this method will also search the enclosing class * hierarchy if the class is a nested class. * <p>If multiple factory methods are found that match the search criteria, * an exception is thrown. * @param clazz the class in which to search for the factory method * @param methodReturnType the return type for the factory method * @param methodNames a set of supported names for the factory method * @return the corresponding factory method * @throws IllegalStateException if a matching factory method cannot * be found or multiple methods match */ 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); // Process fully-qualified method names first. 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.115+46
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.034−7.551

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

Score0.063

Feature contributions

FeatureValueContribution
(log-odds)
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.244.983−6.711
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.244.991+3.148
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.116−3.071
Indentation frequencyHow rapidly indentation changes from line to line.76+1.892
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.76−1.323
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.114.866+1.196
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.082+0.142

Intercept 0.07 + feature contributions = -4.658 (log-odds).
Score = sigmoid(-4.658) = 0.009.

Score0
Score49
Run 1

The code is barely readable due to severe formatting issues. Multiple statements are crammed onto single lines (imports, method signatures, conditionals), making it visually chaotic. Indentation is inconsistent, and braces are misplaced, obscuring code structure. The logic itself is not inherently complex, but the presentation makes it extremely hard to follow: the eye must parse dense lines to find where one statement ends and another begins. There is no standard Java formatting, violating all normal expectations. Concepts like candidate method processing are mixed with exception handling in a way that is difficult to trace. While some method documentation exists, the overall lack of whitespace, standard line breaks, and proper indentation overwhelms any clarity of intent. This code would be rejected in any professional Java codebase and requires an auto-formatter before review.

Run 2

The code suffers from severe readability issues. Multiple statements are packed onto single lines (e.g., field declarations, method signatures, and conditionals), violating the 'one action per line' principle and disrupting natural reading flow. The class declaration and method signatures are also compressed onto single lines, making the structure difficult to parse. Deep nesting is present in the fully-qualified method name parsing loop, with multiple try-catch blocks and conditionals creating tangled logic. While some Javadoc comments clarify intent, formatting inconsistencies (e.g., mixed indentation, inline braces) and excessively long boolean assertions obscure the code's purpose. The method `findTestBeanFactoryMethod` is overly long and handles multiple responsibilities, reducing clarity. Overall, the logical organization exists but is buried under poor formatting, dense lines, and inconsistent style, making the code tiring to read.

Run 3

The code suffers from severe formatting issues that significantly impair readability. Multiple statements are packed onto single lines (imports, method signatures, if-statements), violating the 'one action per line' principle. The createHandler method has deeply nested conditional logic and multiple operations per line. While the Javadoc is well-written and the overall structure is logical, the actual implementation is compressed into dense, hard-to-scan blocks. The findTestBeanFactoryMethod method is particularly problematic with long lines, nested loops, and complex boolean conditions crammed together. The code's intent is clear from documentation but the execution makes it unnecessarily difficult to follow the logic flow. Basic formatting improvements alone would raise readability significantly.

Run 1

Code Structure: Responsibilities are logically separated into handler creation, factory-method lookup, and recursive search, though the main lookup method is dense. Nesting: Mostly moderate, but the fully qualified name loop combines conditionals and exception handling with compressed braces. Clarity of intent: Descriptive names, detailed Javadoc, comments, and informative validation messages clearly explain the purpose. Code length: Generally justified by the search and validation requirements, although long expressions make scanning harder. Action granularity: Frequently poor; multiple imports, declarations, assertions, and control-flow transitions share lines. Reading flow: The overall algorithm follows a sensible sequence, but inconsistent formatting, inline closing braces, and oversized lines repeatedly interrupt it. Strong naming and documentation preserve comprehension despite substantially degraded presentation.

Run 2

Code Structure: Responsibilities are logically divided into handler creation, factory-method lookup, and recursive discovery, but compressed formatting obscures these boundaries. Nesting: Mostly moderate, though the fully qualified method-name loop combines conditionals and exception handling in a difficult-to-scan block. Clarity of intent: Descriptive names, detailed documentation, comments, and informative exception messages clearly explain the purpose. Code length: Implementation length is reasonable for the functionality; documentation is extensive but useful, while several lines are excessively long. Action granularity: Multiple imports, declarations, assertions, and control-flow transitions frequently share lines, substantially reducing readability. Reading flow: The overall sequence is coherent, but inconsistent line breaks, inline closing braces, and crowded expressions repeatedly interrupt scanning.

Run 3

Code Structure: Responsibilities are logically separated into handler creation, factory-method lookup, and recursive search, but compressed formatting obscures these boundaries. Nesting: Mostly moderate, though the fully qualified method-name loop combines conditionals and exception handling in a difficult-to-scan block. Clarity of intent: Descriptive identifiers, Javadoc, comments, and informative validation messages explain the purpose well. Code length: Implementation is reasonably concise for its responsibilities; documentation is useful rather than redundant. Action granularity: Numerous imports, declarations, assertions, and control-flow transitions share lines, significantly reducing readability. Reading flow: The overall sequence is logical, but inconsistent spacing, long expressions, and closing braces followed immediately by statements frequently interrupt scanning. Conventional formatting and one statement per line would substantially improve readability without changing the design.