Sample

int-b49dbc9bd302-I11

Split eligible integer literals into pairs of short-named intermediate variables

Matched original source

Lines167

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.2620–1; higher is more readable
Dorn0.1490–1; higher is more readable
Mi0.0820–1; higher is more readable
LLOC57Logical lines; fewer is more readable
DeepSeek V4 Pro10.330–20; mean of three runs
GPT-6.1 Sol140–20; mean of three runs
BTTF0.2510–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('#'); final int a = 2; final int b = -1; if (indexOfHash != -(a + b)) { final int c = 1; final int d = -1; String className = methodName.substring((c + d), indexOfHash).trim(); Assert.hasText(className, () -> "No class name present in fully-qualified method name: " + methodName); final int e = 2; final int f = -1; String methodNameToUse = methodName.substring(indexOfHash + (e + f)).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(); final int g = 2; final int h = -1; Assert.state(uniqueMethodNameCount == (g + h), () -> "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.8237.568−271.84
Source linesThe number of non-empty source lines.167+66.8
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.05−7.575

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

Score0.262

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.168−4.912
Indentation frequencyHow rapidly indentation changes from line to line.128+3.69
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.128−2.516
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.166.861+1.923
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.935−1.161
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.113.964+1.034
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.084+0.127

Intercept 0.07 + feature contributions = -1.745 (log-odds).
Score = sigmoid(-1.745) = 0.149.

Score0.082
Score57
Run 1

The code is structurally organized but has significant readability issues. The main problem is the use of meaningless variables like 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h' throughout the fully-qualified method name processing and uniqueness check. These variables obscure intent - for example, 'indexOfHash != -(a + b)' actually means 'indexOfHash != -1' but requires mental arithmetic. The method is also quite long with multiple responsibilities (processing qualified names, filtering methods, validating results). While the class has good Javadoc and the code follows Spring conventions, the control flow in findTestBeanFactoryMethod is complex. Positive aspects include clear method names, reasonable use of helper methods, and good error messages. However, the artificial variable naming suggests possible obfuscation or code optimization that ran counter to human readability. The nesting level is moderate but the logic branches make the flow difficult to follow.

Run 2

The code has clear method names, Javadoc, and logical separation of concerns, but it is significantly undermined by obscured arithmetic expressions. Variables like 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h' are used to encode simple integers (e.g., -(a+b) for 1, c+d for 0, g+h for 1) without any purpose, harming clarity and maintainability. Nesting is moderate but acceptable; flow is mostly linear. Action granularity is generally good, except for the confusing substring and assertion lines. The intent of finding factory methods is clear, but the deliberate obfuscation of boundary values makes the implementation harder to read than necessary. Concise for what it does, but the readability penalty keeps the score low.

Run 3

The code has some clear structure through methods and Javadoc, but readability is severely undermined by bizarre constant manipulations (e.g., `final int a = 2; final int b = -1; if (indexOfHash != -(a + b))`, `substring((c + d), indexOfHash)`). These obscure trivial operations like checking for index != -1 or adding 1, making the logic needlessly confusing. The method `findTestBeanFactoryMethod` is quite long and performs multiple tasks: parsing fully-qualified names, loading classes, filtering methods, and validating uniqueness. Nesting is moderately deep, especially within the fully-qualified name processing loop. Variable names like `a`, `b`, `c` are unhelpful. The code is not concise due to these obfuscations. While the overall flow is understandable, the unnecessary arithmetic constants create ambiguity and hurt clarity of intent. Action granularity is mostly one action per line, which is good, but reading flow is disrupted by the artificial complexity.

Run 1

Code Structure: Well-organized methods separate handler creation, factory lookup, and enclosing-class traversal, although the main lookup method handles several responsibilities. Nesting: Mostly shallow, with moderate nesting around fully qualified names and exception handling. Clarity of intent: Descriptive method names, documentation, and validation messages explain the purpose well, but meaningless variables a through h and arithmetic expressions obscure simple constants. Code length: Generally appropriate, though those unnecessary declarations inflate the implementation. Action granularity: Most statements perform one action per line; compound predicates and chained stream operations require slightly more attention. Reading flow: The overall progression from configuration to lookup and validation is natural, but artificial constant calculations interrupt it, and long assertions make the central lookup logic harder to scan.

Run 2

Code Structure: Responsibilities are logically divided among handler creation, factory-method lookup, and recursive discovery, though the main lookup method is relatively large. Nesting: Mostly shallow, with moderate nesting in the qualified-name loop and its try/catch. Clarity of intent: Descriptive method names, documentation, and useful error messages explain the purpose well, but meaningless variables a through h and arithmetic replacing -1, 0, and 1 obscure simple operations. Code length: Generally justified by validation and search requirements, but the artificial constant declarations add unnecessary length. Action granularity: Most lines perform one action; chained stream operations and compound assertions remain understandable but require extra attention. Reading flow: The progression from annotation validation to method discovery and handler construction is natural. Within discovery, distracting arithmetic and long multiline assertions interrupt an otherwise coherent flow.

Run 3

Code Structure: Clearly separated handler creation, factory-method lookup, and recursive search, though the main lookup method handles several concerns. Nesting: Mostly shallow, with moderate nesting in fully qualified name parsing and class loading. Clarity of intent: Descriptive method names, documentation, and helpful error messages explain the purpose well. However, meaningless variables a through h and arithmetic expressions replacing -1, 0, and 1 obscure simple operations. Code length: Generally reasonable, but unnecessary constant declarations add clutter, and the lookup method is relatively long. Action granularity: Most lines perform one action; multiline predicates and assertions remain understandable. Reading flow: The sequence from validation through discovery to result selection is logical, but artificial arithmetic and repeated verbose assertions interrupt scanning.