Sample

int-2fa7148a9ed1-I11

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

Matched original source

Lines109

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.5120–1; higher is more readable
Dorn0.3110–1; higher is more readable
Mi0.4670–1; higher is more readable
LLOC40Logical lines; fewer is more readable
DeepSeek V4 Pro15.670–20; mean of three runs
GPT-6.1 Sol170–20; mean of three runs
BTTF0.4150–1; higher is more readable

Views

Source code

package org.springframework.cache.jcache.interceptor; import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; import javax.cache.annotation.CacheInvocationParameter; import javax.cache.annotation.CacheKeyGenerator; import javax.cache.annotation.CacheKeyInvocationContext; import org.jspecify.annotations.Nullable; import org.springframework.cache.interceptor.KeyGenerator; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; /** * Spring's {@link KeyGenerator} implementation that either delegates to a standard JSR-107 * {@link javax.cache.annotation.CacheKeyGenerator}, or wrap a standard {@link KeyGenerator} * so that only relevant parameters are handled. * * @author Stephane Nicoll * @author Juergen Hoeller * @since 4.1 */ class KeyGeneratorAdapter implements KeyGenerator { private final JCacheOperationSource cacheOperationSource; private @Nullable KeyGenerator keyGenerator; private @Nullable CacheKeyGenerator cacheKeyGenerator; /** * Create an instance with the given {@link KeyGenerator} so that {@link javax.cache.annotation.CacheKey} * and {@link javax.cache.annotation.CacheValue} are handled according to the spec. */ public KeyGeneratorAdapter(JCacheOperationSource cacheOperationSource, KeyGenerator target) { Assert.notNull(cacheOperationSource, "JCacheOperationSource must not be null"); Assert.notNull(target, "KeyGenerator must not be null"); this.cacheOperationSource = cacheOperationSource; this.keyGenerator = target; } /** * Create an instance used to wrap the specified {@link javax.cache.annotation.CacheKeyGenerator}. */ public KeyGeneratorAdapter(JCacheOperationSource cacheOperationSource, CacheKeyGenerator target) { Assert.notNull(cacheOperationSource, "JCacheOperationSource must not be null"); Assert.notNull(target, "CacheKeyGenerator must not be null"); this.cacheOperationSource = cacheOperationSource; this.cacheKeyGenerator = target; } /** * Return the target key generator to use in the form of either a {@link KeyGenerator} * or a {@link CacheKeyGenerator}. */ public Object getTarget() { if (this.cacheKeyGenerator != null) { return this.cacheKeyGenerator; } Assert.state(this.keyGenerator != null, "No key generator"); return this.keyGenerator; } @Override public Object generate(Object target, Method method, @Nullable Object... params) { JCacheOperation<?> operation = this.cacheOperationSource.getCacheOperation(method, target.getClass()); if (!(operation instanceof AbstractJCacheKeyOperation)) { throw new IllegalStateException("Invalid operation, should be a key-based operation " + operation); } CacheKeyInvocationContext<?> invocationContext = createCacheKeyInvocationContext(target, operation, params); if (this.cacheKeyGenerator != null) { return this.cacheKeyGenerator.generateCacheKey(invocationContext); } else { Assert.state(this.keyGenerator != null, "No key generator"); return doGenerate(this.keyGenerator, invocationContext); } } private static Object doGenerate(KeyGenerator keyGenerator, CacheKeyInvocationContext<?> context) { List<Object> parameters = new ArrayList<>(); for (CacheInvocationParameter param : context.getKeyParameters()) { Object value = param.getValue(); final int a = 2; final int b = -1; if (param.getParameterPosition() == context.getAllParameters().length - (a + b) && context.getMethod().isVarArgs()) { parameters.addAll(CollectionUtils.arrayToList(value)); } else { parameters.add(value); } } return keyGenerator.generate(context.getTarget(), context.getMethod(), parameters.toArray()); } @SuppressWarnings("unchecked") private CacheKeyInvocationContext<?> createCacheKeyInvocationContext( Object target, JCacheOperation<?> operation, @Nullable Object[] params) { AbstractJCacheKeyOperation<Annotation> keyCacheOperation = (AbstractJCacheKeyOperation<Annotation>) operation; return new DefaultCacheKeyInvocationContext<>(keyCacheOperation, target, params); } }

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.3908.413−128.978
Source linesThe number of non-empty source lines.109+43.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.4.94−7.41

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

