Sample

int-03eb33121728-I13

Lower every eligible classic and enhanced for loop to a while loop

Matched original source

Lines189

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.7650–1; higher is more readable
Dorn0.8210–1; higher is more readable
Mi0.4050–1; higher is more readable
LLOC55Logical lines; fewer is more readable
DeepSeek V4 Pro15.670–20; mean of three runs
GPT-6.1 Sol170–20; mean of three runs
BTTF0.5720–1; higher is more readable

Views

Source code

package org.springframework.jms.config; import java.util.ArrayList; import java.util.List; import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.InitializingBean; import org.springframework.messaging.handler.annotation.support.DefaultMessageHandlerMethodFactory; import org.springframework.messaging.handler.annotation.support.MessageHandlerMethodFactory; import org.springframework.util.Assert; /** * Helper bean for registering {@link JmsListenerEndpoint} with a {@link JmsListenerEndpointRegistry}. * * @author Stephane Nicoll * @author Juergen Hoeller * @since 4.1 * @see org.springframework.jms.annotation.JmsListenerConfigurer */ public class JmsListenerEndpointRegistrar implements BeanFactoryAware, InitializingBean { private @Nullable JmsListenerEndpointRegistry endpointRegistry; private @Nullable MessageHandlerMethodFactory messageHandlerMethodFactory; private @Nullable JmsListenerContainerFactory<?> containerFactory; private @Nullable String containerFactoryBeanName; private @Nullable BeanFactory beanFactory; private final List<JmsListenerEndpointDescriptor> endpointDescriptors = new ArrayList<>(); private boolean startImmediately; /** * Set the {@link JmsListenerEndpointRegistry} instance to use. */ public void setEndpointRegistry(@Nullable JmsListenerEndpointRegistry endpointRegistry) { this.endpointRegistry = endpointRegistry; } /** * Return the {@link JmsListenerEndpointRegistry} instance for this * registrar, may be {@code null}. */ public @Nullable JmsListenerEndpointRegistry getEndpointRegistry() { return this.endpointRegistry; } /** * Set the {@link MessageHandlerMethodFactory} to use to configure the message * listener responsible to serve an endpoint detected by this processor. * <p>By default, {@link DefaultMessageHandlerMethodFactory} is used and it * can be configured further to support additional method arguments * or to customize conversion and validation support. See * {@link DefaultMessageHandlerMethodFactory} javadoc for more details. */ public void setMessageHandlerMethodFactory(@Nullable MessageHandlerMethodFactory messageHandlerMethodFactory) { this.messageHandlerMethodFactory = messageHandlerMethodFactory; } /** * Return the custom {@link MessageHandlerMethodFactory} to use, if any. */ public @Nullable MessageHandlerMethodFactory getMessageHandlerMethodFactory() { return this.messageHandlerMethodFactory; } /** * Set the {@link JmsListenerContainerFactory} to use in case a {@link JmsListenerEndpoint} * is registered with a {@code null} container factory. * <p>Alternatively, the bean name of the {@link JmsListenerContainerFactory} to use * can be specified for a lazy lookup, see {@link #setContainerFactoryBeanName}. */ public void setContainerFactory(JmsListenerContainerFactory<?> containerFactory) { this.containerFactory = containerFactory; } /** * Set the bean name of the {@link JmsListenerContainerFactory} to use in case * a {@link JmsListenerEndpoint} is registered with a {@code null} container factory. * Alternatively, the container factory instance can be registered directly: * see {@link #setContainerFactory(JmsListenerContainerFactory)}. * @see #setBeanFactory */ public void setContainerFactoryBeanName(String containerFactoryBeanName) { this.containerFactoryBeanName = containerFactoryBeanName; } /** * A {@link BeanFactory} only needs to be available in conjunction with * {@link #setContainerFactoryBeanName}. */ @Override public void setBeanFactory(BeanFactory beanFactory) { this.beanFactory = beanFactory; } @Override public void afterPropertiesSet() { registerAllEndpoints(); } protected void registerAllEndpoints() { Assert.state(this.endpointRegistry != null, "No JmsListenerEndpointRegistry set"); { java.util.Iterator<?> loopIterator = (this.endpointDescriptors).iterator(); while (loopIterator.hasNext()) { JmsListenerEndpointDescriptor descriptor = (JmsListenerEndpointDescriptor) loopIterator.next(); this.endpointRegistry.registerListenerContainer( descriptor.endpoint, resolveContainerFactory(descriptor)); } } this.startImmediately = true; // trigger immediate startup } private JmsListenerContainerFactory<?> resolveContainerFactory(JmsListenerEndpointDescriptor descriptor) { if (descriptor.containerFactory != null) { return descriptor.containerFactory; } else if (this.containerFactory != null) { return this.containerFactory; } else if (this.containerFactoryBeanName != null) { Assert.state(this.beanFactory != null, "BeanFactory must be set to obtain container factory by bean name"); // Consider changing this if live change of the factory is required... this.containerFactory = this.beanFactory.getBean( this.containerFactoryBeanName, JmsListenerContainerFactory.class); return this.containerFactory; } else { throw new IllegalStateException("Could not resolve the " + JmsListenerContainerFactory.class.getSimpleName() + " to use for [" + descriptor.endpoint + "] no factory was given and no default is set."); } } /** * Register a new {@link JmsListenerEndpoint} alongside the * {@link JmsListenerContainerFactory} to use to create the underlying container. * <p>The {@code factory} may be {@code null} if the default factory should be * used for the supplied endpoint. */ public void registerEndpoint(JmsListenerEndpoint endpoint, @Nullable JmsListenerContainerFactory<?> factory) { Assert.notNull(endpoint, "Endpoint must not be null"); Assert.hasText(endpoint.getId(), "Endpoint id must be set"); // Factory may be null, we defer the resolution right before actually creating the container JmsListenerEndpointDescriptor descriptor = new JmsListenerEndpointDescriptor(endpoint, factory); if (this.startImmediately) { // register and start immediately Assert.state(this.endpointRegistry != null, "No JmsListenerEndpointRegistry set"); this.endpointRegistry.registerListenerContainer(descriptor.endpoint, resolveContainerFactory(descriptor), true); } else { this.endpointDescriptors.add(descriptor); } } /** * Register a new {@link JmsListenerEndpoint} using the default * {@link JmsListenerContainerFactory} to create the underlying container. * @see #setContainerFactory(JmsListenerContainerFactory) * @see #registerEndpoint(JmsListenerEndpoint, JmsListenerContainerFactory) */ public void registerEndpoint(JmsListenerEndpoint endpoint) { registerEndpoint(endpoint, null); } private static class JmsListenerEndpointDescriptor { public final JmsListenerEndpoint endpoint; public final @Nullable JmsListenerContainerFactory<?> containerFactory; public JmsListenerEndpointDescriptor(JmsListenerEndpoint endpoint, @Nullable JmsListenerContainerFactory<?> containerFactory) { this.endpoint = endpoint; this.containerFactory = containerFactory; } } }

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.4321.784−142.619
Source linesThe number of non-empty source lines.189+75.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.894−7.341

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

Score0.765

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.190−5.691
Indentation frequencyHow rapidly indentation changes from line to line.140+4.105
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.188.796+2.229
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.395−1.053
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.111.926+1.001
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.049+0.466
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.1+0.398

Intercept 0.07 + feature contributions = 1.526 (log-odds).
Score = sigmoid(1.526) = 0.821.

Score0.405
Score55
Run 1

The code is generally well-structured and readable. It follows Spring conventions with clear method names, Javadoc, and separation of concerns. Fields are grouped logically, and getters/setters are straightforward. The `resolveContainerFactory` method uses a clear if-else chain, but this introduces some extra nesting that could benefit from guard clauses. The `registerAllEndpoints` method has an unnecessary block and traditional Iterator usage, which slightly reduces readability compared to a for-each loop. Action granularity is mostly one action per line, and reading flow is natural. Overall, the code is maintainable and clear, with only minor improvements needed for modern Java style and reduced nesting.

Run 2

The code is generally readable but has some inconsistent style choices. The class has a logical structure with fields, setters/getters, Javadoc, and clear method separation. Nesting is mostly flat except for a few if-else blocks in `resolveContainerFactory` and `registerEndpoint`, which is acceptable. Intent is fairly clear from descriptive method and field names. However, there are notable readability issues: `registerAllEndpoints` uses an unnecessary block and manual iterator loop instead of a for-each loop. The forced line breaks in exception messages and string concatenation feel awkward. Action granularity is mostly one action per line, but some lines wrap poorly. The class is slightly verbose but not excessively long.

Run 3

The code is generally well-structured with clear purpose, good Javadoc, and mostly one action per line. It follows common Spring patterns (setter injection, InitializingBean) and uses meaningful names. However, readability is reduced by a few issues: the awkward block with an explicit Iterator in registerAllEndpoints is verbose and breaks the flow compared to a standard for-each loop. The registerAllEndpoints method starts by asserting but then sets startImmediately to true after the loop, which can be confusing when read linearly. The resolveContainerFactory method uses a slightly long if/else chain but is still clear. Variable declarations use nullable annotations consistently. Overall, it's readable but could be improved by simplifying the iteration and clarifying the registration-lifetime logic.

Run 1

Code Structure: Well organized into configuration accessors, lifecycle registration, factory resolution, and a small descriptor class. Nesting: Generally shallow, though registerAllEndpoints adds an unnecessary block around an explicit iterator loop. Clarity of intent: Descriptive names, nullability annotations, assertions, and Javadoc clearly explain responsibilities and factory fallback behavior. Code length: Mostly justified, but extensive accessor documentation and the verbose iterator implementation add bulk; an enhanced for-loop would be clearer and shorter. Action granularity: Statements generally perform one action per line, with sensible wrapping of longer calls. Reading flow: Configuration precedes operational methods naturally, and factory selection follows a clear priority order. The iterator's wildcard type, cast, redundant parentheses, and inconsistent indentation interrupt otherwise consistent formatting. Overall, the code is highly readable with a few localized verbosity and flow issues.

Run 2

Code Structure: Fields, configuration methods, lifecycle registration, factory resolution, and the descriptor class are logically organized. Nesting: Mostly shallow, although the unnecessary block around the explicit iterator loop adds clutter. Clarity of intent: Descriptive names, Javadoc, nullability annotations, and assertions clearly explain responsibilities and factory-selection precedence. Code length: Reasonable for the functionality, but extensive accessor documentation and a manually expanded iterator loop make it longer than necessary; an enhanced for-loop would be clearer. Action granularity: Statements generally perform one action per line, with multiline calls formatted intelligibly. Reading flow: Configuration leads naturally into initialization and registration, with factory resolution extracted into a focused helper. Inconsistent indentation in the iterator block and verbose type names slightly interrupt an otherwise clear, conventional flow.

Run 3

Code Structure: Configuration accessors, lifecycle registration, factory resolution, and the descriptor class are logically separated. Nesting: Mostly shallow, although registerAllEndpoints adds an unnecessary block around an explicit iterator loop. Clarity of intent: Descriptive names, Javadoc, nullability annotations, and validation messages clearly communicate purpose and factory fallback rules. Code length: Reasonable for the responsibilities, but accessor documentation and the verbose iterator make it longer than necessary; an enhanced for-loop would simplify registration. Action granularity: Statements generally perform one action per line, with longer calls sensibly wrapped. Reading flow: Configuration precedes lifecycle and registration logic naturally, and helper methods keep operations focused. Inconsistent indentation in the iterator block, its wildcard type and cast, and some long declarations slightly interrupt otherwise strong readability.