You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2022/01/20 12:01:59 UTC

[isis] branch master updated: ISIS-2944: fixes swep method search algorithm

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

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


The following commit(s) were added to refs/heads/master by this push:
     new e18237d  ISIS-2944: fixes swep method search algorithm
e18237d is described below

commit e18237dc1415f38d0f286d2113bc8393c99ba886
Author: Andi Huber <ah...@apache.org>
AuthorDate: Thu Jan 20 13:01:46 2022 +0100

    ISIS-2944: fixes swep method search algorithm
---
 .../core/metamodel/facets/ParameterSupport.java    | 38 ++++++++++++----------
 1 file changed, 20 insertions(+), 18 deletions(-)

diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/ParameterSupport.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/ParameterSupport.java
index e50735c..23abb45 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/ParameterSupport.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/ParameterSupport.java
@@ -190,28 +190,25 @@ public final class ParameterSupport {
         val methodNames = searchRequest.getSupporingMethodNameCandidates(paramIndex);
         val paramType = paramTypes[paramIndex];
         val additionalParamTypes = searchRequest.getAdditionalParamTypes();
-        val additionalParamCount = additionalParamTypes.size();
 
-        int paramsConsideredCount = paramIndex + additionalParamCount;
-        while(paramsConsideredCount>=0) {
+        //limit: [0 .. paramIndex + 1]
+        for(int limit = paramIndex + 1; limit>=0; --limit) {
 
-            val signature = concat(paramTypes, paramsConsideredCount, additionalParamTypes);
+            val signature = concat(paramTypes, limit, additionalParamTypes);
 
             val supportingMethod =
-            MethodFinder
-            .memberSupport(type, methodNames, processMethodContext.getIntrospectionPolicy())
-            .withReturnTypeAnyOf(searchRequest.getReturnTypePattern().matchingTypes(paramType))
-            .streamMethodsMatchingSignature(signature)
-            .findFirst()
-            .orElse(null);
+                    MethodFinder
+                    .memberSupport(type, methodNames, processMethodContext.getIntrospectionPolicy())
+                    .withReturnTypeAnyOf(searchRequest.getReturnTypePattern().matchingTypes(paramType))
+                    .streamMethodsMatchingSignature(signature)
+                    .findFirst()
+                    .orElse(null);
 
             if(supportingMethod != null) {
                 onMethodFound.accept(toSearchResult(paramIndex, paramType, supportingMethod));
                 return;
             }
 
-            // remove last, and search again
-            paramsConsideredCount--;
         }
 
     }
@@ -227,19 +224,24 @@ public final class ParameterSupport {
                         Optional.empty());
     }
 
+    /**
+     * @param paramTypes - all available
+     * @param paramsConsidered - limit
+     * @param additionalParamTypes - append regardless
+     */
     private static Class<?>[] concat(
             final Class<?>[] paramTypes,
-            final int paramsConsidered,
+            final int limit,
             final Can<Class<?>> additionalParamTypes) {
 
-        if(paramsConsidered>paramTypes.length) {
-            val msg = String.format("paramsConsidered %d exceeds size of paramTypes %d",
-                    paramsConsidered, paramTypes.length);
+        if(limit>paramTypes.length) {
+            val msg = String.format("limit %d exceeds size of paramTypes %d",
+                    limit, paramTypes.length);
             throw new IllegalArgumentException(msg);
         }
 
-        val paramTypesConsidered = paramsConsidered<paramTypes.length
-                ? Arrays.copyOf(paramTypes, paramsConsidered)
+        val paramTypesConsidered = limit<paramTypes.length
+                ? Arrays.copyOf(paramTypes, limit)
                 : paramTypes;
 
         val withAdditional = additionalParamTypes.isNotEmpty()