This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/causeway.git


The following commit(s) were added to refs/heads/main by this push:
     new 826dfb37520 CAUSEWAY-3859: Java record refactoring (part 20)
826dfb37520 is described below

commit 826dfb375201352abf5f990445eb1df58af7cb6d
Author: Andi Huber <[email protected]>
AuthorDate: Wed Feb 19 12:25:12 2025 +0100

    CAUSEWAY-3859: Java record refactoring (part 20)
---
 .../core/metamodel/facets/ActionSupport.java       | 12 ++---
 .../core/metamodel/facets/ParameterSupport.java    | 16 +++---
 .../core/metamodel/methods/MethodFinder.java       | 63 ++++++++++------------
 .../core/metamodel/methods/MethodFinderPAT.java    | 10 ++--
 4 files changed, 45 insertions(+), 56 deletions(-)

diff --git 
a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/ActionSupport.java
 
b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/ActionSupport.java
index dcdac01994b..99795373e96 100644
--- 
a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/ActionSupport.java
+++ 
b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/ActionSupport.java
@@ -113,9 +113,9 @@ private static ActionSupportingMethodSearchResult 
toSearchResult(
             final MethodAndPatConstructor supportingMethodAndPatConstructor) {
         return ActionSupportingMethodSearchResult
                 .of(
-                        
supportingMethodAndPatConstructor.getSupportingMethod(),
-                        
supportingMethodAndPatConstructor.getSupportingMethod().returnType(),
-                        
Optional.of(supportingMethodAndPatConstructor.getPatConstructor()));
+                        supportingMethodAndPatConstructor.supportingMethod(),
+                        
supportingMethodAndPatConstructor.supportingMethod().returnType(),
+                        
Optional.of(supportingMethodAndPatConstructor.patConstructor()));
     }
 
     private final static void findActionSupportingMethodWithAllParamTypes(
@@ -134,9 +134,9 @@ private final static void 
findActionSupportingMethodWithAllParamTypes(
             var signature = concat(paramTypes, paramsConsideredCount, 
additionalParamTypes);
 
             finderOptions
-            .streamMethodsMatchingSignature(signature)
-            .map(ActionSupport::toSearchResult)
-            .forEach(onMethodFound);
+                .streamMethodsMatchingSignature(signature)
+                .map(ActionSupport::toSearchResult)
+                .forEach(onMethodFound);
         }
     }
 
diff --git 
a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/ParameterSupport.java
 
