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 2019/10/04 07:32:57 UTC
[isis] 01/01: ISIS-2158: convert MixinInterceptor to use new
_Annotations API
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch v2
in repository https://gitbox.apache.org/repos/asf/isis.git
commit 8400144799133436e3edbe7060545c892b88fe31
Author: Andi Huber <ah...@apache.org>
AuthorDate: Fri Oct 4 09:32:45 2019 +0200
ISIS-2158: convert MixinInterceptor to use new _Annotations API
---
.../org/apache/isis/commons/internal/base/_With.java | 6 +++---
.../commons/internal/reflection/_Annotations.java | 20 +++++++++++++++++++-
.../cssclassfa/annotprop/MixinInterceptor.java | 18 +++++++++---------
3 files changed, 31 insertions(+), 13 deletions(-)
diff --git a/core/commons/src/main/java/org/apache/isis/commons/internal/base/_With.java b/core/commons/src/main/java/org/apache/isis/commons/internal/base/_With.java
index 569a5e1..f30fbf4 100644
--- a/core/commons/src/main/java/org/apache/isis/commons/internal/base/_With.java
+++ b/core/commons/src/main/java/org/apache/isis/commons/internal/base/_With.java
@@ -214,7 +214,7 @@ public final class _With<T> {
*/
public static <T> T requires(@Nullable T obj, String paramName) {
if (obj == null) {
- throw new NullPointerException(String.format("Parameter '%s' is required to be present (not null).", paramName));
+ throw new NullPointerException(String.format("Parameter/Field '%s' is required to be present (not null).", paramName));
}
return obj;
}
@@ -231,10 +231,10 @@ public final class _With<T> {
*/
public static String requiresNotEmpty(@Nullable String obj, String paramName) {
if (obj == null) {
- throw new NullPointerException(String.format("Parameter '%s' is required to be present (not null).", paramName));
+ throw new NullPointerException(String.format("Parameter/Field '%s' is required to be present (not null).", paramName));
}
if (obj.length()==0) {
- throw new IllegalArgumentException(String.format("Parameter '%s' is required to be present and not empty.", paramName));
+ throw new IllegalArgumentException(String.format("Parameter/Field '%s' is required to be present and not empty.", paramName));
}
return obj;
}
diff --git a/core/commons/src/main/java/org/apache/isis/commons/internal/reflection/_Annotations.java b/core/commons/src/main/java/org/apache/isis/commons/internal/reflection/_Annotations.java
index a74241a..39a7b61 100644
--- a/core/commons/src/main/java/org/apache/isis/commons/internal/reflection/_Annotations.java
+++ b/core/commons/src/main/java/org/apache/isis/commons/internal/reflection/_Annotations.java
@@ -42,6 +42,22 @@ import lombok.val;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class _Annotations {
+
+ /**
+ * Optionally returns the 'nearest' annotation of given type based on presence.
+ *
+ * @param <A>
+ * @param annotatedElement
+ * @param annotationType
+ * @return non-null
+ */
+ public static <A extends Annotation> Optional<A> findNearestAnnotation(
+ Class<?> annotatedElement,
+ Class<A> annotationType) {
+ //XXX if synthesize has got runtime performance, than we simply us it here
+ return synthesize(annotatedElement, annotationType);
+ }
+
/**
* Optionally create a type-safe synthesized version of this annotation based on presence.
* <p>
@@ -135,7 +151,7 @@ public final class _Annotations {
Class<E> enumType) {
return getEnum(attributeName, annotatedElement, annotationType, enumType, DEFAULT_ATTRIBUTE_ACCEPT_STRATEGY);
}
-
+
// -- BEHAVIOR
public final static AttributeAcceptStrategy DEFAULT_ATTRIBUTE_ACCEPT_STRATEGY =
@@ -164,6 +180,8 @@ public final class _Annotations {
val collected = MergedAnnotations.from(annotatedElement, SearchStrategy.INHERITED_ANNOTATIONS);
return collected;
}
+
+
diff --git a/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/members/cssclassfa/annotprop/MixinInterceptor.java b/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/members/cssclassfa/annotprop/MixinInterceptor.java
index 191ed85..68cca14 100644
--- a/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/members/cssclassfa/annotprop/MixinInterceptor.java
+++ b/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/members/cssclassfa/annotprop/MixinInterceptor.java
@@ -20,13 +20,13 @@
package org.apache.isis.metamodel.facets.members.cssclassfa.annotprop;
import java.lang.reflect.Method;
-import java.util.List;
-import java.util.Optional;
import org.apache.isis.applib.annotation.Mixin;
-import org.apache.isis.metamodel.facets.Annotations;
+import org.apache.isis.commons.internal.reflection._Annotations;
import org.apache.isis.metamodel.specloader.specimpl.ObjectMemberAbstract;
+import lombok.val;
+
/**
* To solve <a href="https://issues.apache.org/jira/browse/ISIS-1743">ISIS-1743</a>.<br/>
* Could be better integrated into Isis' meta-model.
@@ -43,15 +43,15 @@ class MixinInterceptor {
*/
static String intendedNameOf(Method method) {
- final Class<?> declaringClass = method.getDeclaringClass();
- final List<Mixin> mixins = Annotations.getAnnotations(declaringClass, Mixin.class);
- final Optional<Mixin> mixinIfAny = mixins.stream().findFirst();
+ val declaringClass = method.getDeclaringClass();
+ val mixinIfAny = _Annotations.findNearestAnnotation(declaringClass, Mixin.class);
if(mixinIfAny.isPresent()) {
- final String methodName = method.getName();
- final String mixinAnnotMethodName = mixinIfAny.get().method();
+ val methodName = method.getName();
+ val mixinAnnotMethodName = mixinIfAny.get().method();
if(mixinAnnotMethodName.equals(methodName)) {
- final String mixinMethodName = ObjectMemberAbstract.deriveMemberNameFrom(method.getDeclaringClass().getName());
+ val mixinMethodName =
+ ObjectMemberAbstract.deriveMemberNameFrom(method.getDeclaringClass().getName());
if(mixinMethodName!=null) {
return mixinMethodName;
}