Sample

int-91744f7cc7ab-I05

Rewrite eligible decimal integer literals in hexadecimal notation

Matched original source

Lines107

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.5120–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 Pro16.330–20; mean of three runs
GPT-6.1 Sol17.330–20; mean of three runs
BTTF0.3660–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 - 0x1 && 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.3777.695−124.664
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.937−7.405

Intercept 8.87 + feature contributions = -80.399 (log-odds).
Score = sigmoid(-80.399) = 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.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.85+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 generally readable with clear class structure, logical method organization, and good naming conventions. The constructors are well-documented with meaningful Javadoc. Most methods follow the single-responsibility principle and maintain flat nesting levels. The main generate() method has a clear flow: validate operation type, create context, then delegate to either cacheKeyGenerator or keyGenerator. The doGenerate() method effectively handles varargs with a reasonable if-else block. Minor readability issues include: the magic number '0x1' in the varargs check (should be a named constant or simple '1'), the somewhat dense parameter validation in generate(), and the unchecked cast requiring @SuppressWarnings. The getTarget() method has slightly awkward null-checking logic but remains understandable. Overall, the code demonstrates good Spring framework conventions and maintains clear separation of concerns, though a few minor improvements could enhance clarity further.

Run 2

The code is well-structured, with clear separation of concerns and a logical organization into two constructors, a public API method, and private helper methods. Nesting is generally shallow; the only slightly complex block is the varargs handling in doGenerate, but it remains readable. Intent is clearly expressed through descriptive method and variable names, javadoc, and Spring's Assert usage. Code length is moderate and mostly concise, though some null-state checks are repeated. Action granularity is good—most lines perform a single operation. Reading flow is natural, with methods ordered from public API to private helpers. Minor deductions: repeated null/state assertions could be simplified, and the varargs check (length - 0x1) is slightly less clear than using - 1 or a helper.

Run 3

The code is well-structured with clear class organization, logical method separation, and meaningful naming that makes intent obvious. Nesting is minimal, with only one level of conditional logic in generate() and doGenerate(). Each method has a single responsibility, and actions are generally one per line. The constructor validation and field declarations are clean. Minor readability issues include the cryptic '0x1' expression (should be '1' for clarity), the slightly awkward boolean expression in generate() that could use 'instanceof' with pattern matching or negated logic, and the multi-line boolean condition wrapped without obvious line-break reasoning. Import ordering and vertical spacing are good. The Javadoc could more explicitly explain the varargs handling edge case. Overall the code is concise, maintainable, and follows Spring conventions well, with only a few small clarity improvements possible.

Run 1

Code Structure: Well-organized adapter with distinct constructors, delegation logic, parameter preparation, and context creation. Nesting: Shallow overall; the loop with an inner conditional is easy to follow. Clarity of intent: Descriptive names, Javadoc, and assertions explain the purpose and invariants. However, the hexadecimal 0x1 unnecessarily obscures a simple last-parameter check, and varargs flattening could benefit from a brief comment. Code length: Reasonably concise, although constructors duplicate validation and initialization, and generate contains an avoidable else after an early return. Action granularity: Statements generally perform one action per line; the compound conditional remains manageable. Reading flow: Methods progress naturally from construction to delegation and supporting helpers. Consistent formatting helps, though tightly grouped imports and occasional extra blank lines slightly reduce polish.

Run 2

Code Structure: Well-organized adapter with clearly separated constructors, delegation logic, parameter handling, and context creation. Nesting: Shallow overall; the loop with an inner conditional is easy to follow. Clarity of intent: Descriptive names, documentation, and explicit assertions explain the purpose, although hexadecimal 0x1 unnecessarily obscures a simple last-parameter check, and two nullable delegate fields require understanding an implicit invariant. Code length: Appropriately concise, with minor repetition in constructor validation and delegate checks. Action granularity: Statements generally perform one action per line; chained calls remain manageable. Reading flow: Natural progression from initialization to public behavior and private helpers, supported by consistent formatting. Long type names and the multiline varargs condition slightly slow reading.

Run 3

Code Structure: Constructors, delegation logic, and context creation are logically separated into focused methods. Nesting: Mostly shallow, with only a loop containing an if/else in parameter handling. Clarity of intent: Descriptive names, documentation, and assertions clearly explain the adapter's purpose; however, two nullable generator fields imply an exclusive-choice invariant rather than expressing it directly, and hexadecimal 0x1 unnecessarily obscures a simple subtraction. Code length: Reasonably concise, though constructor validation and generator checks repeat slightly. Action granularity: Statements generally perform one action per line, making execution easy to follow. Reading flow: The progression from initialization to target selection, generation, and helper methods is natural. Long generic declarations, the multiline varargs condition, and an unchecked cast introduce minor reading friction.