b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/ParameterSupport.java
index d21000347ba..ee723370c27 100644
--- 
a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/ParameterSupport.java
+++ 
b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/ParameterSupport.java
@@ -152,10 +152,10 @@ private static ParamSupportingMethodSearchResult 
toSearchResult(
             final MethodAndPatConstructor supportingMethodAndPatConstructor) {
         return ParamSupportingMethodSearchResult
                 .of(paramIndex, paramType,
-                    supportingMethodAndPatConstructor.getSupportingMethod(),
-                    
Optional.of(supportingMethodAndPatConstructor.getPatConstructor()),
+                    supportingMethodAndPatConstructor.supportingMethod(),
+                    
Optional.of(supportingMethodAndPatConstructor.patConstructor()),
                     _GenericResolver.forMethodReturn(
-                            
supportingMethodAndPatConstructor.getSupportingMethod()));
+                            
supportingMethodAndPatConstructor.supportingMethod()));
     }
 
     private static void singleArgBeingParamType(
@@ -171,11 +171,11 @@ private static void singleArgBeingParamType(
         var signature = new Class<?>[]{paramType};
 
         MethodFinder
-        .memberSupport(type, methodNames, 
processMethodContext.getIntrospectionPolicy())
-        
.withReturnTypeAnyOf(searchRequest.getReturnTypePattern().matchingTypes(paramType))
-        .streamMethodsMatchingSignature(signature)
-        .map(supportingMethod->toSearchResult(paramIndex, paramType, 
supportingMethod))
-        .forEach(onMethodFound);
+            .memberSupport(type, methodNames, 
processMethodContext.getIntrospectionPolicy())
+            
.withReturnTypeAnyOf(searchRequest.getReturnTypePattern().matchingTypes(paramType))
+            .streamMethodsMatchingSignature(signature)
+            .map(supportingMethod->toSearchResult(paramIndex, paramType, 
supportingMethod))
+            .forEach(onMethodFound);
     }
 
     /*
diff --git 
a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/methods/MethodFinder.java
 
b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/methods/MethodFinder.java
index b2a59831741..8761a4d8aa3 100644
--- 
a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/methods/MethodFinder.java
+++ 
b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/methods/MethodFinder.java
@@ -39,13 +39,16 @@
 import 
org.apache.causeway.core.config.progmodel.ProgrammingModelConstants.ConflictingAnnotations;
 import org.apache.causeway.core.metamodel.commons.MethodUtil;
 
-import lombok.AccessLevel;
-import lombok.Getter;
 import org.jspecify.annotations.NonNull;
-import lombok.RequiredArgsConstructor;
 
-@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
-public class MethodFinder {
+public record MethodFinder(
+        @NonNull Class<?> correspondingClass,
+        @NonNull Can<String> methodNameCandidates,
+        @NonNull EncapsulationPolicy encapsulationPolicy,
+        @NonNull Predicate<ResolvedMethod> mustSatisfy) {
+
+    public static final Can<String> ANY_NAME = Can.of(""); // arbitrary marker
+    public static final Class<?>[] NO_ARG = new Class<?>[0];
 
     public static MethodFinder of(
             final @NonNull Class<?> correspondingClass,
@@ -58,18 +61,15 @@ public static MethodFinder of(
 
         return new MethodFinder(
                 correspondingClass,
+                methodNameCandidates,
                 encapsulationPolicy,
                 methodNameCandidates.equals(ANY_NAME)
                         ? isNotStatic.and(mustSatisfy)
                         : isNotStatic
                             
.and(method->methodNameCandidates.contains(method.name()))
-                            .and(mustSatisfy),
-                methodNameCandidates);
+                            .and(mustSatisfy));
     }
 
-    public static final Can<String> ANY_NAME = Can.of(""); // arbitrary marker
-    public static final Class<?>[] NO_ARG = new Class<?>[0];
-
     public static MethodFinder notNecessarilyPublic(
             final Class<?> correspondingClass,
             final Can<String> methodNameCandidates) {
@@ -77,8 +77,7 @@ public static MethodFinder notNecessarilyPublic(
                 correspondingClass,
                 methodNameCandidates,
                 EncapsulationPolicy.ENCAPSULATED_MEMBERS_SUPPORTED,
-                _Predicates.alwaysTrue()
-                );
+                _Predicates.alwaysTrue());
     }
 
     public static MethodFinder publicOnly(
@@ -88,8 +87,7 @@ public static MethodFinder publicOnly(
                 correspondingClass,
                 methodNameCandidates,
                 EncapsulationPolicy.ONLY_PUBLIC_MEMBERS_SUPPORTED,
-                _Predicates.alwaysTrue()
-                );
+                _Predicates.alwaysTrue());
     }
 
     public static MethodFinder accessor(
@@ -138,21 +136,14 @@ public static MethodFinder memberSupport(
                 
ProgrammingModelConstants.ConflictingAnnotations.MEMBER_SUPPORT);
     }
 
-    @Getter private final @NonNull Class<?> correspondingClass;
-    @Getter private final @NonNull EncapsulationPolicy encapsulationPolicy;
-    @Getter private final @NonNull Predicate<ResolvedMethod> mustSatisfy;
-    private final @NonNull Can<String> methodNameCandidates;
-
     public Stream<ResolvedMethod> streamMethodsMatchingSignature(
             final @Nullable Class<?>[] paramTypes) {
 
-        if(paramTypes==null) {
-            return streamMethodsIgnoringSignature();
-        }
+        if(paramTypes==null) return streamMethodsIgnoringSignature();
 
-        var type = getCorrespondingClass();
+        var type = correspondingClass();
         var classCache = _ClassCache.getInstance();
-        var isEncapsulationSupported = 
getEncapsulationPolicy().isEncapsulatedMembersSupported();
+        var isEncapsulationSupported = 
encapsulationPolicy().isEncapsulatedMembersSupported();
 
         if(methodNameCandidates.equals(ANY_NAME)) {
             //stream all
@@ -164,18 +155,18 @@ public Stream<ResolvedMethod> 
streamMethodsMatchingSignature(
         }
 
         return methodNameCandidates.stream()
-        .map(name->isEncapsulationSupported
-                ? classCache.lookupResolvedMethod(type, name, paramTypes)
-                : classCache.lookupPublicMethod(type, name, paramTypes))
-        .filter(Optional::isPresent)
-        .map(Optional::get)
-        .filter(mustSatisfy);
+            .map(name->isEncapsulationSupported
+                    ? classCache.lookupResolvedMethod(type, name, paramTypes)
+                    : classCache.lookupPublicMethod(type, name, paramTypes))
+            .filter(Optional::isPresent)
+            .map(Optional::get)
+            .filter(mustSatisfy);
     }
 
     public Stream<ResolvedMethod> streamMethodsIgnoringSignature() {
-        var type = getCorrespondingClass();
+        var type = correspondingClass();
         var classCache = _ClassCache.getInstance();
-        var isEncapsulationSupported = 
getEncapsulationPolicy().isEncapsulatedMembersSupported();
+        var isEncapsulationSupported = 
encapsulationPolicy().isEncapsulatedMembersSupported();
         return (isEncapsulationSupported
                 ? classCache.streamResolvedMethods(type)
                 : classCache.streamPublicMethods(type))
@@ -187,17 +178,17 @@ public Stream<ResolvedMethod> 
streamMethodsIgnoringSignature() {
     public MethodFinder withRequiredReturnType(final @NonNull Class<?> 
requiredReturnType) {
         return new MethodFinder(
                 correspondingClass,
+                methodNameCandidates,
                 encapsulationPolicy,
-                
mustSatisfy.and(resolvedMethod->resolvedMethod.isReturnTypeATypeOf(requiredReturnType)),
-                methodNameCandidates);
+                
mustSatisfy.and(resolvedMethod->resolvedMethod.isReturnTypeATypeOf(requiredReturnType)));
     }
 
     public MethodFinder withReturnTypeAnyOf(final @NonNull Can<Class<?>> 
anyOfReturnTypes) {
         return new MethodFinder(
                 correspondingClass,
+                methodNameCandidates,
                 encapsulationPolicy,
-                
mustSatisfy.and(resolvedMethod->resolvedMethod.isReturnTypeAnyTypeOf(anyOfReturnTypes)),
-                methodNameCandidates);
+                
mustSatisfy.and(resolvedMethod->resolvedMethod.isReturnTypeAnyTypeOf(anyOfReturnTypes)));
     }
 
     // -- HELPER
diff --git 
a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/methods/MethodFinderPAT.java
 
b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/methods/MethodFinderPAT.java
index b0338ec9b96..23d8adbd54b 100644
--- 
a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/methods/MethodFinderPAT.java
+++ 
b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/methods/MethodFinderPAT.java
@@ -31,7 +31,6 @@
 import org.apache.causeway.core.metamodel.commons.MethodUtil;
 
 import org.jspecify.annotations.NonNull;
-import lombok.Value;
 import lombok.experimental.UtilityClass;
 
 /**
@@ -42,10 +41,9 @@ public final class MethodFinderPAT {
 
     // -- PAT SUPPORT
 
-    @Value(staticConstructor = "of")
-    public static class MethodAndPatConstructor {
-        @NonNull ResolvedMethod supportingMethod;
-        @NonNull ResolvedConstructor patConstructor;
+    public record MethodAndPatConstructor(
+        @NonNull ResolvedMethod supportingMethod,
+        @NonNull ResolvedConstructor patConstructor) {
     }
 
     // -- SEARCH FOR MULTIPLE NAME CANDIDATES (PAT)
@@ -80,7 +78,7 @@ private Optional<MethodAndPatConstructor> 
lookupPatConstructor(
 
         return classCache
                 .lookupPublicConstructor(patCandidate, signature)
-                .map(constructor->MethodAndPatConstructor.of(supportingMethod, 
constructor));
+                .map(constructor->new 
MethodAndPatConstructor(supportingMethod, constructor));
     }
 
 }

Reply via email to