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

danhaywood pushed a commit to tag saveit
in repository https://gitbox.apache.org/repos/asf/isis.git

commit bbcba4e5d0a52a6b8f2e0a0032d09d503940f6a0
Author: Dan Haywood <d...@haywood-associates.co.uk>
AuthorDate: Mon Aug 29 10:54:51 2022 +0100

    ISIS-3190: excludes all non-annotated methods from metamodel if 
ENCAPSULATION_ENABLED is set as the introspection policy.
---
 .../beans/IsisBeanTypeClassifierDefault.java       |  6 +--
 .../progmodel/ProgrammingModelConstants.java       | 43 +++++++++++++++++-----
 .../_testing/MetaModelContext_forTesting.java      |  2 +-
 .../RemoveAnnotatedMethodsFacetFactory.java        | 40 ++++++++++++++++----
 .../classsubstitutor/ClassSubstitutorAbstract.java |  2 +-
 5 files changed, 70 insertions(+), 23 deletions(-)

diff --git 
a/core/config/src/main/java/org/apache/isis/core/config/beans/IsisBeanTypeClassifierDefault.java
 
b/core/config/src/main/java/org/apache/isis/core/config/beans/IsisBeanTypeClassifierDefault.java
index daded0f1c4..c67d426003 100644
--- 
a/core/config/src/main/java/org/apache/isis/core/config/beans/IsisBeanTypeClassifierDefault.java
+++ 
b/core/config/src/main/java/org/apache/isis/core/config/beans/IsisBeanTypeClassifierDefault.java
@@ -33,7 +33,7 @@ import org.apache.isis.applib.id.LogicalType;
 import org.apache.isis.applib.services.metamodel.BeanSort;
 import org.apache.isis.commons.collections.Can;
 import org.apache.isis.commons.internal.reflection._Annotations;
-import 
org.apache.isis.core.config.progmodel.ProgrammingModelConstants.TypeVetoMarker;
+import 
org.apache.isis.core.config.progmodel.ProgrammingModelConstants.TypeExcludeMarker;
 
 import lombok.AccessLevel;
 import lombok.NonNull;
@@ -78,7 +78,7 @@ implements IsisBeanTypeClassifier {
         }
 
         // handle vetoing ...
-        if(TypeVetoMarker.anyMatchOn(type)) {
+        if(TypeExcludeMarker.anyMatchOn(type)) {
             return IsisBeanMetaData.isisManaged(BeanSort.VETOED, type); // 
reject
         }
 
@@ -163,4 +163,4 @@ implements IsisBeanTypeClassifier {
         return activeProfiles.contains(profile);
     }
 
-}
\ No newline at end of file
+}
diff --git 
a/core/config/src/main/java/org/apache/isis/core/config/progmodel/ProgrammingModelConstants.java
 
