Sample

Schnappinger/junit4/org.junit.internal.MethodSorter

Human rating uses the original dataset scale.

Human4
Lines72

Scores

MethodScoreScaleDataset rank
(0–100)
Posnett00–1; higher is more readable
49.5Δ 44.6
Scalabrino0.6940–1; higher is more readable
37.0Δ 57.1
Dorn0.360–1; higher is more readable
52.5Δ 41.6
Mi0.3650–1; higher is more readable
22.4Δ 71.6
LLOC24Logical lines; fewer is more readable
54.3Δ 39.8
DeepSeek V4 Pro170–20; mean of three runs
66.8Δ 27.2
GPT-6.1 Sol180–20; mean of three runs
73.8Δ 20.3
BTTF0.5650–1; higher is more readable
52.1Δ 41.9
Human41–4; original rating
94.1

Views

Source code

package org.junit.internal; import java.lang.reflect.Method; import java.util.Arrays; import java.util.Comparator; import org.junit.FixMethodOrder; public class MethodSorter { /** * DEFAULT sort order */ public static final Comparator<Method> DEFAULT = new Comparator<Method>() { public int compare(Method m1, Method m2) { int i1 = m1.getName().hashCode(); int i2 = m2.getName().hashCode(); if (i1 != i2) { return i1 < i2 ? -1 : 1; } return NAME_ASCENDING.compare(m1, m2); } }; /** * Method name ascending lexicographic sort order, with {@link Method#toString()} as a tiebreaker */ public static final Comparator<Method> NAME_ASCENDING = new Comparator<Method>() { public int compare(Method m1, Method m2) { final int comparison = m1.getName().compareTo(m2.getName()); if (comparison != 0) { return comparison; } return m1.toString().compareTo(m2.toString()); } }; /** * Gets declared methods of a class in a predictable order, unless @FixMethodOrder(MethodSorters.JVM) is specified. * * Using the JVM order is unwise since the Java platform does not * specify any particular order, and in fact JDK 7 returns a more or less * random order; well-written test code would not assume any order, but some * does, and a predictable failure is better than a random failure on * certain platforms. By default, uses an unspecified but deterministic order. * * @param clazz a class * @return same as {@link Class#getDeclaredMethods} but sorted * @see <a href="http://bugs.sun.com/view_bug.do?bug_id=7023180">JDK * (non-)bug #7023180</a> */ public static Method[] getDeclaredMethods(Class<?> clazz) { Comparator<Method> comparator = getSorter(clazz.getAnnotation(FixMethodOrder.class)); Method[] methods = clazz.getDeclaredMethods(); if (comparator != null) { Arrays.sort(methods, comparator); } return methods; } private MethodSorter() { } private static Comparator<Method> getSorter(FixMethodOrder fixMethodOrder) { if (fixMethodOrder == null) { return DEFAULT; } return fixMethodOrder.value().getComparator(); } }

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.1867.718−61.635
Source linesThe number of non-empty source lines.72+28.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.688−7.032

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

Score0.694

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.73−1.548
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.118.973−1.374
Indentation frequencyHow rapidly indentation changes from line to line.55+1.165
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.118.959+1.115
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.55−0.841
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.71.875+0.595
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.072+0.243

Intercept 0.07 + feature contributions = -0.576 (log-odds).
Score = sigmoid(-0.576) = 0.36.

Score0.365
Score24
Run 1

The code is well-structured with clear separation of concerns: comparators are defined as constants, the sorting logic is centralized in getDeclaredMethods, and helper methods have single responsibilities. Nesting is minimal with only one level of conditionals. Intent is clearly documented through Javadoc comments and descriptive method/field names. Code length is appropriate for the functionality. Action granularity is generally one action per line, though the ternary-like return in getSorter could be slightly more explicit. Reading flow is natural, progressing from public API to private helpers. Minor deductions: the DEFAULT comparator's hash-based comparison could use Integer.compare for clarity, and getSorter's null check adds slight cognitive overhead.

Run 2

The code is well-structured with clear separation of concerns: constants for comparators, a public API method, and a private helper. Nesting is minimal and flat. Intent is explicit through comments and method names like getSorter and getDeclaredMethods. The comparators are concise but slightly verbose due to anonymous class syntax; alternative approaches like lambda or Comparator.comparing could reduce length. Action granularity is appropriate, with one logical action per line in most cases. Reading flow is natural, though the Javadoc for getDeclaredMethods is somewhat lengthy and interrupts the code. Overall, readability is high with minor opportunities for modernization and brevity.

Run 3

The code is well-structured with clear separation of concerns: comparators are defined as constants, and helper methods are focused and single-purpose. Nesting is minimal, with only one level of anonymous inner classes and straightforward conditional logic. Intent is clearly communicated through descriptive names and Javadoc. Code length is concise and avoids unnecessary verbosity. Each line typically performs one logical action, promoting readability. The reading flow is natural: constants are introduced first, followed by the public API and private helpers. Minor deductions: anonymous inner classes could be replaced with lambdas for brevity, and the null-check in getDeclaredMethods could be clarified, but overall readability is high.

Run 1

Code Structure: Comparators, method retrieval, and annotation-based sorter selection are logically separated. Nesting: Shallow conditionals and early returns keep control flow simple, despite anonymous comparator classes. Clarity of intent: Descriptive method and constant names plus documentation explain deterministic sorting; DEFAULT's hash-based ordering and null meaning JVM order could be documented more explicitly. Code length: Implementation is concise, though anonymous classes and lengthy documentation add some bulk. Action granularity: Statements generally perform one action each; the nested annotation lookup remains easy to follow. Reading flow: Comparators precede their usage, and methods read naturally from lookup through optional sorting to return. Minor drawbacks include abbreviated comparator variables and placing the private constructor between related methods.

Run 2

Code Structure: Comparators, method retrieval, and annotation-based sorter selection are logically separated. Nesting: Shallow conditionals and early returns keep control flow simple, although anonymous comparator classes add structural nesting. Clarity of intent: Descriptive API names and documentation explain deterministic ordering and tie-breaking; DEFAULT's hash-based ordering and abbreviated variables i1/i2 are less immediately clear. Code length: Compact implementation with useful documentation, though anonymous classes add boilerplate. Action granularity: Each statement performs a focused action, with no crowded multi-statement lines. Reading flow: Comparator definitions lead naturally into their use, and the small helper is easy to follow; the private constructor between operational methods slightly interrupts the flow. Overall, highly readable with minor naming and boilerplate limitations.

Run 3

Code Structure: Well-organized utility class with separate comparators and a small helper for selecting the sort order. Nesting: Shallow conditionals and early returns keep control flow simple, although anonymous comparator classes add some visual nesting. Clarity of intent: Descriptive constants, method names, and documentation explain predictable method ordering; however, the DEFAULT comment does not explain hash-based ordering, and i1/i2 are vague names. Code length: Compact implementation with useful documentation, though anonymous classes introduce boilerplate. Action granularity: Statements generally perform one clear action per line; chained calls remain straightforward. Reading flow: Natural progression from sorting strategies to the public operation and supporting helper, with consistent formatting and spacing.