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 2018/01/15 21:01:32 UTC
[isis] branch master updated: ISIS-1743 fa-Icon mapping for mixins
using '$$' method names
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 a0ac44c ISIS-1743 fa-Icon mapping for mixins using '$$' method names
a0ac44c is described below
commit a0ac44c4e1dd74f5faf4cb59541101d3b42be88b
Author: Andi Huber <ah...@apache.org>
AuthorDate: Mon Jan 15 22:01:29 2018 +0100
ISIS-1743 fa-Icon mapping for mixins using '$$' method names
---
.../annotprop/CssClassFaFacetOnMemberFactory.java | 9 +--
.../cssclassfa/annotprop/MixinInterceptor.java | 75 ++++++++++++++++++++++
2 files changed, 77 insertions(+), 7 deletions(-)
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/members/cssclassfa/annotprop/CssClassFaFacetOnMemberFactory.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/members/cssclassfa/annotprop/CssClassFaFacetOnMemberFactory.java
index 8fd1508..a72bac1 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/members/cssclassfa/annotprop/CssClassFaFacetOnMemberFactory.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/members/cssclassfa/annotprop/CssClassFaFacetOnMemberFactory.java
@@ -69,7 +69,7 @@ public class CssClassFaFacetOnMemberFactory extends FacetFactoryAbstract impleme
private CssClassFaFacet createFromConfiguredRegexIfPossible(final ProcessMethodContext processMethodContext) {
final Method method = processMethodContext.getMethod();
- String value = faIconIfAnyFor(method);
+ String value = faIconIfAnyFor(MixinInterceptor.intendedNameOf(method));
CssClassFaPosition position = CssClassFaPosition.LEFT;
if (value != null) {
int idxOfSeparator = value.indexOf(':');
@@ -84,12 +84,7 @@ public class CssClassFaFacetOnMemberFactory extends FacetFactoryAbstract impleme
}
}
- private String faIconIfAnyFor(Method method) {
- final String name = method.getName();
- return faIconIfAnyFor(name);
- }
-
- private String faIconIfAnyFor(String name) {
+ private String faIconIfAnyFor(String name) {
final Map<Pattern, String> faIconByPattern = getFaIconByPattern();
for (Map.Entry<Pattern, String> entry : faIconByPattern.entrySet()) {
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/members/cssclassfa/annotprop/MixinInterceptor.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/members/cssclassfa/annotprop/MixinInterceptor.java
new file mode 100644
index 0000000..21563f5
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/members/cssclassfa/annotprop/MixinInterceptor.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.isis.core.metamodel.facets.members.cssclassfa.annotprop;
+
+import java.lang.reflect.Method;
+
+import org.apache.isis.applib.annotation.Mixin;
+import org.apache.isis.core.commons.lang.NullSafe;
+import org.apache.isis.core.metamodel.facets.Annotations;
+
+/**
+ * To solve <a href="https://issues.apache.org/jira/browse/ISIS-1743">ISIS-1743</a>.<br/>
+ * Could be better integrated into Isis' meta-model.
+ *
+ * @author ahuber@apache.org
+ */
+class MixinInterceptor {
+
+ /**
+ * If method originates from a mixin and is named '$$' we infer the intended name
+ * from the mixin's class name.
+ *
+ * @param method
+ * @return the intended name of the method
+ */
+ public static String intendedNameOf(Method method) {
+
+ if("$$".equals(method.getName()) && isMixin(method.getDeclaringClass()) ) {
+ final String mixinMethodName = inferMixinMethodName(method.getDeclaringClass());
+ if(mixinMethodName!=null)
+ return mixinMethodName;
+ }
+ // default behavior
+ return method.getName();
+ }
+
+ // -- HELPER
+
+ private static boolean isMixin(Class<?> cls) {
+ return !NullSafe.isEmpty(Annotations.getAnnotations(cls, Mixin.class));
+ }
+
+
+ /**
+ * Parses class name of format 'Holder_mixinMethodName' and returns 'mixinMethodName'.
+ * @param mixin
+ * @return null if parsing fails
+ */
+ private static String inferMixinMethodName(Class<?> mixin) {
+ final String className = mixin.getSimpleName();
+ final int p = className.indexOf('_');
+ if(p>0 && className.length()>(p+1)) { // min length := p+2
+ return className.substring(p+1);
+ }
+ return null;
+ }
+
+}
--
To stop receiving notification emails like this one, please contact
['"commits@isis.apache.org" <co...@isis.apache.org>'].