From 622cb9698249db85837194396d07bf35147ba9fa Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Wed, 22 Nov 2023 05:56:52 +0100 Subject: [PATCH] refactor: Use diamond operator (#10146) Use this link to re-run the recipe: https://app.moderne.io/recipes/org.openrewrite.staticanalysis.UseDiamondOperator?organizationId=TWljcm9uYXV0 Co-authored-by: Moderne --- .../java/io/micronaut/aop/chain/MethodInterceptorChain.java | 2 +- .../src/jmh/java/io/micronaut/supplier/SupplierBenchmark.java | 4 ++-- .../src/main/java/io/micronaut/inject/ast/MethodElement.java | 2 +- .../micronaut/core/async/propagation/ReactivePropagation.java | 2 +- .../core/annotation/ImmutableSortedStringsArrayMap.java | 4 ++-- .../java/io/micronaut/core/bind/DefaultExecutableBinder.java | 4 ++-- .../main/java/io/micronaut/core/convert/TypeConverter.java | 2 +- .../micronaut/core/convert/value/ConvertibleMultiValues.java | 4 ++-- .../io/micronaut/core/convert/value/ConvertibleValues.java | 4 ++-- core/src/main/java/io/micronaut/core/type/ReturnType.java | 2 +- .../io/micronaut/http/netty/NettyMutableHttpResponse.java | 2 +- .../java/io/micronaut/http/server/netty/NettyHttpRequest.java | 2 +- .../http/server/netty/binders/NettyBodyAnnotationBinder.java | 2 +- .../io/micronaut/http/converters/HttpConverterRegistrar.java | 2 +- .../test/groovy/io/micronaut/inject/collect/MyIterable.java | 2 +- .../test/java/org/atinject/jakartatck/auto/Convertible.java | 4 ++-- .../src/test/java/org/atinject/jakartatck/auto/Tire.java | 2 +- .../main/java/io/micronaut/context/DefaultBeanContext.java | 2 +- .../java/io/micronaut/context/env/EmptyPropertySource.java | 2 +- .../main/java/io/micronaut/context/env/MapPropertySource.java | 2 +- .../context/event/ApplicationEventPublisherFactory.java | 2 +- inject/src/main/java/io/micronaut/inject/BeanDefinition.java | 2 +- .../inject/annotation/AnnotationMetadataSupport.java | 2 +- .../java/io/micronaut/json/bind/JsonBeanPropertyBinder.java | 2 +- .../src/test/java/org/atinject/javaxtck/auto/Convertible.java | 4 ++-- .../src/test/java/org/atinject/javaxtck/auto/Tire.java | 2 +- 26 files changed, 33 insertions(+), 33 deletions(-) diff --git a/aop/src/main/java/io/micronaut/aop/chain/MethodInterceptorChain.java b/aop/src/main/java/io/micronaut/aop/chain/MethodInterceptorChain.java index cd792b0a919..4d8245d244b 100644 --- a/aop/src/main/java/io/micronaut/aop/chain/MethodInterceptorChain.java +++ b/aop/src/main/java/io/micronaut/aop/chain/MethodInterceptorChain.java @@ -264,7 +264,7 @@ private static T1 doIntercept( ); if (ArrayUtils.isNotEmpty(resolvedInterceptors)) { - final MethodInterceptorChain chain = new MethodInterceptorChain( + final MethodInterceptorChain chain = new MethodInterceptorChain<>( resolvedInterceptors, bean, interceptedMethod, diff --git a/benchmarks/src/jmh/java/io/micronaut/supplier/SupplierBenchmark.java b/benchmarks/src/jmh/java/io/micronaut/supplier/SupplierBenchmark.java index 13665b6c703..4c44cdb34a9 100644 --- a/benchmarks/src/jmh/java/io/micronaut/supplier/SupplierBenchmark.java +++ b/benchmarks/src/jmh/java/io/micronaut/supplier/SupplierBenchmark.java @@ -42,7 +42,7 @@ public void memoizedNonEmpty(Blackhole blackhole) { } private static Supplier memoizedUsingLambda(Supplier actual) { - return new Supplier() { + return new Supplier<>() { Supplier delegate = this::initialize; boolean initialized; @@ -63,7 +63,7 @@ private synchronized T initialize() { } private static Supplier memoizedNonEmptyUsingLambda(Supplier actual) { - return new Supplier() { + return new Supplier<>() { Supplier delegate = this::initialize; boolean initialized; diff --git a/core-processor/src/main/java/io/micronaut/inject/ast/MethodElement.java b/core-processor/src/main/java/io/micronaut/inject/ast/MethodElement.java index cf38d12559a..ae1c5cad5e6 100644 --- a/core-processor/src/main/java/io/micronaut/inject/ast/MethodElement.java +++ b/core-processor/src/main/java/io/micronaut/inject/ast/MethodElement.java @@ -526,7 +526,7 @@ public AnnotationMetadata getAnnotationMetadata() { @Override public MutableAnnotationMetadataDelegate getMethodAnnotationMetadata() { - return new MutableAnnotationMetadataDelegate() { + return new MutableAnnotationMetadataDelegate<>() { @Override public AnnotationMetadata getAnnotationMetadata() { diff --git a/core-reactive/src/main/java/io/micronaut/core/async/propagation/ReactivePropagation.java b/core-reactive/src/main/java/io/micronaut/core/async/propagation/ReactivePropagation.java index 9929695e746..00723f2ed3d 100644 --- a/core-reactive/src/main/java/io/micronaut/core/async/propagation/ReactivePropagation.java +++ b/core-reactive/src/main/java/io/micronaut/core/async/propagation/ReactivePropagation.java @@ -83,7 +83,7 @@ public void subscribe(Subscriber subscriber) { * @return propagation aware subscriber */ public static Subscriber propagate(PropagatedContext propagatedContext, Subscriber actual) { - return new CoreSubscriber() { + return new CoreSubscriber<>() { @Override public Context currentContext() { diff --git a/core/src/main/java/io/micronaut/core/annotation/ImmutableSortedStringsArrayMap.java b/core/src/main/java/io/micronaut/core/annotation/ImmutableSortedStringsArrayMap.java index 68d607b4c7b..7f3c59a1279 100644 --- a/core/src/main/java/io/micronaut/core/annotation/ImmutableSortedStringsArrayMap.java +++ b/core/src/main/java/io/micronaut/core/annotation/ImmutableSortedStringsArrayMap.java @@ -160,10 +160,10 @@ public Set keySet() { @NonNull @Override public Collection values() { - return new AbstractCollection() { + return new AbstractCollection<>() { @Override public Iterator iterator() { - return new Iterator() { + return new Iterator<>() { private int index = 0; @Override diff --git a/core/src/main/java/io/micronaut/core/bind/DefaultExecutableBinder.java b/core/src/main/java/io/micronaut/core/bind/DefaultExecutableBinder.java index 55a03499da2..bbd87da753c 100644 --- a/core/src/main/java/io/micronaut/core/bind/DefaultExecutableBinder.java +++ b/core/src/main/java/io/micronaut/core/bind/DefaultExecutableBinder.java @@ -97,7 +97,7 @@ public BoundExecutable bind( } } - return new BoundExecutable() { + return new BoundExecutable<>() { @Override public Executable getTarget() { return target; @@ -157,7 +157,7 @@ public BoundExecutable tryBind(Executable target, ArgumentBin } } - return new BoundExecutable() { + return new BoundExecutable<>() { @Override public List> getUnboundArguments() { diff --git a/core/src/main/java/io/micronaut/core/convert/TypeConverter.java b/core/src/main/java/io/micronaut/core/convert/TypeConverter.java index 2f050e4feba..f89fed11ad5 100644 --- a/core/src/main/java/io/micronaut/core/convert/TypeConverter.java +++ b/core/src/main/java/io/micronaut/core/convert/TypeConverter.java @@ -73,7 +73,7 @@ default Optional convert(S object, Class targetType) { */ static TypeConverter of(Class sourceType, Class targetType, Function converter) { // Keep the anonymous class instead of Lambda to reduce the Lambda invocation overhead during the startup - return new TypeConverter() { + return new TypeConverter<>() { @Override public Optional convert(ST object, Class targetType1, ConversionContext context) { return Optional.ofNullable(converter.apply(object)); diff --git a/core/src/main/java/io/micronaut/core/convert/value/ConvertibleMultiValues.java b/core/src/main/java/io/micronaut/core/convert/value/ConvertibleMultiValues.java index 9d65dd7d101..6725046de5f 100644 --- a/core/src/main/java/io/micronaut/core/convert/value/ConvertibleMultiValues.java +++ b/core/src/main/java/io/micronaut/core/convert/value/ConvertibleMultiValues.java @@ -99,7 +99,7 @@ default void forEach(BiConsumer> action) { @Override default Iterator>> iterator() { Iterator headerNames = names().iterator(); - return new Iterator>>() { + return new Iterator<>() { @Override public boolean hasNext() { return headerNames.hasNext(); @@ -112,7 +112,7 @@ public Map.Entry> next() { } String name = headerNames.next(); - return new Map.Entry>() { + return new Map.Entry<>() { @Override public String getKey() { return name; diff --git a/core/src/main/java/io/micronaut/core/convert/value/ConvertibleValues.java b/core/src/main/java/io/micronaut/core/convert/value/ConvertibleValues.java index e2fe8fec6f2..375a7237b43 100644 --- a/core/src/main/java/io/micronaut/core/convert/value/ConvertibleValues.java +++ b/core/src/main/java/io/micronaut/core/convert/value/ConvertibleValues.java @@ -216,7 +216,7 @@ default Map subMap(String prefix, ArgumentConversionContext valueT @Override default Iterator> iterator() { Iterator names = names().iterator(); - return new Iterator>() { + return new Iterator<>() { @Override public boolean hasNext() { return names.hasNext(); @@ -229,7 +229,7 @@ public Map.Entry next() { } String name = names.next(); - return new Map.Entry() { + return new Map.Entry<>() { @Override public String getKey() { return name; diff --git a/core/src/main/java/io/micronaut/core/type/ReturnType.java b/core/src/main/java/io/micronaut/core/type/ReturnType.java index de3235df475..ead87378dad 100644 --- a/core/src/main/java/io/micronaut/core/type/ReturnType.java +++ b/core/src/main/java/io/micronaut/core/type/ReturnType.java @@ -78,7 +78,7 @@ static ReturnType of(Class type, Argument... typeArguments) { for (Argument argument : typeArguments) { argumentMap.put(argument.getName(), argument); } - return new ReturnType() { + return new ReturnType<>() { @Override public Class getType() { return type; diff --git a/http-netty/src/main/java/io/micronaut/http/netty/NettyMutableHttpResponse.java b/http-netty/src/main/java/io/micronaut/http/netty/NettyMutableHttpResponse.java index 2a029f801d1..270311195cb 100644 --- a/http-netty/src/main/java/io/micronaut/http/netty/NettyMutableHttpResponse.java +++ b/http-netty/src/main/java/io/micronaut/http/netty/NettyMutableHttpResponse.java @@ -434,7 +434,7 @@ protected synchronized Optional convertFromNext(ConversionService conversionS } else { conversion = conversionService.convert(value, conversionContext); } - nextConvertor = new BodyConvertor() { + nextConvertor = new BodyConvertor<>() { @Override public Optional convert(ArgumentConversionContext currentConversionContext, T value) { diff --git a/http-server-netty/src/main/java/io/micronaut/http/server/netty/NettyHttpRequest.java b/http-server-netty/src/main/java/io/micronaut/http/server/netty/NettyHttpRequest.java index 54fc5725369..9ef253cc9ba 100644 --- a/http-server-netty/src/main/java/io/micronaut/http/server/netty/NettyHttpRequest.java +++ b/http-server-netty/src/main/java/io/micronaut/http/server/netty/NettyHttpRequest.java @@ -914,7 +914,7 @@ private abstract static class BodyConvertor { protected synchronized Optional convertFromNext(ConversionService conversionService, ArgumentConversionContext conversionContext, T value) { if (nextConvertor == null) { Optional conversion = conversionService.convert(value, conversionContext); - nextConvertor = new BodyConvertor() { + nextConvertor = new BodyConvertor<>() { @Override public Optional convert(ArgumentConversionContext currentConversionContext, T value) { diff --git a/http-server-netty/src/main/java/io/micronaut/http/server/netty/binders/NettyBodyAnnotationBinder.java b/http-server-netty/src/main/java/io/micronaut/http/server/netty/binders/NettyBodyAnnotationBinder.java index a96bceec901..484fbd6c347 100644 --- a/http-server-netty/src/main/java/io/micronaut/http/server/netty/binders/NettyBodyAnnotationBinder.java +++ b/http-server-netty/src/main/java/io/micronaut/http/server/netty/binders/NettyBodyAnnotationBinder.java @@ -89,7 +89,7 @@ public BindingResult bindFullBody(ArgumentConversionContext context, HttpR ExecutionFlow buffered = nhr.byteBody() .buffer(nhr.getChannelHandlerContext().alloc()); - return new PendingRequestBindingResult() { + return new PendingRequestBindingResult<>() { @SuppressWarnings("OptionalUsedAsFieldOrParameterType") Optional result; diff --git a/http/src/main/java/io/micronaut/http/converters/HttpConverterRegistrar.java b/http/src/main/java/io/micronaut/http/converters/HttpConverterRegistrar.java index 082f7d55281..b78104566b8 100644 --- a/http/src/main/java/io/micronaut/http/converters/HttpConverterRegistrar.java +++ b/http/src/main/java/io/micronaut/http/converters/HttpConverterRegistrar.java @@ -58,7 +58,7 @@ protected HttpConverterRegistrar(BeanProvider resourceResolver */ @Deprecated(forRemoval = true) protected HttpConverterRegistrar(Provider resourceResolver) { - this.resourceResolver = new BeanProvider() { + this.resourceResolver = new BeanProvider<>() { @Override public ResourceResolver get() { return resourceResolver.get(); diff --git a/inject-java/src/test/groovy/io/micronaut/inject/collect/MyIterable.java b/inject-java/src/test/groovy/io/micronaut/inject/collect/MyIterable.java index f73d34e5fea..0c8599bbaa0 100644 --- a/inject-java/src/test/groovy/io/micronaut/inject/collect/MyIterable.java +++ b/inject-java/src/test/groovy/io/micronaut/inject/collect/MyIterable.java @@ -8,7 +8,7 @@ public class MyIterable implements Iterable { @Override public Iterator iterator() { - return new Iterator() { + return new Iterator<>() { @Override public boolean hasNext() { diff --git a/inject-java/src/test/java/org/atinject/jakartatck/auto/Convertible.java b/inject-java/src/test/java/org/atinject/jakartatck/auto/Convertible.java index d4e5f2a2802..b1840e26702 100644 --- a/inject-java/src/test/java/org/atinject/jakartatck/auto/Convertible.java +++ b/inject-java/src/test/java/org/atinject/jakartatck/auto/Convertible.java @@ -169,7 +169,7 @@ void setSeat(Seat unused) { * value to avoid null checks for omitted provider injections. */ private static jakarta.inject.Provider nullProvider() { - return new org.atinject.jakartatck.auto.Convertible.NullProvider(); + return new org.atinject.jakartatck.auto.Convertible.NullProvider<>(); } static class NullProvider implements jakarta.inject.Provider { @@ -181,7 +181,7 @@ public T get() { } public static ThreadLocal localConvertible - = new ThreadLocal(); + = new ThreadLocal<>(); public static class Tests { diff --git a/inject-java/src/test/java/org/atinject/jakartatck/auto/Tire.java b/inject-java/src/test/java/org/atinject/jakartatck/auto/Tire.java index 2486c34da37..2e063dd63fc 100644 --- a/inject-java/src/test/java/org/atinject/jakartatck/auto/Tire.java +++ b/inject-java/src/test/java/org/atinject/jakartatck/auto/Tire.java @@ -28,7 +28,7 @@ public class Tire extends RoundThing { protected static final FuelTank NEVER_INJECTED = new FuelTank(); - protected static final Set moreProblems = new LinkedHashSet(); + protected static final Set moreProblems = new LinkedHashSet<>(); FuelTank constructorInjection = NEVER_INJECTED; @Inject FuelTank fieldInjection = NEVER_INJECTED; diff --git a/inject/src/main/java/io/micronaut/context/DefaultBeanContext.java b/inject/src/main/java/io/micronaut/context/DefaultBeanContext.java index 49f707f596a..b63b01c2692 100644 --- a/inject/src/main/java/io/micronaut/context/DefaultBeanContext.java +++ b/inject/src/main/java/io/micronaut/context/DefaultBeanContext.java @@ -166,7 +166,7 @@ public class DefaultBeanContext implements InitializableBeanContext { private static final String PARALLEL_TYPE = Parallel.class.getName(); private static final String INDEXES_TYPE = Indexes.class.getName(); private static final String REPLACES_ANN = Replaces.class.getName(); - private static final Comparator> BEAN_REGISTRATION_COMPARATOR = new Comparator>() { + private static final Comparator> BEAN_REGISTRATION_COMPARATOR = new Comparator<>() { // Keep anonymous class to avoid lambda overhead during the startup @Override public int compare(BeanRegistration o1, BeanRegistration o2) { diff --git a/inject/src/main/java/io/micronaut/context/env/EmptyPropertySource.java b/inject/src/main/java/io/micronaut/context/env/EmptyPropertySource.java index 71cdbeda626..ed6e86b3a0d 100644 --- a/inject/src/main/java/io/micronaut/context/env/EmptyPropertySource.java +++ b/inject/src/main/java/io/micronaut/context/env/EmptyPropertySource.java @@ -55,7 +55,7 @@ public Object get(String key) { @Override public Iterator iterator() { - return new Iterator() { + return new Iterator<>() { @Override public boolean hasNext() { return false; diff --git a/inject/src/main/java/io/micronaut/context/env/MapPropertySource.java b/inject/src/main/java/io/micronaut/context/env/MapPropertySource.java index 77b01c859d7..c59e31290ca 100644 --- a/inject/src/main/java/io/micronaut/context/env/MapPropertySource.java +++ b/inject/src/main/java/io/micronaut/context/env/MapPropertySource.java @@ -55,7 +55,7 @@ public Object get(String key) { public Iterator iterator() { Iterator i = map.keySet().iterator(); - return new Iterator() { + return new Iterator<>() { @Override public boolean hasNext() { return i.hasNext(); diff --git a/inject/src/main/java/io/micronaut/context/event/ApplicationEventPublisherFactory.java b/inject/src/main/java/io/micronaut/context/event/ApplicationEventPublisherFactory.java index bce859b1255..c72be109abb 100644 --- a/inject/src/main/java/io/micronaut/context/event/ApplicationEventPublisherFactory.java +++ b/inject/src/main/java/io/micronaut/context/event/ApplicationEventPublisherFactory.java @@ -192,7 +192,7 @@ public int hashCode() { } private ApplicationEventPublisher createObjectEventPublisher(BeanContext beanContext) { - return new ApplicationEventPublisher() { + return new ApplicationEventPublisher<>() { @Override public void publishEvent(Object event) { getTypedEventPublisher(Argument.of(event.getClass()), beanContext).publishEvent(event); diff --git a/inject/src/main/java/io/micronaut/inject/BeanDefinition.java b/inject/src/main/java/io/micronaut/inject/BeanDefinition.java index ecf58da2bd0..4334ff77279 100644 --- a/inject/src/main/java/io/micronaut/inject/BeanDefinition.java +++ b/inject/src/main/java/io/micronaut/inject/BeanDefinition.java @@ -174,7 +174,7 @@ default Optional> getDeclaringType() { * @return The constructor injection point */ default ConstructorInjectionPoint getConstructor() { - return new ConstructorInjectionPoint() { + return new ConstructorInjectionPoint<>() { @Override public Argument[] getArguments() { diff --git a/inject/src/main/java/io/micronaut/inject/annotation/AnnotationMetadataSupport.java b/inject/src/main/java/io/micronaut/inject/annotation/AnnotationMetadataSupport.java index 08882507aa5..8e8043a6863 100644 --- a/inject/src/main/java/io/micronaut/inject/annotation/AnnotationMetadataSupport.java +++ b/inject/src/main/java/io/micronaut/inject/annotation/AnnotationMetadataSupport.java @@ -575,7 +575,7 @@ public AnnotationValue annotationValue() { if (annotationValue != null) { return this.annotationValue; } else { - return new AnnotationValue(annotationClass.getName()); + return new AnnotationValue<>(annotationClass.getName()); } } } diff --git a/json-core/src/main/java/io/micronaut/json/bind/JsonBeanPropertyBinder.java b/json-core/src/main/java/io/micronaut/json/bind/JsonBeanPropertyBinder.java index da0e2762f4a..2ffa61b1869 100644 --- a/json-core/src/main/java/io/micronaut/json/bind/JsonBeanPropertyBinder.java +++ b/json-core/src/main/java/io/micronaut/json/bind/JsonBeanPropertyBinder.java @@ -73,7 +73,7 @@ public BindingResult bind(ArgumentConversionContext context, Map return () -> Optional.of(result); } catch (Exception e) { context.reject(e); - return new BindingResult() { + return new BindingResult<>() { @Override public List getConversionErrors() { return CollectionUtils.iterableToList(context); diff --git a/test-suite-javax-inject/src/test/java/org/atinject/javaxtck/auto/Convertible.java b/test-suite-javax-inject/src/test/java/org/atinject/javaxtck/auto/Convertible.java index 55519bb0c62..fcce19a25c6 100644 --- a/test-suite-javax-inject/src/test/java/org/atinject/javaxtck/auto/Convertible.java +++ b/test-suite-javax-inject/src/test/java/org/atinject/javaxtck/auto/Convertible.java @@ -169,7 +169,7 @@ void setSeat(Seat unused) { * value to avoid null checks for omitted provider injections. */ private static Provider nullProvider() { - return new NullProvider(); + return new NullProvider<>(); } static class NullProvider implements Provider { @@ -180,7 +180,7 @@ public T get() { } } - public static ThreadLocal localConvertible = new ThreadLocal(); + public static ThreadLocal localConvertible = new ThreadLocal<>(); @TestInstance(TestInstance.Lifecycle.PER_CLASS) diff --git a/test-suite-javax-inject/src/test/java/org/atinject/javaxtck/auto/Tire.java b/test-suite-javax-inject/src/test/java/org/atinject/javaxtck/auto/Tire.java index 190abc56851..841c10e26c7 100644 --- a/test-suite-javax-inject/src/test/java/org/atinject/javaxtck/auto/Tire.java +++ b/test-suite-javax-inject/src/test/java/org/atinject/javaxtck/auto/Tire.java @@ -26,7 +26,7 @@ public class Tire extends RoundThing { protected static final FuelTank NEVER_INJECTED = new FuelTank(); - protected static final Set moreProblems = new LinkedHashSet(); + protected static final Set moreProblems = new LinkedHashSet<>(); FuelTank constructorInjection = NEVER_INJECTED; @Inject FuelTank fieldInjection = NEVER_INJECTED;