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 2023/01/19 10:48:03 UTC
[isis] branch master updated: ISIS-3327: minor refactoring
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 6d03ff13d5 ISIS-3327: minor refactoring
6d03ff13d5 is described below
commit 6d03ff13d5817a0e504838daa31430dbe8560ac0
Author: Andi Huber <ah...@apache.org>
AuthorDate: Thu Jan 19 11:47:55 2023 +0100
ISIS-3327: minor refactoring
---
.../commons/internal/reflection/_ClassCache.java | 26 +---------------------
.../commons/internal/reflection/_Reflect.java | 24 ++++++++++++++++++++
2 files changed, 25 insertions(+), 25 deletions(-)
diff --git a/commons/src/main/java/org/apache/causeway/commons/internal/reflection/_ClassCache.java b/commons/src/main/java/org/apache/causeway/commons/internal/reflection/_ClassCache.java
index 7280dec668..944c611894 100644
--- a/commons/src/main/java/org/apache/causeway/commons/internal/reflection/_ClassCache.java
+++ b/commons/src/main/java/org/apache/causeway/commons/internal/reflection/_ClassCache.java
@@ -284,7 +284,7 @@ public final class _ClassCache implements AutoCloseable {
} else {
// key-clash originating from one method overriding the other
// we need to figure out which is the overriding one (not the overwritten one)
- model.publicMethodsByKey.put(key, whichIsOverridingTheOther(methodWithSameKey, method));
+ model.publicMethodsByKey.put(key, _Reflect.methodsWhichIsOverridingTheOther(methodWithSameKey, method));
}
model.nonPublicDeclaredMethodsByKey.remove(key);
@@ -388,28 +388,4 @@ public final class _ClassCache implements AutoCloseable {
return _Strings.decapitalize(fieldName);
}
- /**
- * If MethodKey(type, a) equals MethodKey(type, b), which one wins, that is,
- * which one overrides the other?
- * @implNote if both declaring type and return type are the same we don't care
- */
- private Method whichIsOverridingTheOther(final Method a, final Method b) {
- val aType = a.getDeclaringClass();
- val bType = b.getDeclaringClass();
- if(aType.equals(bType)) {
- val aReturn = a.getReturnType();
- val bReturn = b.getReturnType();
- if(aReturn.equals(bReturn)) {
- // we should not care, arbitrarily picking b
- return b;
- }
- return aReturn.isAssignableFrom(bReturn)
- ? b
- : a;
- }
- return aType.isAssignableFrom(bType)
- ? b
- : a;
- }
-
}
diff --git a/commons/src/main/java/org/apache/causeway/commons/internal/reflection/_Reflect.java b/commons/src/main/java/org/apache/causeway/commons/internal/reflection/_Reflect.java
index 670d1aaf31..e7a834e0a7 100644
--- a/commons/src/main/java/org/apache/causeway/commons/internal/reflection/_Reflect.java
+++ b/commons/src/main/java/org/apache/causeway/commons/internal/reflection/_Reflect.java
@@ -107,6 +107,30 @@ public final class _Reflect {
|| b.getReturnType().isAssignableFrom(a.getReturnType());
}
+ /**
+ * If a and b are related, such that one overrides the other,
+ * that one which is overriding the other is returned.
+ * @implNote if both declaring type and return type are the same we (arbitrarily) return b
+ */
+ public static Method methodsWhichIsOverridingTheOther(final Method a, final Method b) {
+ val aType = a.getDeclaringClass();
+ val bType = b.getDeclaringClass();
+ if(aType.equals(bType)) {
+ val aReturn = a.getReturnType();
+ val bReturn = b.getReturnType();
+ if(aReturn.equals(bReturn)) {
+ // if a and b are not equal, this code path is expected unreachable
+ return b;
+ }
+ return aReturn.isAssignableFrom(bReturn)
+ ? b
+ : a;
+ }
+ return aType.isAssignableFrom(bType)
+ ? b
+ : a;
+ }
+
// -- COMPARATORS
/**