Sample

int-35cfbc14f0e2-I13

Lower every eligible classic and enhanced for loop to a while loop

Matched original source

Lines78

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.8510–1; higher is more readable
Dorn0.4450–1; higher is more readable
Mi0.2650–1; higher is more readable
LLOC19Logical lines; fewer is more readable
DeepSeek V4 Pro17.670–20; mean of three runs
GPT-6.1 Sol170–20; mean of three runs
BTTF0.6680–1; higher is more readable

Views

Source code

package com.google.common.reflect; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Proxy; /** * Static utilities relating to Java reflection. * * @since 12.0 */ public final class Reflection { /** * Returns the package name of {@code clazz} according to the Java Language Specification (section * 6.7). Unlike {@link Class#getPackage}, this method only parses the class name, without * attempting to define the {@link Package} and hence load files. */ public static String getPackageName(Class<?> clazz) { return getPackageName(clazz.getName()); } /** * Returns the package name of {@code classFullName} according to the Java Language Specification * (section 6.7). Unlike {@link Class#getPackage}, this method only parses the class name, without * attempting to define the {@link Package} and hence load files. */ public static String getPackageName(String classFullName) { int lastDot = classFullName.lastIndexOf('.'); return (lastDot < 0) ? "" : classFullName.substring(0, lastDot); } /** * Ensures that the given classes are initialized, as described in <a * href="http://java.sun.com/docs/books/jls/third_edition/html/execution.html#12.4.2">JLS Section * 12.4.2</a>. * * <p>WARNING: Normally it's a smell if a class needs to be explicitly initialized, because static * state hurts system maintainability and testability. In cases when you have no choice while * interoperating with a legacy framework, this method helps to keep the code less ugly. * * @throws ExceptionInInitializerError if an exception is thrown during initialization of a class */ public static void initialize(Class<?>... classes) { { Class<?>[] loopArray = classes; int loopIndex = 0; while (loopIndex < loopArray.length) { Class<?> clazz = loopArray[loopIndex++]; try { Class.forName(clazz.getName(), true, clazz.getClassLoader()); } catch (ClassNotFoundException e) { throw new AssertionError(e); } } } } /** * Returns a proxy instance that implements {@code interfaceType} by dispatching method * invocations to {@code handler}. The class loader of {@code interfaceType} will be used to * define the proxy class. To implement multiple interfaces or specify a class loader, use {@link * Proxy#newProxyInstance}. * * @throws IllegalArgumentException if {@code interfaceType} does not specify the type of a Java * interface */ public static <T> T newProxy(Class<T> interfaceType, InvocationHandler handler) { checkNotNull(handler); checkArgument(interfaceType.isInterface(), "%s is not an interface", interfaceType); Object object = Proxy.newProxyInstance( interfaceType.getClassLoader(), new Class<?>[] {interfaceType}, handler); return interfaceType.cast(object); } private Reflection() {} }

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.1818.147−59.999
Source linesThe number of non-empty source lines.78+31.2
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.846−7.269

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

Score0.851

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.79−1.761
Indentation frequencyHow rapidly indentation changes from line to line.48+0.923
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.92.519+0.688
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.48−0.681
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.77.911+0.679
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.99.962−0.569
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.053+0.428

Intercept 0.07 + feature contributions = -0.222 (log-odds).
Score = sigmoid(-0.222) = 0.445.

Score0.265
Score19
Run 1

The code is highly readable. It has a clear, logical structure with a private constructor enforcing non-instantiability, well-named public methods, and concise Javadoc explaining intent and edge cases. Nesting is minimal; the only block with a loop is flat with a straightforward try-catch. Each method performs a single, clearly defined action, and lines are kept short and focused. The `initialize` method has a redundant outer block and a manually managed loop index instead of an enhanced for loop, which slightly hurts the reading flow and action granularity. Otherwise, the code is clean, concise, and easy to follow.

Run 2

The code is well-structured, with clear separation of public methods and private constructor. Nested complexity is minimal, and each method is concise. The `initialize` method uses a manual while loop with an unnecessary outer block, which slightly harms readability and action granularity; a standard for-each loop would be clearer. The use of guard-style checks in `newProxy` improves clarity. Javadoc comments are detailed and informative, aiding intent. The static imports and exception handling are straightforward. Overall, the code is highly readable but has a minor awkward loop in `initialize`.

Run 3

The code is highly readable due to its clear logical organization, minimal nesting, and explicit intent. Each public method is documented with Javadoc, explaining its purpose and edge cases. The structure separates overloads cleanly, and helper methods are concise with one action per line. Naming is descriptive, and flow is natural—each method reads top-to-bottom without jumps. Minor issues: the `initialize` method wraps a `while` loop in an unnecessary block and uses verbose manual indexing instead of an enhanced for-loop, slightly reducing readability. The `newProxy` method is well structured but spans multiple lines for a single proxy creation, which is acceptable. Overall, the code is maintainable and easy to understand, with only minor stylistic improvements possible.

Run 1

Code Structure: Well-organized utility class with focused methods, grouped overloads, and a private constructor. Nesting: Mostly flat, but initialize adds an unnecessary block around a while loop and try/catch. Clarity of intent: Descriptive method names and detailed Javadocs clearly explain purpose and behavior; generic names such as object are slightly less informative. Code length: Generally concise, although initialize uses redundant array and index variables instead of a simpler enhanced for loop. Action granularity: Most statements perform one action; accessing the array while incrementing loopIndex combines two actions. Reading flow: Methods read naturally from inputs through validation and execution to results, with consistent formatting. The verbose loop machinery and lack of spacing between package and import declarations introduce minor friction.

Run 2

Code Structure: Well-organized utility class with focused methods and a private constructor. Nesting: Most methods are flat, but initialize adds an unnecessary block around a while loop and try/catch. Clarity of intent: Descriptive method names, explicit validation, and informative Javadocs make the reflection operations clear. Code length: Generally concise; initialize could be shorter and clearer with an enhanced for loop instead of an array alias and manual index. Action granularity: Most statements perform one action, though loopArray[loopIndex++] combines element access with index mutation. Reading flow: Methods follow a natural sequence, and formatting is consistent overall; the redundant loop scaffolding and tightly grouped imports slightly interrupt readability.

Run 3

Code Structure: Well-organized utility class with focused methods and a private constructor. Nesting: Mostly flat, but initialize introduces an unnecessary block around a while loop and try/catch. Clarity of intent: Descriptive method names, explicit validation, and detailed Javadoc clearly explain behavior. Code length: Generally concise; initialize could be shorter and clearer using an enhanced for loop instead of temporary array and index variables. Action granularity: Most lines perform one action, although loopArray[loopIndex++] combines element access and index mutation. Reading flow: Methods follow a natural sequence, and formatting is consistent overall. The manual iteration and redundant scope interrupt otherwise straightforward reading.