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 2021/05/05 06:49:46 UTC
[isis] branch master updated: ISIS-2642: _Generics: just some
java-doc
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 6ca9d77 ISIS-2642: _Generics: just some java-doc
6ca9d77 is described below
commit 6ca9d77a4bf1ef1ea3351ce412538d24920a5ac6
Author: Andi Huber <ah...@apache.org>
AuthorDate: Wed May 5 08:49:32 2021 +0200
ISIS-2642: _Generics: just some java-doc
---
.../commons/internal/reflection/_Generics.java | 68 +++++++++++++---------
1 file changed, 42 insertions(+), 26 deletions(-)
diff --git a/commons/src/main/java/org/apache/isis/commons/internal/reflection/_Generics.java b/commons/src/main/java/org/apache/isis/commons/internal/reflection/_Generics.java
index cd8c276..100b569 100644
--- a/commons/src/main/java/org/apache/isis/commons/internal/reflection/_Generics.java
+++ b/commons/src/main/java/org/apache/isis/commons/internal/reflection/_Generics.java
@@ -43,9 +43,9 @@ import lombok.val;
* @since 2.0
*/
public final class _Generics {
-
+
// -- STREAMING TYPE ARGUMENTS
-
+
/**
* Returns a Stream of the actual type arguments for given {@code genericType}.
* @param owner - the corresponding class that declares the field or method,
@@ -53,61 +53,77 @@ public final class _Generics {
* @param genericType
*/
public static Stream<Class<?>> streamGenericTypeArgumentsOf(
- final @NonNull Class<?> owner,
+ final @NonNull Class<?> owner,
final @NonNull Type genericType) {
- return (genericType instanceof ParameterizedType)
+ return (genericType instanceof ParameterizedType)
? Stream.of(((ParameterizedType) genericType).getActualTypeArguments())
.flatMap(type->streamClassesOfType(owner, type))
: Stream.empty();
}
-
+
/**
- * Streams given {@code genericTypes} for their actual type arguments
- * and calls back {@code onTypeArgument} on each type argument found.
- * @param owner - the corresponding class that declares the method,
+ * Returns a Stream of the actual type arguments for given {@code genericTypes}.
+ * @param owner - the corresponding class that declares the method,
* which uses the {@code genericTypes}
* @param genericTypes
*/
public static Stream<Class<?>> streamGenericTypeArgumentsOf(
final @NonNull Class<?> owner,
final @Nullable Type[] genericTypes) {
-
+
return _NullSafe.stream(genericTypes)
.flatMap(type->streamGenericTypeArgumentsOf(owner, type));
}
-
+
// -- SHORTCUTS
-
+
+ /**
+ * Returns a Stream of the actual type arguments for given {@code field}.
+ */
public static Stream<Class<?>> streamGenericTypeArgumentsOfField(
final @NonNull Field field) {
- return streamGenericTypeArgumentsOf(field.getDeclaringClass(), field.getGenericType());
+ return streamGenericTypeArgumentsOf(
+ field.getDeclaringClass(),
+ field.getGenericType());
}
-
+
+ /**
+ * Returns a Stream of the actual type arguments for given {@code method}'s return type.
+ */
public static Stream<Class<?>> streamGenericTypeArgumentsOfMethodParameterTypes(
final @NonNull Method method) {
- return streamGenericTypeArgumentsOf(method.getDeclaringClass(), method.getGenericParameterTypes());
+ return streamGenericTypeArgumentsOf(
+ method.getDeclaringClass(),
+ method.getGenericParameterTypes());
}
-
+
+ /**
+ * Returns a Stream of the actual type arguments for given {@code method}'s parameter types.
+ */
public static Stream<Class<?>> streamGenericTypeArgumentsOfMethodReturnType(
final @NonNull Method method) {
- return streamGenericTypeArgumentsOf(method.getDeclaringClass(), method.getGenericReturnType());
+ return streamGenericTypeArgumentsOf(
+ method.getDeclaringClass(),
+ method.getGenericReturnType());
}
-
+
+ /**
+ * Returns a Stream of the actual type arguments for given {@code param}.
+ */
public static Stream<Class<?>> streamGenericTypeArgumentsOfParameter(
final @NonNull Parameter param) {
return streamGenericTypeArgumentsOf(
- param.getDeclaringExecutable().getDeclaringClass(),
+ param.getDeclaringExecutable().getDeclaringClass(),
param.getParameterizedType());
}
-
-
+
// -- HELPER
-
+
private static Stream<Class<?>> streamClassesOfType(
- final Class<?> owner,
+ final Class<?> owner,
final Type type) {
-
+
if (type instanceof Class) {
return Stream.of((Class<?>) type);
}
@@ -118,7 +134,7 @@ public final class _Generics {
Stream.of(wildcardType.getUpperBounds()))
.flatMap(x->streamClassesOfType(owner, x)); // recursive call
}
-
+
if (type instanceof TypeVariable) {
// try to match up with the actual type argument of the owner's generic superclass.
@@ -133,8 +149,8 @@ public final class _Generics {
}
// otherwise, what to do?
}
-
+
return Stream.empty();
}
-
+
}