Sample

int-ab31a1d681ef-I11

Split eligible integer literals into pairs of short-named intermediate variables

Matched original source

Lines156

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.7440–1; higher is more readable
Dorn0.2260–1; higher is more readable
Mi0.5890–1; higher is more readable
LLOC53Logical lines; fewer is more readable
DeepSeek V4 Pro17.330–20; mean of three runs
GPT-6.1 Sol180–20; mean of three runs
BTTF0.4740–1; higher is more readable

Views

Source code

package org.springframework.mock.web; import java.io.IOException; import java.util.ArrayList; import java.util.List; import jakarta.servlet.AsyncContext; import jakarta.servlet.AsyncEvent; import jakarta.servlet.AsyncListener; import jakarta.servlet.ServletContext; import jakarta.servlet.ServletException; import jakarta.servlet.ServletRequest; import jakarta.servlet.ServletResponse; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.jspecify.annotations.Nullable; import org.springframework.beans.BeanUtils; import org.springframework.util.Assert; import org.springframework.web.util.WebUtils; /** * Mock implementation of the {@link AsyncContext} interface. * * @author Rossen Stoyanchev * @since 3.2 */ public class MockAsyncContext implements AsyncContext { private final HttpServletRequest request; private final @Nullable HttpServletResponse response; private final List<AsyncListener> listeners = new ArrayList<>(); private @Nullable String dispatchedPath; private long timeout = 10 * 1000L; private final List<Runnable> dispatchHandlers = new ArrayList<>(); public MockAsyncContext(ServletRequest request, @Nullable ServletResponse response) { this.request = (HttpServletRequest) request; this.response = (HttpServletResponse) response; } public void addDispatchHandler(Runnable handler) { Assert.notNull(handler, "Dispatch handler must not be null"); synchronized (this) { if (this.dispatchedPath == null) { this.dispatchHandlers.add(handler); } else { handler.run(); } } } @Override public ServletRequest getRequest() { return this.request; } @Override public @Nullable ServletResponse getResponse() { return this.response; } @Override public boolean hasOriginalRequestAndResponse() { return (this.request instanceof MockHttpServletRequest && this.response instanceof MockHttpServletResponse); } @Override public void dispatch() { dispatch(this.request.getRequestURI()); } @Override public void dispatch(String path) { dispatch(null, path); } @Override public void dispatch(@Nullable ServletContext context, String path) { synchronized (this) { this.dispatchedPath = path; this.dispatchHandlers.forEach(Runnable::run); } } public @Nullable String getDispatchedPath() { return this.dispatchedPath; } @Override public void complete() { MockHttpServletRequest mockRequest = WebUtils.getNativeRequest(this.request, MockHttpServletRequest.class); if (mockRequest != null) { mockRequest.setAsyncStarted(false); } for (AsyncListener listener : this.listeners) { try { listener.onComplete(new AsyncEvent(this, this.request, this.response)); } catch (IOException ex) { throw new IllegalStateException("AsyncListener failure", ex); } } } @Override public void start(Runnable runnable) { runnable.run(); } @Override public void addListener(AsyncListener listener) { this.listeners.add(listener); } @Override public void addListener(AsyncListener listener, ServletRequest request, ServletResponse response) { this.listeners.add(listener); } public List<AsyncListener> getListeners() { return this.listeners; } @Override public <T extends AsyncListener> T createListener(Class<T> clazz) throws ServletException { return BeanUtils.instantiateClass(clazz); } /** * By default this is set to 10000 (10 seconds) even though the Servlet API * specifies a default async request timeout of 30 seconds. Keep in mind the * timeout could further be impacted by global configuration through the MVC * Java config or the XML namespace, as well as be overridden per request on * {@link org.springframework.web.context.request.async.DeferredResult DeferredResult} * or on * {@link org.springframework.web.servlet.mvc.method.annotation.SseEmitter SseEmitter}. * @param timeout the timeout value to use. * @see AsyncContext#setTimeout(long) */ @Override public void setTimeout(long timeout) { this.timeout = timeout; } @Override public long getTimeout() { return this.timeout; } }

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.4371.314−144.253
Source linesThe number of non-empty source lines.156+62.4
Byte entropyHow varied the bytes in the source text are. Repeated bytes give a lower value; a more even mixture gives a higher value.5.009−7.513

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

