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/11/16 10:51:35 UTC

[isis] branch master updated: ISIS-2894: proper (non-static) inner method detection

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 ddf3bd1  ISIS-2894: proper (non-static) inner method detection
ddf3bd1 is described below

commit ddf3bd186cad585b959b7f20d8c9ac5e3f33263d
Author: Andi Huber <ah...@apache.org>
AuthorDate: Tue Nov 16 11:51:21 2021 +0100

    ISIS-2894: proper (non-static) inner method detection
---
 .../isis/commons/internal/reflection/_Reflect.java |  6 +++++
 .../commons/internal/reflection/ReflectTest.java   | 26 ++++++++++++++++++----
 .../ignore/javalang/RemoveMethodsFacetFactory.java | 13 ++++-------
 3 files changed, 32 insertions(+), 13 deletions(-)

diff --git a/commons/src/main/java/org/apache/isis/commons/internal/reflection/_Reflect.java b/commons/src/main/java/org/apache/isis/commons/internal/reflection/_Reflect.java
index 6c2500a..e0b7f21 100644
--- a/commons/src/main/java/org/apache/isis/commons/internal/reflection/_Reflect.java
+++ b/commons/src/main/java/org/apache/isis/commons/internal/reflection/_Reflect.java
@@ -686,5 +686,11 @@ public final class _Reflect {
         + ")";
     }
 
+    /**
+     * Determine if the supplied method is declared within a non-static <em>inner class</em>.
+     */
+    public static boolean isNonStaticInnerMethod(final @NonNull Method method) {
+        return ClassUtils.isInnerClass(method.getDeclaringClass());
+    }
 
 }
diff --git a/commons/src/test/java/org/apache/isis/commons/internal/reflection/ReflectTest.java b/commons/src/test/java/org/apache/isis/commons/internal/reflection/ReflectTest.java
index 9d23fb3..dbfec38 100644
--- a/commons/src/test/java/org/apache/isis/commons/internal/reflection/ReflectTest.java
+++ b/commons/src/test/java/org/apache/isis/commons/internal/reflection/ReflectTest.java
@@ -55,9 +55,17 @@ class ReflectTest {
 
     }
 
-    Method a;
-    Method b;
-    Method c;
+    static class Outer{
+        class NonStaticInner {
+            public void nonStaticInnerMethod() {}
+        }
+        static class StaticInner {
+            public void staticInnerMethod() {}
+        }
+    }
+
+    Method a, b, c;
+    Method nonStaticInnerMethod, staticInnerMethod;
 
     @BeforeEach
     void setUp() throws Exception {
@@ -67,10 +75,16 @@ class ReflectTest {
         a = ReflectionUtils.findMethod(Parent.class, "getSomething", new Class[] {Collection.class});
         b = ReflectionUtils.findMethod(Child.class, "getSomething", new Class[] {Collection.class});
         c = ReflectionUtils.findMethod(Child.class, "getSomething", new Class[] {List.class});
+        nonStaticInnerMethod = ReflectionUtils
+                .findMethod(Outer.NonStaticInner.class, "nonStaticInnerMethod", new Class[] {});
+        staticInnerMethod = ReflectionUtils
+                .findMethod(Outer.StaticInner.class, "staticInnerMethod", new Class[] {});
 
         assertNotNull(a);
         assertNotNull(b);
         assertNotNull(c);
+        assertNotNull(nonStaticInnerMethod);
+        assertNotNull(staticInnerMethod);
 
         assertNotEquals(a, b);
         assertNotEquals(a, c);
@@ -89,6 +103,10 @@ class ReflectTest {
         assertTrue(_Reflect.methodWeakCompare(a, c) != 0);
     }
 
-
+    @Test
+    void methodIsInner() {
+        assertTrue(_Reflect.isNonStaticInnerMethod(nonStaticInnerMethod));
+        assertFalse(_Reflect.isNonStaticInnerMethod(staticInnerMethod));
+    }
 
 }
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/ignore/javalang/RemoveMethodsFacetFactory.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/ignore/javalang/RemoveMethodsFacetFactory.java
index ebb18cf..13df587 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/ignore/javalang/RemoveMethodsFacetFactory.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/ignore/javalang/RemoveMethodsFacetFactory.java
@@ -26,7 +26,7 @@ import org.apache.isis.applib.annotation.Action;
 import org.apache.isis.commons.internal._Constants;
 import org.apache.isis.commons.internal.collections._Lists;
 import org.apache.isis.commons.internal.reflection._Annotations;
-import org.apache.isis.core.config.progmodel.ProgrammingModelConstants;
+import org.apache.isis.commons.internal.reflection._Reflect;
 import org.apache.isis.core.metamodel.commons.ClassExtensions;
 import org.apache.isis.core.metamodel.context.MetaModelContext;
 import org.apache.isis.core.metamodel.facetapi.Facet;
@@ -88,15 +88,10 @@ public class RemoveMethodsFacetFactory extends FacetFactoryAbstract {
         getClassCache()
         .streamPublicMethods(cls)
         .forEach(method->{
-            // remove synthetic methods (except when is a mixin)
-            // (it seems that javac marks methods synthetic in the context of non-static inner classes)
-
+            // remove methods in the context of non-static inner classes,
+            // except cls when is a mixin
             if (!isConcreteMixin
-                    //FIXME[ISIS-2894] method.isSynthetic() seems a bad indicator for nested inner,
-                    // perhaps find a better way
-                    && method.isSynthetic()
-                    // workaround ... don't remove getters, even if synthetic
-                    && !ProgrammingModelConstants.AccessorPrefix.isGetter(method)) {
+                    && _Reflect.isNonStaticInnerMethod(method)) {
                 processClassContext.removeMethod(method);
                 return;
             }