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/05/03 13:29:58 UTC
[isis] branch master updated: ISIS-2641: let
IsisBeanTypeClassififer also handle non-concrete types
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 e6b062f ISIS-2641: let IsisBeanTypeClassififer also handle non-concrete types
e6b062f is described below
commit e6b062f0f04a8c5f9eb3498967c76d635816fbbb
Author: Andi Huber <ah...@apache.org>
AuthorDate: Mon May 3 15:29:43 2021 +0200
ISIS-2641: let IsisBeanTypeClassififer also handle non-concrete types
---
.../core/config/beans/IsisBeanTypeClassifier.java | 5 +++--
.../config/beans/IsisBeanTypeClassifierImpl.java | 12 ++++++++++++
.../specloader/SpecificationLoaderDefault.java | 21 +--------------------
.../DomainModelTest_usingGoodDomain.java | 19 +++++++++++++++----
.../testdomain/model/good/ElementTypeInterface.java | 18 ++++++++++++++++++
.../testdomain/model/good/ProperElementTypeVm.java | 5 ++++-
6 files changed, 53 insertions(+), 27 deletions(-)
diff --git a/core/config/src/main/java/org/apache/isis/core/config/beans/IsisBeanTypeClassifier.java b/core/config/src/main/java/org/apache/isis/core/config/beans/IsisBeanTypeClassifier.java
index c7a5e38..61ec6a3 100644
--- a/core/config/src/main/java/org/apache/isis/core/config/beans/IsisBeanTypeClassifier.java
+++ b/core/config/src/main/java/org/apache/isis/core/config/beans/IsisBeanTypeClassifier.java
@@ -38,8 +38,9 @@ public interface IsisBeanTypeClassifier {
/**
* Returns the bean classification for given {@code type}.
*
- * @apiNote we assume, that the {@code type} is not a primitive,
- * not an interface and not an abstract type
+ * @apiNote Initially used to collect all concrete types that are considered by Spring
+ * for type inspection, but later used by the {@code SpecificationLoader} to also
+ * classify non-concrete types (interfaces and abstract classes).
*/
BeanClassification classify(Class<?> type);
diff --git a/core/config/src/main/java/org/apache/isis/core/config/beans/IsisBeanTypeClassifierImpl.java b/core/config/src/main/java/org/apache/isis/core/config/beans/IsisBeanTypeClassifierImpl.java
index 770e732..acf91ff 100644
--- a/core/config/src/main/java/org/apache/isis/core/config/beans/IsisBeanTypeClassifierImpl.java
+++ b/core/config/src/main/java/org/apache/isis/core/config/beans/IsisBeanTypeClassifierImpl.java
@@ -19,6 +19,7 @@
package org.apache.isis.core.config.beans;
import java.io.Serializable;
+import java.lang.reflect.Modifier;
import java.util.Collection;
import java.util.Locale;
@@ -54,6 +55,10 @@ implements IsisBeanTypeClassifier {
@Override
public BeanClassification classify(final @NonNull Class<?> type) {
+ if(type.isPrimitive()) {
+ return BeanClassification.delegated(BeanSort.VALUE);
+ }
+
if(findNearestAnnotation(type, Vetoed.class).isPresent()
|| findNearestAnnotation(type, Programmatic.class).isPresent()) {
return BeanClassification.selfManaged(BeanSort.VETOED); // reject
@@ -143,6 +148,13 @@ implements IsisBeanTypeClassifier {
return BeanClassification.selfManaged(BeanSort.COLLECTION);
}
+ if(type.isInterface()
+ // modifier predicate must be called after testing for non-scalar type above,
+ // otherwise we'd get false positives
+ || Modifier.isAbstract(type.getModifiers())) {
+ return BeanClassification.delegated(BeanSort.ABSTRACT);
+ }
+
if(Serializable.class.isAssignableFrom(type)) {
return BeanClassification.delegated(BeanSort.VALUE);
}
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/SpecificationLoaderDefault.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/SpecificationLoaderDefault.java
index c80d893..a31e9f1 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/SpecificationLoaderDefault.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/SpecificationLoaderDefault.java
@@ -18,9 +18,7 @@
*/
package org.apache.isis.core.metamodel.specloader;
-import java.lang.reflect.Modifier;
import java.util.Arrays;
-import java.util.Collection;
import java.util.Collections;
import java.util.Optional;
import java.util.concurrent.BlockingQueue;
@@ -380,24 +378,7 @@ public class SpecificationLoaderDefault implements SpecificationLoader {
__->isisBeanTypeRegistry
.lookupIntrospectableType(type)
.map(IsisBeanMetaData::getBeanSort)
- .orElseGet(()->{
- // the isisBeanTypeClassifier is not meant to handle
- // - primitive types
- // - non-concrete types
- if(type.isPrimitive()) {
- return BeanSort.VALUE;
- }
- if(Collection.class.isAssignableFrom(type)
- || Can.class.isAssignableFrom(type)
- || type.isArray()) {
- return BeanSort.COLLECTION;
- }
- if(type.isInterface()
- || Modifier.isAbstract(type.getModifiers())) {
- return BeanSort.ABSTRACT;
- }
- return isisBeanTypeClassifier.classify(type).getBeanSort();
- }),
+ .orElseGet(()->isisBeanTypeClassifier.classify(type).getBeanSort()),
upTo);
}
diff --git a/regressiontests/stable-domainmodel/src/test/java/org/apache/isis/testdomain/domainmodel/DomainModelTest_usingGoodDomain.java b/regressiontests/stable-domainmodel/src/test/java/org/apache/isis/testdomain/domainmodel/DomainModelTest_usingGoodDomain.java
index 3734dab..2f7dcd2 100644
--- a/regressiontests/stable-domainmodel/src/test/java/org/apache/isis/testdomain/domainmodel/DomainModelTest_usingGoodDomain.java
+++ b/regressiontests/stable-domainmodel/src/test/java/org/apache/isis/testdomain/domainmodel/DomainModelTest_usingGoodDomain.java
@@ -35,6 +35,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.apache.isis.applib.services.jaxb.JaxbService;
+import org.apache.isis.applib.services.metamodel.BeanSort;
import org.apache.isis.applib.services.metamodel.Config;
import org.apache.isis.applib.services.metamodel.MetaModelService;
import org.apache.isis.applib.services.registry.ServiceRegistry;
@@ -50,6 +51,8 @@ import org.apache.isis.core.metamodel.specloader.specimpl.IntrospectionState;
import org.apache.isis.schema.metamodel.v2.DomainClassDto;
import org.apache.isis.testdomain.conf.Configuration_headless;
import org.apache.isis.testdomain.model.good.Configuration_usingValidDomain;
+import org.apache.isis.testdomain.model.good.ElementTypeConcrete;
+import org.apache.isis.testdomain.model.good.ElementTypeInterface;
import org.apache.isis.testdomain.model.good.ProperElementTypeVm;
import org.apache.isis.testdomain.model.good.ProperMemberInheritanceInterface;
import org.apache.isis.testdomain.model.good.ProperMemberInheritance_usingAbstract;
@@ -280,12 +283,20 @@ class DomainModelTest_usingGoodDomain {
val vmSpec = specificationLoader.loadSpecification(ProperElementTypeVm.class,
IntrospectionState.FULLY_INTROSPECTED);
- val coll = vmSpec.getCollectionElseFail("myColl");
- val collSpec = coll.getSpecification();
+ val concreteColl = vmSpec.getCollectionElseFail("concreteColl");
+ val concreteCollSpec = concreteColl.getSpecification();
- val elementTypeSpec = collSpec.getElementSpecification().orElse(null);
- // TODO add actual checks
+ assertEquals(ElementTypeConcrete.class, concreteCollSpec.getCorrespondingClass());
+ assertEquals(BeanSort.VIEW_MODEL, concreteCollSpec.getBeanSort());
+ val interfaceColl = vmSpec.getCollectionElseFail("interfaceColl");
+ val interfaceCollSpec = interfaceColl.getSpecification();
+
+ //FIXME yet test fails
+ //assertEquals(ElementTypeInterface.class, interfaceCollSpec.getCorrespondingClass());
+ //assertEquals(BeanSort.ABSTRACT, interfaceCollSpec.getBeanSort());
+
+ // TODO for the abstract case, we also want to see any members and the title-facet
}
// -- HELPER
diff --git a/regressiontests/stable/src/main/java/org/apache/isis/testdomain/model/good/ElementTypeInterface.java b/regressiontests/stable/src/main/java/org/apache/isis/testdomain/model/good/ElementTypeInterface.java
index 51490c5..12a059a 100644
--- a/regressiontests/stable/src/main/java/org/apache/isis/testdomain/model/good/ElementTypeInterface.java
+++ b/regressiontests/stable/src/main/java/org/apache/isis/testdomain/model/good/ElementTypeInterface.java
@@ -1,3 +1,21 @@
+/*
+ * 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.testdomain.model.good;
import org.apache.isis.applib.annotation.DomainObject;
diff --git a/regressiontests/stable/src/main/java/org/apache/isis/testdomain/model/good/ProperElementTypeVm.java b/regressiontests/stable/src/main/java/org/apache/isis/testdomain/model/good/ProperElementTypeVm.java
index 52f4d9a..b92621c 100644
--- a/regressiontests/stable/src/main/java/org/apache/isis/testdomain/model/good/ProperElementTypeVm.java
+++ b/regressiontests/stable/src/main/java/org/apache/isis/testdomain/model/good/ProperElementTypeVm.java
@@ -31,6 +31,9 @@ import lombok.Setter;
public class ProperElementTypeVm {
@Collection
- @Getter @Setter private List<? extends ElementTypeInterface> myColl;
+ @Getter @Setter private List<? extends ElementTypeInterface> interfaceColl;
+
+ @Collection
+ @Getter @Setter private List<ElementTypeConcrete> concreteColl;
}