Sample

int-5f615ece9bde-I12

Inline all eligible single-use intermediate local variables

Matched original source

Lines72

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.8520–1; higher is more readable
Dorn0.4760–1; higher is more readable
Mi0.2650–1; higher is more readable
LLOC15Logical lines; fewer is more readable
DeepSeek V4 Pro180–20; mean of three runs
GPT-6.1 Sol18.330–20; mean of three runs
BTTF0.7410–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) { for (Class<?> clazz : classes) { 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); return interfaceType.cast((Proxy.newProxyInstance( interfaceType.getClassLoader(), new Class<?>[] {interfaceType}, handler))); } 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.1599.743−52.792
Source linesThe number of non-empty source lines.72+28.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.4.845−7.268

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

Score0.852

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.71−1.478
Indentation frequencyHow rapidly indentation changes from line to line.42+0.716
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.90.479+0.655
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.71.851+0.595
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.986−0.57
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.42−0.543
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.05+0.458

Intercept 0.07 + feature contributions = -0.096 (log-odds).
Score = sigmoid(-0.096) = 0.476.

Score0.265
Score15
Run 1

The code demonstrates excellent readability across all criteria. Structure is logical with clear separation of related utilities and a private constructor preventing instantiation. Nesting is consistently flat - the only loop and try-catch blocks are minimal and necessary. Intent is immediately clear from the descriptive method names and thorough Javadoc comments that explain edge cases and rationale. Code length is appropriate; no method is excessively long or unnecessarily verbose. Action granularity is well-balanced, with each meaningful step on its own line while avoiding fragmentation. Reading flow is natural, progressing from simpler operations to more complex ones with clear documentation guiding the reader. The one minor deduction comes from the newProxy method's cast and nested Proxy.newProxyInstance call being slightly dense, but the surrounding documentation and formatting mitigate confusion. Overall, this represents production-quality readable code.

Run 2

The code is highly readable. It follows a logical structure: imports, a final class with private constructor, and well-documented public methods. Javadoc comments clearly explain each method's purpose, edge cases, and rationale. Nesting is minimal, with only a try-catch inside a loop in initialize(). The intent of each method is unambiguous. Code length is concise and appropriate—no redundancy or verbose boilerplate. Action granularity is good, with most lines performing a single logical operation; the newProxy method combines a cast and Proxy creation, but this remains understandable. Reading flow is natural, with methods ordered by conceptual relevance and clear parameter validation. The only minor nit is the slightly dense cast/Proxy line, but overall this aligns well with typical high-quality Java library code.

Run 3

The code demonstrates excellent readability through clear structure, flat nesting, and well-documented intent. Methods are concise with single responsibilities: getPackageName parses strings logically, initialize loops through classes with minimal nesting, and newProxy validates inputs and delegates proxy creation cleanly. Naming is descriptive and follows Java conventions. Javadoc comments thoroughly explain behavior, edge cases, and warnings, enhancing clarity. Action granularity is appropriate - each line performs one logical operation. Reading flow is natural, following a logical progression from simple utilities to more complex reflection operations. Minor deductions: the newProxy method has slightly more complex casting and indentation, and the initialize method's exception handling adds modest nesting depth. Overall, the code exemplifies clean, maintainable utility class design with strong separation of concerns and effective documentation that balances completeness with readability.

Run 1

Code Structure: Well-organized utility class with focused methods and a private constructor. Nesting: Mostly flat; the loop and try/catch in initialize add only modest, necessary nesting. Clarity of intent: Descriptive names and thorough Javadocs clearly explain behavior and constraints. Code length: Implementations are concise, although documentation is somewhat verbose. Action granularity: Generally one action per statement, with validation separated from proxy creation; the proxy return expression combines several operations but remains understandable. Reading flow: Methods follow a natural sequence, and overload delegation is straightforward. Minor distractions include tightly grouped imports, redundant parentheses, and awkward indentation in the proxy creation expression.

Run 2

Code Structure: A well-organized utility class groups small, related reflection methods and prevents instantiation. Nesting: Mostly flat; only initialization introduces a shallow loop and try/catch. Clarity of intent: Descriptive method and variable names, useful Javadoc, and explicit argument validation make purposes clear. Code length: Implementations are concise; documentation is lengthy but provides relevant context. Action granularity: Each statement performs a focused action, with the proxy construction expression slightly denser than the rest. Reading flow: Overloads appear together, and methods follow a natural sequence. Minor distractions include tightly grouped imports, redundant parentheses around proxy construction, and awkward indentation of its multiline return statement.

Run 3

Code Structure: Small, focused utility methods are logically organized, with a private constructor preventing instantiation. Nesting: Minimal overall; only initialize uses a straightforward loop with try/catch. Clarity of intent: Descriptive method and variable names, explicit validation, and informative Javadocs clearly explain behavior. Code length: Implementations are concise; documentation is extensive but relevant. Action granularity: Each statement performs a distinct action, though the proxy return combines creation and casting in one expression. Reading flow: Consistent formatting and simple delegation make the code easy to follow. Minor distractions include missing spacing between import groups and redundant parentheses with awkward indentation in newProxy.