b/core/config/src/main/java/org/apache/isis/core/config/progmodel/ProgrammingModelConstants.java
index a161a9ad7f..1ffef8a1c4 100644
--- 
a/core/config/src/main/java/org/apache/isis/core/config/progmodel/ProgrammingModelConstants.java
+++ 
b/core/config/src/main/java/org/apache/isis/core/config/progmodel/ProgrammingModelConstants.java
@@ -69,18 +69,18 @@ import lombok.val;
 
 public final class ProgrammingModelConstants {
 
-    // -- TYPE VETO MARKERS (EXLUDE FROM DOMAIN)
+    // -- TYPE EXCLUDE MARKERS
 
     @Getter
     @RequiredArgsConstructor
-    public enum TypeVetoMarker {
-        DOMAIN_EXLCUDE(Domain.Exclude.class),
+    public enum TypeExcludeMarker {
+        DOMAIN_EXCLUDE(Domain.Exclude.class),
         VETO(Vetoed.class);
         private final Class<? extends Annotation> annotationType;
 
         public static boolean anyMatchOn(final Class<?> type) {
-            for(TypeVetoMarker vetoMarker : TypeVetoMarker.values()) {
-                if(_Annotations.synthesize(type, 
vetoMarker.getAnnotationType()).isPresent()) {
+            for(TypeExcludeMarker excludeMarker : TypeExcludeMarker.values()) {
+                if(_Annotations.synthesize(type, 
excludeMarker.getAnnotationType()).isPresent()) {
                     return true;
                 }
             }
@@ -88,12 +88,35 @@ public final class ProgrammingModelConstants {
         }
     }
 
-    // -- METHOD VETO MARKERS (EXLUDE FROM DOMAIN)
+    // -- METHOD INCLUDE MARKERS
 
+    /**
+     * Ensure included.
+     */
     @Getter
     @RequiredArgsConstructor
-    public enum MethodVetoMarker {
-        DOMAIN_EXLCUDE(Domain.Exclude.class),
+    public enum MethodIncludeMarker {
+        DOMAIN_INCLUDE(Domain.Include.class),
+        ;
+        private final Class<? extends Annotation> annotationType;
+
+        public static boolean anyMatchOn(final Method method) {
+            for(MethodIncludeMarker includeMarker : 
MethodIncludeMarker.values()) {
+                if(_Annotations.synthesize(method, 
includeMarker.getAnnotationType()).isPresent()) {
+                    return true;
+                }
+            }
+            return false;
+        }
+    }
+
+
+    // -- METHOD EXCLUDE MARKERS
+
+    @Getter
+    @RequiredArgsConstructor
+    public enum MethodExcludeMarker {
+        DOMAIN_EXCLUDE(Domain.Exclude.class),
         PRE_DESTROY_JAVAX(javax.annotation.PreDestroy.class),
         POST_CONSTRUCT_JAVAX(javax.annotation.PostConstruct.class),
         //PRE_DESTROY__JAKARTA(jakarta.annotation.PreDestroy.class),
@@ -102,8 +125,8 @@ public final class ProgrammingModelConstants {
         private final Class<? extends Annotation> annotationType;
 
         public static boolean anyMatchOn(final Method method) {
-            for(MethodVetoMarker vetoMarker : MethodVetoMarker.values()) {
-                if(_Annotations.synthesize(method, 
vetoMarker.getAnnotationType()).isPresent()) {
+            for(MethodExcludeMarker excludeMarker : 
MethodExcludeMarker.values()) {
+                if(_Annotations.synthesize(method, 
excludeMarker.getAnnotationType()).isPresent()) {
                     return true;
                 }
             }
diff --git 
a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/_testing/MetaModelContext_forTesting.java
 
b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/_testing/MetaModelContext_forTesting.java
index 3f92fd2134..ddaf0d4f79 100644
--- 
a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/_testing/MetaModelContext_forTesting.java
+++ 
b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/_testing/MetaModelContext_forTesting.java
@@ -504,7 +504,7 @@ implements MetaModelContext {
                         "Cannot get service instance of type '%s'",
                         managedBeanAdapter.getBeanClass()));
 
-        
if(ProgrammingModelConstants.TypeVetoMarker.anyMatchOn(managedBeanAdapter.getBeanClass()))
 {
+        
if(ProgrammingModelConstants.TypeExcludeMarker.anyMatchOn(managedBeanAdapter.getBeanClass()))
 {
             return Optional.empty();
         }
         return Optional.of(ManagedObject.lazy(getSpecificationLoader(), 
servicePojo));
diff --git 
a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/ignore/annotation/RemoveAnnotatedMethodsFacetFactory.java
 
b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/ignore/annotation/RemoveAnnotatedMethodsFacetFactory.java
index 6794f18ee4..6e56642fb6 100644
--- 
a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/ignore/annotation/RemoveAnnotatedMethodsFacetFactory.java
+++ 
b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/ignore/annotation/RemoveAnnotatedMethodsFacetFactory.java
@@ -20,11 +20,14 @@ package 
org.apache.isis.core.metamodel.facets.object.ignore.annotation;
 
 import javax.inject.Inject;
 
-import 
org.apache.isis.core.config.progmodel.ProgrammingModelConstants.MethodVetoMarker;
+import org.apache.isis.core.config.progmodel.ProgrammingModelConstants;
+import 
org.apache.isis.core.config.progmodel.ProgrammingModelConstants.MethodExcludeMarker;
 import org.apache.isis.core.metamodel.context.MetaModelContext;
 import org.apache.isis.core.metamodel.facetapi.FeatureType;
 import org.apache.isis.core.metamodel.facets.FacetFactoryAbstract;
 
+import lombok.val;
+
 public class RemoveAnnotatedMethodsFacetFactory
 extends FacetFactoryAbstract {
 
@@ -35,13 +38,34 @@ extends FacetFactoryAbstract {
 
     @Override
     public void process(final ProcessClassContext processClassContext) {
-        getClassCache()
-        .streamPublicMethods(processClassContext.getCls())
-        .forEach(method->{
-            if(MethodVetoMarker.anyMatchOn(method)) {
-                processClassContext.removeMethod(method);
-            }
-        });
+
+        val policy = 
getMetaModelContext().getConfiguration().getCore().getMetaModel().getIntrospector().getPolicy();
+        switch (policy) {
+            case ENCAPSULATION_ENABLED:
+                
getClassCache().streamPublicOrDeclaredMethods(processClassContext.getCls())
+                        .forEach(method -> {
+                            if 
(!ProgrammingModelConstants.MethodIncludeMarker.anyMatchOn(method)) {
+                                processClassContext.removeMethod(method);
+                            }
+                        });
+                break;
+
+            case ANNOTATION_REQUIRED:
+                // TODO: this could probably be more precise and insist on 
@Domain.Include for members.
+
+            case ANNOTATION_OPTIONAL:
+
+                getClassCache()
+                        .streamPublicMethods(processClassContext.getCls())
+                        .forEach(method->{
+                            if(MethodExcludeMarker.anyMatchOn(method)) {
+                                processClassContext.removeMethod(method);
+                            }
+                        });
+
+                break;
+        }
+
 
     }
 
diff --git 
a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/classsubstitutor/ClassSubstitutorAbstract.java
 
b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/classsubstitutor/ClassSubstitutorAbstract.java
index 0e1f86d009..2732b36350 100644
--- 
a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/classsubstitutor/ClassSubstitutorAbstract.java
+++ 
b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/classsubstitutor/ClassSubstitutorAbstract.java
@@ -130,7 +130,7 @@ public abstract class ClassSubstitutorAbstract implements 
ClassSubstitutor {
         }
 
         // ignore vetoed types
-        if(ProgrammingModelConstants.TypeVetoMarker.anyMatchOn(cls)) {
+        if(ProgrammingModelConstants.TypeExcludeMarker.anyMatchOn(cls)) {
             return true;
         }
 

Reply via email to