Skip to content

Commit

Permalink
Merge pull request #31388 from geoand/rr-polish
Browse files Browse the repository at this point in the history
Apply various polishing operations to RESTEasy Reactive source code
  • Loading branch information
geoand authored Feb 27, 2023
2 parents 608c1db + d237ccd commit 4bee348
Show file tree
Hide file tree
Showing 37 changed files with 61 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* then we need to make sure that Arc doesn't create a bean for it automatically (as it will fail validation because
* there is no way to pass the parameter).
* For these resources we add {@link jakarta.enterprise.inject.Vetoed}, and we generate custom CDI producers under the hood
* in {@link CustomResourceProducersGenerator#generate}.
* in {@code io.quarkus.resteasy.reactive.server.deployment.CustomResourceProducersGenerator#generate}.
*/
public class VetoingAnnotationTransformer implements AnnotationsTransformer {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public interface JaxRsSecurityConfig {
* If no security annotations are affecting a method then they will default to requiring these roles,
* (equivalent to adding an @RolesAllowed annotation with the roles to every endpoint class).
*
* The role of '**' means any authenticated user, which is equivalent to the {@link io.quarkus.security.Authenticated}
* The role of '**' means any authenticated user, which is equivalent to the {@code io.quarkus.security.Authenticated}
* annotation.
*/
Optional<List<String>> defaultRolesAllowed();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package io.quarkus.resteasy.reactive.common.runtime;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import org.jboss.resteasy.reactive.common.core.Serialisers;
Expand All @@ -14,19 +12,15 @@

@Recorder
public class ResteasyReactiveCommonRecorder {
private static final Map<String, Class<?>> primitiveTypes;
static {
Map<String, Class<?>> prims = new HashMap<>();
prims.put(byte.class.getName(), byte.class);
prims.put(boolean.class.getName(), boolean.class);
prims.put(char.class.getName(), char.class);
prims.put(short.class.getName(), short.class);
prims.put(int.class.getName(), int.class);
prims.put(float.class.getName(), float.class);
prims.put(double.class.getName(), double.class);
prims.put(long.class.getName(), long.class);
primitiveTypes = Collections.unmodifiableMap(prims);
}
private static final Map<String, Class<?>> primitiveTypes = Map.of(
byte.class.getName(), byte.class,
boolean.class.getName(), boolean.class,
char.class.getName(), char.class,
short.class.getName(), short.class,
int.class.getName(), int.class,
float.class.getName(), float.class,
double.class.getName(), double.class,
long.class.getName(), long.class);

public <T> BeanFactory<T> factory(String targetClass, BeanContainer beanContainer) {
return new ArcBeanFactory<>(loadClass(targetClass),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public boolean isMethodSignatureAsync(MethodInfo info) {
* This method generates the same invocation code as for the standard invoker but also passes along the implicit
* {@code Continuation} argument provided by kotlinc and the coroutines library.
*
* @see io.quarkus.resteasy.reactive.server.deployment.QuarkusInvokerFactory#create(ResourceMethod, ClassInfo, MethodInfo)
* See: io.quarkus.resteasy.reactive.server.deployment.QuarkusInvokerFactory#create(ResourceMethod, ClassInfo, MethodInfo)
*/
private Supplier<EndpointInvoker> createCoroutineInvoker(ClassInfo currentClassInfo,
MethodInfo info, BuildProducer<GeneratedClassBuildItem> generatedClassBuildItemBuildProducer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public RuntimeConfiguration get() {
};
}

@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings({ "unchecked", "rawtypes", "ForLoopReplaceableByForEach" })
public void configureHandlers(RuntimeValue<Deployment> deployment, Map<Class<?>, Supplier<?>> runtimeConfigMap) {
List<GenericRuntimeConfigurableServerRestHandler<?>> runtimeConfigurableServerRestHandlers = deployment.getValue()
.getRuntimeConfigurableServerRestHandlers();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ default URI handle(Response response) {

@Override
default RedirectHandler getContext(Class<?> aClass) {
return response -> handle(response);
return this::handle;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.jboss.resteasy.reactive.client.spi.MultipartResponseData;
import org.jboss.resteasy.reactive.common.jaxrs.ConfigurationImpl;

@SuppressWarnings("ForLoopReplaceableByForEach")
class HandlerChain {

private static final ClientRestHandler[] EMPTY_REST_HANDLERS = new ClientRestHandler[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,18 +159,12 @@ private <R> void registerForSse(MultiRequest<? super R> multiRequest,
SseEventSourceImpl sseSource = new SseEventSourceImpl(invocationBuilder.getTarget(),
invocationBuilder, Integer.MAX_VALUE, TimeUnit.SECONDS);

multiRequest.onCancel(() -> {
sseSource.close();
});
multiRequest.onCancel(sseSource::close);
sseSource.register(event -> {
// DO NOT pass the response mime type because it's SSE: let the event pick between the X-SSE-Content-Type header or
// the content-type SSE field
multiRequest.emit(event.readData(responseType));
}, error -> {
multiRequest.fail(error);
}, () -> {
multiRequest.complete();
});
}, multiRequest::fail, multiRequest::complete);
// watch for user cancelling
sseSource.registerAfterRequest(vertxResponse);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
import java.nio.charset.StandardCharsets;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -135,22 +134,15 @@ public abstract class EndpointIndexer<T extends EndpointIndexer<T, PARAM, METHOD

public static final Map<String, String> primitiveTypes;
private static final Map<DotName, Class<?>> supportedReaderJavaTypes;
// spec
// NOTE: sync with ContextProducer and ContextParamExtractor
private static final Set<DotName> DEFAULT_CONTEXT_TYPES = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
// spec
URI_INFO,
HTTP_HEADERS,
REQUEST,
SECURITY_CONTEXT,
PROVIDERS,
RESOURCE_CONTEXT,
CONFIGURATION,
SSE,
private static final Set<DotName> DEFAULT_CONTEXT_TYPES = Set.of(URI_INFO, HTTP_HEADERS, REQUEST, SECURITY_CONTEXT,
PROVIDERS, RESOURCE_CONTEXT, CONFIGURATION, SSE,
SSE_EVENT_SINK,
// extras
SERVER_REQUEST_CONTEXT,
DotName.createSimple("org.jboss.resteasy.reactive.server.SimpleResourceInfo"), //TODO: fixme
RESOURCE_INFO)));
RESOURCE_INFO);

protected static final Set<DotName> SUPPORT_TEMPORAL_PARAMS = Set.of(INSTANT, LOCAL_DATE, LOCAL_TIME, LOCAL_DATE_TIME,
OFFSET_TIME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

@SuppressWarnings("ForLoopReplaceableByForEach")
public final class HashUtil {

private HashUtil() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class PathPart {
/**
* Create a new partial {@link Path} object.
*
* @param path The file to send
* @param file The file to send
* @param offset The starting byte of the file (must be >= 0)
* @param count The number of bytes to send (must be >= 0 and offset+count <= file size)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.jboss.resteasy.reactive.common.util.QuarkusMultivaluedHashMap;
import org.jboss.resteasy.reactive.common.util.QuarkusMultivaluedMap;

@SuppressWarnings("ForLoopReplaceableByForEach")
public abstract class Serialisers {
public static final Annotation[] NO_ANNOTATION = new Annotation[0];
public static final ReaderInterceptor[] NO_READER_INTERCEPTOR = new ReaderInterceptor[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* This is the Response class for user-created responses. The client response
* object has more deserialising powers in @{link {@link io.quarkus.rest.server.runtime.client.QuarkusRestClientResponse}.
*/
@SuppressWarnings("JavadocReference")
@SuppressWarnings({ "JavadocReference", "ForLoopReplaceableByForEach" })
public class ResponseImpl extends Response {

int status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* This is the Response class for user-created responses. The client response
* object has more deserialising powers in @{link {@link io.quarkus.rest.server.runtime.client.QuarkusRestClientResponse}.
*/
@SuppressWarnings("JavadocReference")
@SuppressWarnings({ "JavadocReference", "ForLoopReplaceableByForEach" })
public class RestResponseImpl<T> extends RestResponse<T> {

int status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.jboss.resteasy.reactive.common.util.MediaTypeHelper;
import org.jboss.resteasy.reactive.spi.BeanFactory;

@SuppressWarnings("ForLoopReplaceableByForEach")
public class ResourceReader {

private BeanFactory<MessageBodyReader<?>> factory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.jboss.resteasy.reactive.common.util.ServerMediaType;
import org.jboss.resteasy.reactive.spi.BeanFactory;

@SuppressWarnings("ForLoopReplaceableByForEach")
public class ResourceWriter {

private BeanFactory<MessageBodyWriter<?>> factory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
package org.jboss.resteasy.reactive.common.util;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import org.jboss.resteasy.reactive.common.core.Serialisers;
import org.jboss.resteasy.reactive.common.model.ResourceReader;
import org.jboss.resteasy.reactive.common.model.ResourceWriter;

public abstract class DeploymentUtils {
private static final Map<String, Class<?>> primitiveTypes;

static {
Map<String, Class<?>> prims = new HashMap<>();
prims.put(byte.class.getName(), byte.class);
prims.put(boolean.class.getName(), boolean.class);
prims.put(char.class.getName(), char.class);
prims.put(short.class.getName(), short.class);
prims.put(int.class.getName(), int.class);
prims.put(float.class.getName(), float.class);
prims.put(double.class.getName(), double.class);
prims.put(long.class.getName(), long.class);
primitiveTypes = Collections.unmodifiableMap(prims);
}
private static final Map<String, Class<?>> primitiveTypes = Map.of(
byte.class.getName(), byte.class,
boolean.class.getName(), boolean.class,
char.class.getName(), char.class,
short.class.getName(), short.class,
int.class.getName(), int.class,
float.class.getName(), float.class,
double.class.getName(), double.class,
long.class.getName(), long.class);

public static void registerWriter(Serialisers serialisers, String entityClassName,
ResourceWriter writer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/**
* @author <a href="mailto:[email protected]">Bill Burke</a>
*/
@SuppressWarnings(value = "rawtypes")
@SuppressWarnings({ "ForLoopReplaceableByForEach" })
public class MediaTypeHelper {
public static final MediaTypeComparator Q_COMPARATOR = new MediaTypeComparator("q");
public static final MediaTypeComparator QS_COMPARATOR = new MediaTypeComparator("qs");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* @author <a href="mailto:[email protected]">Oleg Kalnichevski</a>
*/

@SuppressWarnings("ForLoopReplaceableByForEach")
public class ParameterParser {
/**
* String to be parsed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

public class TypeVariableImpl<D extends GenericDeclaration> implements TypeVariable<D> {

private static final Type[] EMPTY_TYPES_ARRAY = new Type[0];
private final String name;

private final List<Type> bounds;
Expand All @@ -36,7 +37,7 @@ public Annotation[] getDeclaredAnnotations() {

@Override
public Type[] getBounds() {
return bounds.toArray(new Type[bounds.size()]);
return bounds.toArray(EMPTY_TYPES_ARRAY);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.jboss.resteasy.reactive.server.jaxrs.OutboundSseEventImpl;
import org.jboss.resteasy.reactive.server.spi.ServerHttpResponse;

@SuppressWarnings("ForLoopReplaceableByForEach")
public class SseUtil extends CommonSseUtil {

private static final String NL = "\n";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

// FIXME: we need to refactor the serialisation of entities to bytes between here and Sse and Serialisers
// and figure out where interceptors come into play
@SuppressWarnings("ForLoopReplaceableByForEach")
public class StreamingUtil {

public static CompletionStage<?> send(ResteasyReactiveRequestContext context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import java.io.Closeable;
import java.io.IOException;

import org.jboss.resteasy.reactive.server.core.ResteasyReactiveRequestContext;

/**
* Parser for form data. This can be used by down-stream handlers to parse
* form data.
Expand All @@ -25,9 +23,7 @@ public interface FormDataParser extends Closeable {
void parse() throws Exception;

/**
* Parse the data, blocking the current thread until parsing is complete. For blocking handlers this method is
* more efficient than {@link #parse(ResteasyReactiveRequestContext next)}, as the calling thread should do that
* actual parsing, rather than the read thread
* Parse the data, blocking the current thread until parsing is complete.
*
* @return The parsed form data
* @throws IOException If the data could not be read
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
*
* @author Stuart Douglas
*/
@SuppressWarnings("ForLoopReplaceableByForEach")
public class FormParserFactory {

private final ParserDefinition[] parserDefinitions;

FormParserFactory(final List<ParserDefinition> parserDefinitions) {
this.parserDefinitions = parserDefinitions.toArray(new ParserDefinition[parserDefinitions.size()]);
this.parserDefinitions = parserDefinitions.toArray(new ParserDefinition[0]);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.jboss.resteasy.reactive.server.spi.ServerRequestContext;
import org.jboss.resteasy.reactive.spi.BeanFactory;

@SuppressWarnings("ForLoopReplaceableByForEach")
public class MultipartMessageBodyWriter extends ServerMessageBodyWriter.AllWriteableMessageBodyWriter {

private static final String DOUBLE_DASH = "--";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import org.jboss.resteasy.reactive.server.core.ResteasyReactiveRequestContext;

@SuppressWarnings("ForLoopReplaceableByForEach")
public class QueryParamExtractor implements ParameterExtractor {

private final String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* @author Pascal S. de Kloe
* @see "RFC 2296"
*/
@SuppressWarnings("ForLoopReplaceableByForEach")
public class ServerDrivenNegotiation {

private Map<MediaType, QualityValue> requestedMediaTypes = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* A fixed entity writer that iterates an array of providers until it finds one that can handle
* the given types.
*/
@SuppressWarnings("ForLoopReplaceableByForEach")
public class FixedEntityWriterArray implements EntityWriter {

private final MessageBodyWriter[] writers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import org.jboss.resteasy.reactive.spi.BeanFactory;
import org.jboss.resteasy.reactive.spi.ThreadSetupAction;

@SuppressWarnings("ForLoopReplaceableByForEach")
public class RuntimeDeploymentManager {
public static final ServerRestHandler[] EMPTY_REST_HANDLER_ARRAY = new ServerRestHandler[0];
private final DeploymentInfo info;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.jboss.resteasy.reactive.server.mapping.URITemplate;
import org.jboss.resteasy.reactive.server.spi.ServerRestHandler;

@SuppressWarnings("ForLoopReplaceableByForEach")
class RuntimeMappingDeployment {

private final Map<String, TreeMap<URITemplate, List<RequestMapper.RequestPath<RuntimeResource>>>> classTemplates;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
import org.jboss.resteasy.reactive.server.util.ScoreSystem;
import org.jboss.resteasy.reactive.spi.BeanFactory;

@SuppressWarnings("ForLoopReplaceableByForEach")
public class RuntimeResourceDeployment {

private static final ServerRestHandler[] EMPTY_REST_HANDLER_ARRAY = new ServerRestHandler[0];
Expand Down Expand Up @@ -265,6 +266,7 @@ public RuntimeResource buildResourceMethod(ResourceClass clazz,
for (ResourceRequestFilterHandler handler : containerRequestFilterHandlers) {
if (handler.isWithFormRead()) {
hasWithFormReadRequestFilters = true;
break;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.jboss.resteasy.reactive.server.mapping.RuntimeResource;
import org.jboss.resteasy.reactive.server.spi.ServerRestHandler;

@SuppressWarnings("ForLoopReplaceableByForEach")
public class ClassRoutingHandler implements ServerRestHandler {
private static final String INVALID_ACCEPT_HEADER_MESSAGE = "The accept header value did not match the value in @Produces";

Expand Down
Loading

0 comments on commit 4bee348

Please sign in to comment.