From 73abd582029fc81a683fe8b995fa07a41202dc43 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Fri, 2 Sep 2022 10:23:53 +0200 Subject: [PATCH] Polishing --- .../aot/hint/ExecutableHint.java | 6 ++--- .../springframework/aot/hint/FieldHint.java | 8 +++---- .../aot/hint/ReflectionHintsTests.java | 22 ++++++++----------- .../context/aot/TestContextAotGenerator.java | 4 ++-- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/aot/hint/ExecutableHint.java b/spring-core/src/main/java/org/springframework/aot/hint/ExecutableHint.java index 8e85a04be77..1897a3cabc7 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/ExecutableHint.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/ExecutableHint.java @@ -55,7 +55,7 @@ public final class ExecutableHint extends MemberHint { } /** - * Initialize a builder with the name and parameters types of a method. + * Initialize a builder with the name and parameter types of a method. * @param name the name of the method * @param parameterTypes the parameter types of the method * @return a builder @@ -74,7 +74,7 @@ public final class ExecutableHint extends MemberHint { } /** - * Return the {@linkplain ExecutableMode mode} that apply to this hint. + * Return the {@linkplain ExecutableMode mode} that applies to this hint. * @return the mode */ public ExecutableMode getMode() { @@ -116,7 +116,7 @@ public final class ExecutableHint extends MemberHint { */ public Builder withMode(ExecutableMode mode) { Assert.notNull(mode, "'mode' must not be null"); - if ((this.mode == null || !this.mode.includes(mode))) { + if ((this.mode == null) || !this.mode.includes(mode)) { this.mode = mode; } return this; diff --git a/spring-core/src/main/java/org/springframework/aot/hint/FieldHint.java b/spring-core/src/main/java/org/springframework/aot/hint/FieldHint.java index f2604a75fb5..0587700ccbc 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/FieldHint.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/FieldHint.java @@ -23,7 +23,7 @@ import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** - * A hint that describes the need of reflection on a {@link Field}. + * A hint that describes the need for reflection on a {@link Field}. * * @author Stephane Nicoll * @since 6.0 @@ -52,7 +52,7 @@ public final class FieldHint extends MemberHint { } /** - * Return the {@linkplain FieldMode mode} that apply to this hint. + * Return the {@linkplain FieldMode mode} that applies to this hint. * @return the mode */ public FieldMode getMode() { @@ -60,7 +60,7 @@ public final class FieldHint extends MemberHint { } /** - * Return whether if using {@code Unsafe} on the field should be allowed. + * Return whether using {@code Unsafe} on the field should be allowed. * @return {@code true} to allow unsafe access */ public boolean isAllowUnsafeAccess() { @@ -123,7 +123,7 @@ public final class FieldHint extends MemberHint { } /** - * Specify if using {@code Unsafe} on the field should be allowed. + * Specify whether using {@code Unsafe} on the field should be allowed. * @param allowUnsafeAccess {@code true} to allow unsafe access * @return {@code this}, to facilitate method chaining */ diff --git a/spring-core/src/test/java/org/springframework/aot/hint/ReflectionHintsTests.java b/spring-core/src/test/java/org/springframework/aot/hint/ReflectionHintsTests.java index 5c831323886..a7213d999ad 100644 --- a/spring-core/src/test/java/org/springframework/aot/hint/ReflectionHintsTests.java +++ b/spring-core/src/test/java/org/springframework/aot/hint/ReflectionHintsTests.java @@ -47,7 +47,7 @@ class ReflectionHintsTests { } @Test - void registerTypeIfPresentRegisterExistingClass() { + void registerTypeIfPresentRegistersExistingClass() { this.reflectionHints.registerTypeIfPresent(null, String.class.getName(), hint -> hint.withMembers(MemberCategory.DECLARED_FIELDS)); assertThat(this.reflectionHints.typeHints()).singleElement().satisfies( @@ -56,7 +56,7 @@ class ReflectionHintsTests { @Test @SuppressWarnings("unchecked") - void registerTypeIfPresentIgnoreMissingClass() { + void registerTypeIfPresentIgnoresMissingClass() { Consumer hintBuilder = mock(Consumer.class); this.reflectionHints.registerTypeIfPresent(null, "com.example.DoesNotExist", hintBuilder); assertThat(this.reflectionHints.typeHints()).isEmpty(); @@ -84,7 +84,7 @@ class ReflectionHintsTests { } @Test - void registerTypeReuseBuilder() { + void registerTypeReusesBuilder() { this.reflectionHints.registerType(TypeReference.of(String.class), MemberCategory.INVOKE_DECLARED_CONSTRUCTORS); Field field = ReflectionUtils.findField(String.class, "value"); @@ -105,7 +105,7 @@ class ReflectionHintsTests { } @Test - void registerClassWitCustomizer() { + void registerClassWithCustomizer() { this.reflectionHints.registerType(Integer.class, typeHint -> typeHint.withMembers(MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS)); assertThat(this.reflectionHints.typeHints()).singleElement().satisfies( @@ -113,16 +113,13 @@ class ReflectionHintsTests { } @Test - void registerTypesApplyTheSameHints() { + void registerTypesAppliesTheSameHints() { this.reflectionHints.registerTypes(TypeReference.listOf(Integer.class, String.class, Double.class), TypeHint.builtWith(MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS)); assertThat(this.reflectionHints.typeHints()) - .anySatisfy( - typeWithMemberCategories(Integer.class, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS)) - .anySatisfy( - typeWithMemberCategories(String.class, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS)) - .anySatisfy( - typeWithMemberCategories(Double.class, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS)) + .anySatisfy(typeWithMemberCategories(Integer.class, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS)) + .anySatisfy(typeWithMemberCategories(String.class, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS)) + .anySatisfy(typeWithMemberCategories(Double.class, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS)) .hasSize(3); } @@ -286,8 +283,7 @@ class ReflectionHintsTests { void registerMethodWithCustomizerAppliesCustomization() { Method method = ReflectionUtils.findMethod(TestType.class, "setName", String.class); assertThat(method).isNotNull(); - this.reflectionHints.registerMethod(method, methodHint -> - methodHint.withMode(ExecutableMode.INTROSPECT)); + this.reflectionHints.registerMethod(method, methodHint -> methodHint.withMode(ExecutableMode.INTROSPECT)); assertTestTypeMethodHints(methodHint -> { assertThat(methodHint.getName()).isEqualTo("setName"); assertThat(methodHint.getParameterTypes()).containsOnly(TypeReference.of(String.class)); diff --git a/spring-test/src/main/java/org/springframework/test/context/aot/TestContextAotGenerator.java b/spring-test/src/main/java/org/springframework/test/context/aot/TestContextAotGenerator.java index e003123aa4f..b4eaf1e756b 100644 --- a/spring-test/src/main/java/org/springframework/test/context/aot/TestContextAotGenerator.java +++ b/spring-test/src/main/java/org/springframework/test/context/aot/TestContextAotGenerator.java @@ -220,8 +220,8 @@ public class TestContextAotGenerator { new AotTestMappingsCodeGenerator(initializerClassMappings, generatedClasses); generationContext.writeGeneratedContent(); String className = codeGenerator.getGeneratedClass().getName().reflectionName(); - this.runtimeHints.reflection().registerType(TypeReference.of(className), - builder -> builder.withMembers(MemberCategory.INVOKE_PUBLIC_METHODS)); + this.runtimeHints.reflection() + .registerType(TypeReference.of(className), MemberCategory.INVOKE_PUBLIC_METHODS); } }