Sample

int-f1e207bc82dd-I02

Shorten method, parameter, and local names without collisions

Matched original source

Lines134

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.8670–1; higher is more readable
Dorn0.2740–1; higher is more readable
Mi0.4770–1; higher is more readable
LLOC31Logical lines; fewer is more readable
DeepSeek V4 Pro16.330–20; mean of three runs
GPT-6.1 Sol150–20; mean of three runs
BTTF0.570–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> replacement, char safe, char safe2) { this(ArrayBasedEscaperMap.create(replacement), safe, safe2); } /** * 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 escaper, char safe3, char safe4) { checkNotNull(escaper); // GWT specific check (do not optimize) this.replacements = escaper.getReplacementArray(); this.replacementsLength = replacements.length; if (safe4 < safe3) { // 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. safe4 = Character.MIN_VALUE; safe3 = Character.MAX_VALUE; } this.safeMin = safe3; this.safeMax = safe4; } /* * 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 esc(String s) { checkNotNull(s); // GWT specific check (do not optimize). for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if ((c < replacementsLength && replacements[c] != null) || c > safeMax || c < safeMin) { return escapeSlow(s, i); } } return s; } /** * 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 [] esc(char c) { if (c < replacementsLength) { char[] cha = replacements[c]; if (cha != null) { return cha; } } if (c >= safeMin && c <= safeMax) { return null; } return escape(c); } /** * 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 [] escape(char c); }

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.2162.197−71.352
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.611−6.917

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

Score0.867

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.871+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.96.244+0.748
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.032+0.63
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.985−0.57

Intercept 0.07 + feature contributions = -0.975 (log-odds).
Score = sigmoid(-0.975) = 0.274.

Score0.477
Score31
Run 1

The class is well-structured and follows typical Java conventions, with logical organization of fields, constructors, and methods, and clear separation of concerns via utility methods. Nesting is shallow everywhere, and intent is mostly clear with meaningful names and helpful Javadoc. However, there are notable readability issues: parameter names like `safe`, `safe2`, `safe3`, `safe4` are misleading and inconsistent with the documentation; the single-character variable names `c`, `s`, `i` are acceptable but `cha` is less conventional. The `esc(String)` method crams multiple actions into a single long if-statement, reducing clarity and action granularity. The constructor has a slightly obscure comment about setting extremes. While the code is fairly concise, some lines are dense and would benefit from being split for improved reading flow. Overall, it is reasonably readable but has localized areas where clarity could be improved.

Run 2

The code is well-structured with clear separation of concerns, appropriate documentation, and logical organization. It maintains flat nesting throughout, with only two-level conditionals at most. Intent is clearly expressed through descriptive method names, comprehensive Javadoc, and inline comments explaining non-obvious decisions like the safe range inversion and GWT-specific checks. Code length is appropriate given the domain complexity. Action granularity is good, with one logical operation per line. Reading flow is natural, moving from class documentation through fields, constructors, and methods in a logical progression. Minor deductions for the awkward parameter names (safe/safe2, safe3/safe4) that could be more descriptive, and the slightly dense conditional in the escape method that combines multiple checks on one line.

Run 3

The code is well-structured and highly readable. It has clear separation of concerns with logical field grouping and well-documented class/method purposes. Nesting depth is minimal (3 levels at most), and each line performs a single action. The constructor overloads, while slightly redundant in documentation, are clearly intented. Parameter names like 'safe', 'safe2', 'safe3', 'safe4' are ambiguous and detract from readability, though the accompanying Javadoc clarifies their meaning. The 'esc' method is concise and efficient, with a readble flow and good performance-oriented comments. Overall, the code maintains strong clarity, though minor improvements to parameter naming would make it even more readable.

Run 1

Code Structure: Fields, constructors, and escaping methods are logically organized, with clear separation of responsibilities. Nesting: Shallow loops and conditionals, plus early returns, keep control flow easy to follow. Clarity of intent: Extensive documentation explains the algorithm, but names such as safe2, safe3, safe4, cha, and esc obscure meaning. Constructor documentation uses parameter names that do not match the signatures, and references to escapeUnsafe conflict with the declared escape method. Code length: Implementation is concise; repeated constructor documentation adds some unnecessary length. Action granularity: Statements generally perform one action per line, although the combined replacement-and-range condition requires careful reading. Reading flow: Initialization, fast string scanning, and character handling follow a natural sequence, but inconsistent naming and documentation interrupt comprehension.

Run 2

Code Structure: Fields, constructors, and escaping methods are logically organized with clear separation of responsibilities. Nesting: Control flow is shallow, with at most two nested conditional levels. Clarity of intent: Detailed documentation explains replacement lookup and safe-range behavior, but vague names such as safe2, safe3, safe4, and cha reduce clarity. Documentation references escapeUnsafe and parameter names that do not match the implementation, while esc versus escape makes the method roles harder to distinguish. Code length: Implementation is concise, although constructor documentation is repetitive. Action granularity: Statements generally perform one action per line; the combined lookup and range condition is compact but requires careful reading. Reading flow: Constructor delegation and early returns provide a natural progression, weakened by inconsistent naming and documentation mismatches.

Run 3

Code Structure: Fields, constructors, and escaping methods are logically grouped, with clear separation of responsibilities. Nesting: Control flow is shallow, using early returns and only one nested conditional. Clarity of intent: Class documentation explains the algorithm well, but names such as safe2, safe3, safe4, cha, and esc obscure meaning. Documentation references escapeUnsafe and parameter names that do not match the declarations, adding confusion. Code length: Implementation is concise; extensive documentation is useful but somewhat repetitive. Action granularity: Statements generally perform one action per line, although the string-scanning condition combines several checks. Reading flow: Initialization followed by string and character processing is natural, but inconsistent naming and stale documentation interrupt understanding.