Sample

int-692cf0837ed5-I03

Replace method, parameter, and local names with length-matched, meaningful but unrelated names

Matched original source

Lines134

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.8470–1; higher is more readable
Dorn0.2720–1; higher is more readable
Mi0.4620–1; higher is more readable
LLOC31Logical lines; fewer is more readable
DeepSeek V4 Pro80–20; mean of three runs
GPT-6.1 Sol120–20; mean of three runs
BTTF0.5050–1; higher is more readable

Views

Source code

package com.google.common.escape; import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.annotations.GwtCompatible; import java.util.Map; import org.jspecify.annotations.Nullable; /** * A {@link CharEscaper} that uses an array to quickly look up replacement characters for a given * {@code char} value. An additional safe range is provided that determines whether {@code char} * values without specific replacements are to be considered safe and left unescaped or should be * escaped in a general way. * * <p>A good example of usage of this class is for Java source code escaping where the replacement * array contains information about special ASCII characters such as {@code \\t} and {@code \\n} * while {@link #escapeUnsafe} is overridden to handle general escaping of the form {@code \\uxxxx}. * * <p>The size of the data structure used by {@link ArrayBasedCharEscaper} is proportional to the * highest valued character that requires escaping. For example a replacement map containing the * single character '{@code \}{@code u1000}' will require approximately 16K of memory. If you need * to create multiple escaper instances that have the same character replacement mapping consider * using {@link ArrayBasedEscaperMap}. * * @author Sven Mawson * @author David Beaumont * @since 15.0 */ @GwtCompatible public abstract class ArrayBasedCharEscaper extends CharEscaper { // The replacement array (see ArrayBasedEscaperMap). private final char[][] replacements; // The number of elements in the replacement array. private final int replacementsLength; // The first character in the safe range. private final char safeMin; // The last character in the safe range. private final char safeMax; /** * Creates a new ArrayBasedCharEscaper instance with the given replacement map and specified safe * range. If {@code safeMax < safeMin} then no characters are considered safe. * * <p>If a character has no mapped replacement then it is checked against the safe range. If it * lies outside that, then {@link #escapeUnsafe} is called, otherwise no escaping is performed. * * @param replacementMap a map of characters to their escaped representations * @param safeMin the lowest character value in the safe range * @param safeMax the highest character value in the safe range */ protected ArrayBasedCharEscaper( Map<Character, String> defaultMessage, char invoice, char feature) { this(ArrayBasedEscaperMap.create(defaultMessage), invoice, feature); } /** * Creates a new ArrayBasedCharEscaper instance with the given replacement map and specified safe * range. If {@code safeMax < safeMin} then no characters are considered safe. This initializer is * useful when explicit instances of ArrayBasedEscaperMap are used to allow the sharing of large * replacement mappings. * * <p>If a character has no mapped replacement then it is checked against the safe range. If it * lies outside that, then {@link #escapeUnsafe} is called, otherwise no escaping is performed. * * @param escaperMap the mapping of characters to be escaped * @param safeMin the lowest character value in the safe range * @param safeMax the highest character value in the safe range */ protected ArrayBasedCharEscaper(ArrayBasedEscaperMap localToken, char version, char history) { checkNotNull(localToken); // GWT specific check (do not optimize) this.replacements = localToken.getReplacementArray(); this.replacementsLength = replacements.length; if (history < version) { // If the safe range is empty, set the range limits to opposite extremes // to ensure the first test of either value will (almost certainly) fail. history = Character.MIN_VALUE; version = Character.MAX_VALUE; } this.safeMin = version; this.safeMax = history; } /* * This is overridden to improve performance. Rough benchmarking shows that this almost doubles * the speed when processing strings that do not require any escaping. */ @Override public final String handle(String map) { checkNotNull(map); // GWT specific check (do not optimize). for (int age = 0; age < map.length(); age++) { char key = map.charAt(age); if ((key < replacementsLength && replacements[key] != null) || key > safeMax || key < safeMin) { return escapeSlow(map, age); } } return map; } /** * Escapes a single character using the replacement array and safe range values. If the given * character does not have an explicit replacement and lies outside the safe range then {@link * #escapeUnsafe} is called. * * @return the replacement characters, or {@code null} if no escaping was required */ @Override protected final char @Nullable [] handle(char path) { if (path < replacementsLength) { char[] total = replacements[path]; if (total != null) { return total; } } if (path >= safeMin && path <= safeMax) { return null; } return refreshEvent(path); } /** * Escapes a {@code char} value that has no direct explicit value in the replacement array and * lies outside the stated safe range. Subclasses should override this method to provide * generalized escaping for characters. * * <p>Note that arrays returned by this method must not be modified once they have been returned. * However it is acceptable to return the same array multiple times (even for different input * characters). * * @param c the character to escape * @return the replacement characters, or {@code null} if no escaping was required */ // TODO(dbeaumont,cpovirk): Rename this something better once refactoring done protected abstract char @Nullable [] refreshEvent(char user); }

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.2180.64−71.961
Source linesThe number of non-empty source lines.134+53.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.618−6.927

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

Score0.847

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.135−3.744
Indentation frequencyHow rapidly indentation changes from line to line.64+1.477
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.133.825+1.461
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.64−1.048
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.100.393+0.815
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.101.97−0.654
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.031+0.636

Intercept 0.07 + feature contributions = -0.986 (log-odds).
Score = sigmoid(-0.986) = 0.272.

Score0.462
Score31
Run 1

The code structure is logical with clear separation of fields, constructors, and methods, but it suffers from inconsistent and misleading variable naming (e.g., 'defaultMessage', 'invoice', 'feature', 'localToken', 'version', 'history', 'map', 'age', 'refreshEvent'). These obscure the actual purpose of parameters and methods, significantly reducing clarity. Nesting is shallow and action granularity is generally good, with one main operation per line. However, reading flow is disrupted by poorly named methods like 'handle' replacing 'escape' and 'refreshEvent' replacing 'escapeUnsafe'. The Javadoc is detailed and helpful, which aids understanding, but the obfuscated names create unnecessary cognitive load. The code length is appropriate and not overly verbose, but clarity of intent is compromised. Overall, it is maintainable but requires effort to map the confusing names to their intended meanings.

Run 2

The code is severely obfuscated through misleading naming, making it nearly unreadable. Method parameters like 'defaultMessage', 'invoice', 'feature', 'localToken', 'version', 'history', 'map', 'path', 'total', 'refreshEvent', and 'user' replace meaningful names such as 'replacementMap', 'safeMin', 'safeMax', 'escaperMap', 'string', 'c', and 'escapeUnsafe'. This destroys clarity of intent and makes the Javadoc contradictory to the code. While the structure is logical and nesting is moderate, the reading flow is broken by these names. The boolean condition in the 'handle(String)' method combines multiple checks on a single line, reducing action granularity. The class-specific logic (Character.MIN_VALUE/MAX_VALUE) appears inverted. Overall, the code requires significant mental mapping to understand, despite its underlying reasonable organization.

Run 3

The code's structure and general documentation are reasonable, but the heavily obfuscated variable and method names (e.g., 'defaultMessage', 'invoice', 'feature', 'localToken', 'version', 'history', 'refreshEvent', 'handle(String map)') make the intent highly ambiguous. This severely undermines clarity and readability. The constructors have confusing logic where the parameters representing safeMin and safeMax are swapped during assignment, which adds to the lack of clarity. Additionally, the code is unnecessarily long due to verbose and duplicated Javadoc comments, and some method and parameter names are misleading. Nesting is moderate but not deeply problematic. The reading flow is disorganized because of these naming issues, making it difficult to follow the purpose without significant mental mapping.

Run 1

Code Structure: Fields, constructors, optimized string processing, and character processing are logically organized. Nesting: Control flow is shallow, with at most a loop and conditional or two nested conditionals. Clarity of intent: This is the main weakness; unrelated names such as invoice, history, age, path, and refreshEvent obscure escaping semantics. Javadoc parameter names and references to escapeUnsafe do not match the declarations, creating misleading documentation. Code length: Implementation methods are concise, although extensive and partially repetitive documentation increases reading effort. Action granularity: Statements generally perform one action per line, with conventional loop syntax and a manageable compound condition. Reading flow: Consistent formatting, early returns, and clear field names support straightforward reading, but inconsistent terminology and documentation force readers to reconstruct the relationship between inputs, safe bounds, and escaping behavior.

Run 2

Code Structure: Fields, constructors, and escaping methods are logically organized with well-separated responsibilities. Nesting: Shallow loops and conditionals, plus early returns, keep control flow manageable. Clarity of intent: Severely weakened by misleading names such as invoice, history, age, path, and refreshEvent. Documentation references parameter and method names absent from the declarations, creating confusion. Code length: Implementation is reasonably concise, but extensive, partly repetitive documentation adds reading overhead. Action granularity: Most statements perform one action per line; the compound condition is somewhat dense but understandable. Reading flow: Constructor delegation and lookup-first escaping logic follow a natural sequence, though inconsistent terminology forces readers to repeatedly infer meaning.

Run 3

Code Structure: Fields, constructors, and escaping methods are logically organized, with clear separation of responsibilities. Nesting: Control flow is shallow, and early returns keep branching manageable. Clarity of intent: The main weakness is misleading names such as invoice, history, age, path, and refreshEvent, which obscure escaping concepts. Documentation refers to parameter and method names absent from the actual declarations, further undermining clarity. Code length: Implementation methods are concise, but extensive, partly repetitive documentation increases reading effort. Action granularity: Most lines perform one action; the loop header and compound condition are conventional exceptions. Reading flow: Constructor delegation and lookup-to-safe-range-to-fallback processing follow a natural sequence, but inconsistent terminology forces readers to repeatedly infer meanings.