Score0.512

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.110−2.858
Indentation frequencyHow rapidly indentation changes from line to line.93+2.48
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.93−1.713
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.108.858+1.112
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.111.964−1.077
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.111.855+1
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.077+0.191

Intercept 0.07 + feature contributions = -0.796 (log-odds).
Score = sigmoid(-0.796) = 0.311.

Score0.467
Score40
Run 1

The code is generally well-structured and readable. It has clear class responsibilities, logical method separation, and good Javadoc comments. The nesting level is shallow, and most methods are concise. However, the score is reduced due to the confusing expression in doGenerate: `context.getAllParameters().length - (a + b)` with unexplained variables `a` and `b` (values 2 and -1). This obscures intent. Additionally, the method `doGenerate` mixes logic (varargs check) with collection building in a single block, slightly reducing action granularity. The adapter constructors are clear, but the dual state fields (`keyGenerator` vs `cacheKeyGenerator`) introduce minor ambiguity. Overall, it is maintainable and clean but has localized readability issues.

Run 2

The code is generally well-structured, with clear class responsibilities, good use of constructors, and meaningful method names. Imports are organized, and Javadocs explain intent. However, readability is hindered by a few issues: the `doGenerate` method contains magic numbers and unclear logic (`a` and `b` constants) that obscure the varargs handling; the method has moderate nesting and mixes conditionals with collection logic. While most actions are one per line, some expressions are dense. The `generate` method has a slightly tangled flow due to nested if/else and casting. Overall, the structure and intent are clear, but the presence of unexplained constants and somewhat complex control flow reduces readability from excellent to good.

Run 3

The code is generally well-structured with clear class responsibilities, logical method organization, and good use of Javadoc. It reads naturally: constructors, getters, core logic, then private helpers. Nesting is shallow, and most lines perform one clear action. However, readability is reduced by a few issues: the magic numbers 'a' and 'b' in the varargs check are unintuitive and obscure the logic (e.g., why 'length - (2 + -1)'?). The conditional logic for handling varargs parameters could be extracted into a named method to improve intent clarity. Additionally, the null-check and exception messages are clear, but the dual key generator fields (keyGenerator vs cacheKeyGenerator) require careful reading to understand their mutual exclusivity. Overall, the code is professional and maintainable but would benefit from clearer varargs handling and eliminating magic numbers.

Run 1

Code Structure: Well-organized adapter with distinct constructors and focused helper methods; minor constructor duplication. Nesting: Shallow conditionals and a single loop keep control flow manageable. Clarity of intent: Descriptive names, documentation, and explicit assertions explain delegation and parameter handling. However, constants a = 2 and b = -1 obscure a simple last-parameter check, and varargs expansion lacks an explanatory comment. Code length: Generally concise, though redundant constants and repeated initialization add unnecessary lines. Action granularity: Statements consistently perform one action per line. Reading flow: Methods progress naturally from construction to delegation and context creation, with consistent formatting; the multiline varargs condition and generic cast introduce modest reading friction.

Run 2

Code Structure: Well-organized adapter with focused constructors and helper methods separating delegation, parameter processing, and context creation. Nesting: Generally shallow; the loop with an embedded conditional remains easy to follow. Clarity of intent: Descriptive names, documentation, and assertions communicate the purpose clearly, but the unexplained constants a and b and expression (a + b) obscure a simple last-parameter check. Code length: Mostly concise, with minor constructor duplication and unnecessary constants. Action granularity: Statements generally perform one action per line, making execution easy to trace. Reading flow: Methods follow a natural progression from initialization to delegation and supporting helpers; the compound varargs condition and generic cast introduce modest cognitive overhead.

Run 3

Code Structure: Constructors, delegation, parameter processing, and context creation are cleanly separated into focused methods. Nesting: Control flow remains shallow, with only a conditional inside the parameter loop. Clarity of intent: Descriptive class and method names, documentation, and assertions clearly communicate the adapter's purpose; however, the arbitrary constants a = 2 and b = -1 obscure the straightforward last-parameter check. Code length: Mostly concise, though those constants and some repeated validation add minor verbosity. Action granularity: Statements generally perform one action per line, making execution easy to follow. Reading flow: The progression from construction to target selection, generation, and helpers is natural. The multiline varargs condition and generic cast introduce modest cognitive overhead, but the unexplained arithmetic is the main readability weakness.