You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2017/11/15 14:12:14 UTC

[isis] branch master updated: ISIS-1778: excludes anonymous and @Programmatic classes from metamodel

This is an automated email from the ASF dual-hosted git repository.

danhaywood 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 fa8a1e8  ISIS-1778: excludes anonymous and @Programmatic classes from metamodel
     new 900f345  Merge branch 'ISIS-1778'
fa8a1e8 is described below

commit fa8a1e86aadad1e083d5bb8c179ed1e7a7080dec
Author: Dan Haywood <da...@haywood-associates.co.uk>
AuthorDate: Wed Nov 15 11:47:03 2017 +0000

    ISIS-1778: excludes anonymous and @Programmatic classes from metamodel
---
 .../org/apache/isis/applib/annotation/Programmatic.java   |  7 ++++++-
 .../specloader/classsubstitutor/ClassSubstitutor.java     | 15 +++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/core/applib/src/main/java/org/apache/isis/applib/annotation/Programmatic.java b/core/applib/src/main/java/org/apache/isis/applib/annotation/Programmatic.java
index 540e88c..19a0e21 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/annotation/Programmatic.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/annotation/Programmatic.java
@@ -35,11 +35,16 @@ import java.lang.annotation.Target;
  * parameter types).
  * 
  * <p>
+ * It can also be added to a type, meaning that the type is ignored from the metamodel.
+ * This is intended as a &quot;get out of jail&quot; for any classes from unit tests, say,
+ * that end up on the classpath of integration tests but should otherwise be ignored.
+ *
+ * <p>
  * This is intended as a replacement for {@link Ignore} (the use of which is
  * being discouraged because of the name clash with <tt>org.junit.Ignore</tt>).
  */
 @Inherited
-@Target({ ElementType.METHOD })
+@Target({ ElementType.METHOD, ElementType.TYPE })
 @Retention(RetentionPolicy.RUNTIME)
 public @interface Programmatic {
 
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/classsubstitutor/ClassSubstitutor.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/classsubstitutor/ClassSubstitutor.java
index df108b2..2cb35d5 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/classsubstitutor/ClassSubstitutor.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/classsubstitutor/ClassSubstitutor.java
@@ -22,6 +22,7 @@ package org.apache.isis.core.metamodel.specloader.classsubstitutor;
 import java.util.Set;
 import com.google.common.collect.Sets;
 import org.apache.isis.applib.DomainObjectContainer;
+import org.apache.isis.applib.annotation.Programmatic;
 import org.apache.isis.core.commons.lang.ClassUtil;
 
 /**
@@ -62,6 +63,14 @@ public class ClassSubstitutor {
         if (shouldIgnore(cls)) {
             return null;
         }
+
+        // primarily to ignore unit test fixtures if they happen to be on the classpath.
+        // (we can't simply ignore them; for example ApplicationFeatureType enum
+        // uses anonymous inner classes and these *are* part of the metamodel)
+        if(cls.isAnonymousClass()) {
+            return cls.getSuperclass();
+        }
+
         final Class<?> superclass = cls.getSuperclass();
         if(superclass != null && superclass.isEnum()) {
             return superclass;
@@ -99,6 +108,12 @@ public class ClassSubstitutor {
         if (cls.isArray()) {
             return shouldIgnore(cls.getComponentType());
         }
+
+        // ignore any classes
+        if(cls.getAnnotation(Programmatic.class) != null) {
+            return true;
+        }
+
         return classesToIgnore.contains(cls) || classNamesToIgnore.contains(cls.getCanonicalName());
     }
 

-- 
To stop receiving notification emails like this one, please contact
['"commits@isis.apache.org" <co...@isis.apache.org>'].