Sample

int-aa949608cc02-SRC

Unmodified source class

Lines107

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.5110–1; higher is more readable
Dorn0.3140–1; higher is more readable
Mi0.4670–1; higher is more readable
LLOC38Logical lines; fewer is more readable
DeepSeek V4 Pro17.330–20; mean of three runs
GPT-6.1 Sol180–20; mean of three runs
BTTF0.5050–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(); if (param.getParameterPosition() == context.getAllParameters().length - 1 && 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.3763.655−124.201
Source linesThe number of non-empty source lines.107+42.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.934−7.402

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

Score0.511

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.108−2.788
Indentation frequencyHow rapidly indentation changes from line to line.91+2.41
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.91−1.667
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.106.841+1.084
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.981−1.078
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.110.907+0.985
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.076+0.203

Intercept 0.07 + feature contributions = -0.781 (log-odds).
Score = sigmoid(-0.781) = 0.314.

Score0.467
Score38
Run 1

The code is well-structured with clear separation of concerns and straightforward logic. The class has a cohesive purpose as an adapter between two key generator types. Nesting is minimal - only one conditional branch in generate() and a simple if/else in doGenerate(). Clarity of intent is strong with descriptive method names and meaningful validation messages. The Javadoc comments explain the design rationale for both constructors. Code length is appropriate - no unnecessary verbosity while maintaining readability. Action granularity is mostly good, though some lines combine multiple operations (e.g., method chain calls). The reading flow is natural: validate input, retrieve operation, create context, delegate to appropriate generator. Minor deductions: the varargs handling logic in doGenerate() could use extraction for better clarity, and the null-check pattern with Assert.state() before returning keyGenerator in getTarget() is slightly redundant with the field being @Nullable. Overall, this is production-quality Spring framework code that balances conciseness with readability effectively.

Run 2

The code is well-structured with clear separation of concerns, appropriate constructors, and a clean delegation pattern. It maintains a flat structure with minimal nesting - only one level of if-else in generate() and doGenerate(). Variable and method names clearly express intent (e.g., createCacheKeyInvocationContext, doGenerate). The class is reasonably concise without unnecessary boilerplate. Each line performs a single logical action, and the reading flow follows a natural top-to-bottom progression. Minor deductions: the varargs handling condition could be extracted for clarity, and the unchecked cast requires a suppression annotation which slightly obscures intent. Overall, this is highly readable Java code that follows Spring framework conventions well.

Run 3

The code demonstrates excellent readability with a clear, logical structure: fields, constructors, public methods, then private helpers. Import organization and class-level documentation are well done. Nesting is minimal—the deepest level is two blocks in doGenerate and generate. Intent is clear from descriptive method/field names (e.g., getTarget, doGenerate, createCacheKeyInvocationContext) and inline comments that explain non-obvious varargs handling. Code is concise without unnecessary duplication. Action granularity is mostly one action per line, though a few lines combine method calls with control flow (e.g., the varargs check). Reading flow is natural, progressing from high-level public API to lower-level private helpers. Minor deductions: the unchecked cast in createCacheKeyInvocationContext requires a @SuppressWarnings annotation and slightly reduces clarity, and the else branch after the if in generate could be flattened by returning early, but these are minor concerns in an otherwise very clean implementation.

Run 1

Code Structure: Clearly organized fields, constructors, public methods, and focused private helpers separate responsibilities. Nesting: Mostly flat, with early validation and only a loop containing a simple conditional. Clarity of intent: Descriptive names, documentation, and explicit assertions make the adapter's two delegation paths understandable; nullable alternative fields and the unchecked cast add minor cognitive overhead. Code length: Appropriately concise, though constructor validation is duplicated and some branching could be simplified. Action granularity: Each statement performs one clear action, with no compressed multi-statement lines. Reading flow: Natural progression from initialization to delegation and parameter preparation; the multiline varargs condition and framework-specific types require slightly closer reading.

Run 2

Code Structure: Well-organized adapter with distinct constructors, delegation logic, parameter processing, and context creation. Nesting: Shallow overall; only the parameter loop contains an inner conditional. Clarity of intent: Descriptive names, documentation, and explicit assertions make the two generator modes clear. The nullable alternative fields, unchecked cast, and varargs handling require some additional interpretation. Code length: Appropriately concise, with minor duplication in constructor validation and generator checks. Action granularity: Statements generally perform one action per line; the compound varargs condition remains readable. Reading flow: Methods progress naturally from construction to target access, generation, and supporting helpers. Consistent formatting supports scanning, although long generic types and framework-specific abstractions slightly increase cognitive load.

Run 3

Code Structure: Well-organized adapter with distinct constructors, delegation logic, and focused helper methods. Nesting: Shallow overall; only parameter processing combines a loop with an if/else. Clarity of intent: Descriptive names, documentation, and explicit assertions clearly communicate the two generator modes, although mutually exclusive nullable fields and the unchecked cast add some cognitive overhead. Code length: Appropriately concise, with minor repetition in constructors and state checks. Action granularity: Statements generally perform one action per line; longer expressions remain understandable. Reading flow: Natural progression from initialization to target access, generation, and supporting helpers. The multiline varargs condition and generic types slightly slow reading, but consistent formatting and clear method boundaries maintain strong readability.