Score0.744

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.157−4.523
Indentation frequencyHow rapidly indentation changes from line to line.141+4.14
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.141−2.815
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.155.91+1.769
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.109.968−0.993
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.109.955+0.97
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.081+0.152

Intercept 0.07 + feature contributions = -1.229 (log-odds).
Score = sigmoid(-1.229) = 0.226.

Score0.589
Score53
Run 1

The code is well-structured, with clear separation of concerns and consistent naming conventions. Methods are concise and focused, generally performing a single action or a small set of related actions. Nesting is minimal, limited to simple conditional blocks and loops. Intent is clear from method names and field declarations. The only minor issues are the use of synchronized blocks in a few methods, which slightly interrupt the reading flow, and the complete() method which catches IOException and wraps it in an IllegalStateException, adding a small layer of complexity. Overall, it is highly readable and maintainable.

Run 2

The code is well-structured with clear separation of fields, constructors, and methods. Imports are organized. Nesting is minimal—only two levels in synchronized blocks and loops. Intent is clear through descriptive method names like addDispatchHandler, getDispatchedPath, and complete. Code length is concise for the functionality provided. Action granularity is generally one action per line, though some lines combine casting and assignment. Reading flow is natural, with methods logically ordered and Javadoc explaining non-obvious behavior (e.g., the 10-second default timeout). Minor deductions for slightly verbose listener iteration in complete() and the if-else in addDispatchHandler that could be flattened, but overall readability is high.

Run 3

The code is well-structured with clear separation of concerns, following standard Java/Spring conventions. Imports are organized, and the class has a single responsibility as a mock AsyncContext implementation. Nesting is minimal - only one level in synchronized blocks and the complete() method. Intent is clear through descriptive method names and a helpful Javadoc on setTimeout explaining the non-standard default. Code length is appropriate, with concise implementations that don't add unnecessary complexity. Action granularity is mostly one action per line, though some lines like the instanceof check in hasOriginalRequestAndResponse() combine logic. Reading flow is natural - fields, constructor, then methods in logical order. Minor deductions: the dispatch() methods could be slightly clearer in their delegation chain, and the complete() method has slightly more complexity than other methods.

Run 1

Code Structure: Fields, constructor, and focused interface methods are logically organized, with dispatch overloads grouped together. Nesting: Mostly flat; synchronization with conditionals and listener iteration with exception handling introduce only modest nesting. Clarity of intent: Descriptive names, explicit overrides, nullable annotations, and timeout documentation make the purpose clear. However, ignored parameters in dispatch and addListener, plus synchronous execution in start, could benefit from brief explanations of mock behavior. Code length: Methods are concise, with little unnecessary implementation code; timeout documentation is somewhat lengthy but informative. Action granularity: Statements generally perform one action per line, and the method reference expresses handler execution compactly. Reading flow: Consistent formatting and straightforward delegation support natural reading, though extra blank lines and ungrouped imports slightly weaken visual organization.

Run 2

Code Structure: Well-organized class with clearly separated state, constructor, and small interface methods. Nesting: Mostly flat; synchronization and listener exception handling introduce only modest nesting. Clarity of intent: Descriptive names, overrides, and timeout documentation communicate purpose well, though ignored parameters and synchronous execution in start() could use brief explanations of mock behavior. Code length: Concise implementation with necessary interface boilerplate; timeout documentation is somewhat lengthy relative to its setter. Action granularity: Statements generally perform one action per line, and delegation keeps dispatch overloads simple. Reading flow: Consistent formatting and straightforward control flow make the class easy to scan, although related listener and dispatch fields could be grouped more closely.

Run 3

Code Structure: Fields, constructor, and focused interface methods are logically organized, with dispatch overloads grouped together. Nesting: Mostly flat; synchronization, conditionals, and listener exception handling introduce only shallow nesting. Clarity of intent: Descriptive names, explicit overrides, nullable annotations, and timeout documentation communicate purpose well. However, unused context and listener request/response parameters, plus synchronous start behavior, could benefit from explanations of mock-specific semantics. Code length: Methods are concise; repetitive interface boilerplate is necessary, although the timeout documentation is relatively lengthy. Action granularity: Statements generally perform one action per line, with clear delegation and a compact method reference for handler execution. Reading flow: Consistent formatting and predictable method bodies support smooth reading, though imports lack visual grouping and documentation coverage is uneven.