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 2021/03/03 09:07:01 UTC
[isis] 02/05: ISIS-439: further work removing dead code re: mutable
collections
This is an automated email from the ASF dual-hosted git repository.
danhaywood pushed a commit to branch ISIS-2444
in repository https://gitbox.apache.org/repos/asf/isis.git
commit 39ebfacbba1a42d6d4cc55e1eba54e4abfe615f9
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Wed Mar 3 07:04:12 2021 +0000
ISIS-439: further work removing dead code re: mutable collections
---
.../events/domain/CollectionDomainEvent.java | 35 -------
.../core/metamodel/facets/DomainEventHelper.java | 110 ++++++++-------------
.../modify/CollectionDomainEventFacetAbstract.java | 2 -
...HelperTest_newCollectionDomainEvent_forAdd.java | 6 +-
...perTest_newCollectionDomainEvent_forRemove.java | 6 +-
5 files changed, 49 insertions(+), 110 deletions(-)
diff --git a/api/applib/src/main/java/org/apache/isis/applib/events/domain/CollectionDomainEvent.java b/api/applib/src/main/java/org/apache/isis/applib/events/domain/CollectionDomainEvent.java
index 6d4c57c..7b1c489 100644
--- a/api/applib/src/main/java/org/apache/isis/applib/events/domain/CollectionDomainEvent.java
+++ b/api/applib/src/main/java/org/apache/isis/applib/events/domain/CollectionDomainEvent.java
@@ -93,32 +93,6 @@ public abstract class CollectionDomainEvent<S,T> extends AbstractDomainEvent<S>
@Getter
private T value;
- public static enum Of {
- /**
- * The collection is being accessed
- * ({@link AbstractDomainEvent.Phase#HIDE hide} and
- * {@link AbstractDomainEvent.Phase#DISABLE disable}) checks.
- */
- ACCESS,
-
- /**
- * The collection is being added to
- * ({@link AbstractDomainEvent.Phase#VALIDATE validity} check and
- * {@link AbstractDomainEvent.Phase#EXECUTED execution}).
- */
- ADD_TO,
-
- /**
- * The collection is being removed from
- * ({@link AbstractDomainEvent.Phase#VALIDATE validity} check and
- * {@link AbstractDomainEvent.Phase#EXECUTED execution}).
- */
- REMOVE_FROM
-
- }
-
- @Getter
- private Of of;
/**
* Not API, set by the framework.
@@ -126,14 +100,6 @@ public abstract class CollectionDomainEvent<S,T> extends AbstractDomainEvent<S>
public void setValue(T value) {
this.value = value;
}
- /**
- * Not API; updates from {@link Of#ACCESS} to either {@link Of#ADD_TO}
- * or {@link Of#REMOVE_FROM} when hits the
- * {@link AbstractDomainEvent.Phase#VALIDATE validation phase}.
- */
- public void setOf(Of of) {
- this.of = of;
- }
private static final ToString<CollectionDomainEvent<?,?>> toString =
@@ -141,7 +107,6 @@ public abstract class CollectionDomainEvent<S,T> extends AbstractDomainEvent<S>
toString("source", CollectionDomainEvent::getSource)
.thenToString("identifier", CollectionDomainEvent::getIdentifier)
.thenToString("eventPhase", CollectionDomainEvent::getEventPhase)
- .thenToString("of", CollectionDomainEvent::getOf)
.thenToString("value", CollectionDomainEvent::getValue)
;
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/DomainEventHelper.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/DomainEventHelper.java
index 8029c45..56cb6d6 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/DomainEventHelper.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/DomainEventHelper.java
@@ -67,7 +67,7 @@ public class DomainEventHelper {
private final MetamodelEventService metamodelEventService;
// -- postEventForAction
-
+
// variant using eventType and no existing event
public ActionDomainEvent<?> postEventForAction(
final AbstractDomainEvent.Phase phase,
@@ -77,12 +77,12 @@ public class DomainEventHelper {
final InteractionHead head,
final Can<ManagedObject> argumentAdapters,
final ManagedObject resultAdapter) {
-
- return postEventForAction(phase, uncheckedCast(eventType), /*existingEvent*/null,
- objectAction, identified,
+
+ return postEventForAction(phase, uncheckedCast(eventType), /*existingEvent*/null,
+ objectAction, identified,
head, argumentAdapters, resultAdapter);
}
-
+
// variant using existing event and not eventType (is derived from event)
public ActionDomainEvent<?> postEventForAction(
final AbstractDomainEvent.Phase phase,
@@ -92,9 +92,9 @@ public class DomainEventHelper {
final InteractionHead head,
final Can<ManagedObject> argumentAdapters,
final ManagedObject resultAdapter) {
-
- return postEventForAction(phase,
- uncheckedCast(existingEvent.getClass()), existingEvent, objectAction, identified,
+
+ return postEventForAction(phase,
+ uncheckedCast(existingEvent.getClass()), existingEvent, objectAction, identified,
head, argumentAdapters, resultAdapter);
}
@@ -107,7 +107,7 @@ public class DomainEventHelper {
final InteractionHead head,
final Can<ManagedObject> argumentAdapters,
final ManagedObject resultAdapter) {
-
+
_Assert.assertTypeIsInstanceOf(eventType, ActionDomainEvent.class);
try {
@@ -166,7 +166,7 @@ public class DomainEventHelper {
final Class<? extends ActionDomainEvent<S>> type,
final Identifier identifier,
final S source,
- final Object... arguments)
+ final Object... arguments)
throws IllegalArgumentException,
NoSuchMethodException, SecurityException {
@@ -174,19 +174,19 @@ public class DomainEventHelper {
val noArgConstructor = constructors.filter(paramCount(0)).getFirst().orElse(null);
if(noArgConstructor!=null) {
-
+
final Object event = invokeConstructor(noArgConstructor);
final ActionDomainEvent<S> ade = uncheckedCast(event);
-
+
ade.initSource(source);
ade.setIdentifier(identifier);
ade.setArguments(asList(arguments));
return ade;
}
-
+
// else
-
+
val updateEventConstructor = constructors
.filter(paramCount(3)
.and(paramAssignableFrom(0, source.getClass()))
@@ -195,12 +195,12 @@ public class DomainEventHelper {
)
.getFirst()
.orElse(null);
-
+
if(updateEventConstructor!=null) {
val event = invokeConstructor(updateEventConstructor, source, identifier, arguments);
- return uncheckedCast(event);
+ return uncheckedCast(event);
}
-
+
throw new NoSuchMethodException(type.getName()+".<init>(? super " + source.getClass().getName() + ", " + Identifier.class.getName() + ", [Ljava.lang.Object;)");
}
@@ -221,7 +221,7 @@ public class DomainEventHelper {
final InteractionHead head,
final T oldValue,
final T newValue) {
-
+
_Assert.assertTypeIsInstanceOf(eventType, PropertyDomainEvent.class);
try {
@@ -232,10 +232,10 @@ public class DomainEventHelper {
event = existingEvent;
} else {
// all other phases, create a new event
-
+
final S source = uncheckedCast(UnwrapUtil.single(head.getTarget()));
final Identifier identifier = identified.getIdentifier();
-
+
event = newPropertyDomainEvent(eventType, identifier, source, oldValue, newValue);
// copy over if have
@@ -271,7 +271,7 @@ public class DomainEventHelper {
val constructors = _Reflect.getPublicConstructors(type);
val noArgConstructors = constructors.filter(paramCount(0));
-
+
for (val constructor : noArgConstructors) {
final Object event = invokeConstructor(constructor);
final PropertyDomainEvent<S, T> pde = uncheckedCast(event);
@@ -292,7 +292,7 @@ public class DomainEventHelper {
.and(paramAssignableFromValue(2, oldValue))
.and(paramAssignableFromValue(3, newValue))
);
-
+
for (val constructor : updateEventConstructors) {
val event = invokeConstructor(constructor, source, identifier, oldValue, newValue);
return uncheckedCast(event);
@@ -308,14 +308,13 @@ public class DomainEventHelper {
public <S, T> CollectionDomainEvent<S, T> postEventForCollection(
AbstractDomainEvent.Phase phase,
final Class<? extends CollectionDomainEvent<S, T>> eventType,
- final CollectionDomainEvent<S, T> existingEvent,
- final IdentifiedHolder identified,
- final InteractionHead head,
- final CollectionDomainEvent.Of of,
- final T reference) {
-
+ final CollectionDomainEvent<S, T> existingEvent,
+ final IdentifiedHolder identified,
+ final InteractionHead head,
+ final T reference) {
+
_Assert.assertTypeIsInstanceOf(eventType, CollectionDomainEvent.class);
-
+
try {
final CollectionDomainEvent<S, T> event;
if (existingEvent != null && phase.isExecuted()) {
@@ -325,7 +324,7 @@ public class DomainEventHelper {
// all other phases, create a new event
final S source = uncheckedCast(UnwrapUtil.single(head.getTarget()));
final Identifier identifier = identified.getIdentifier();
- event = newCollectionDomainEvent(eventType, phase, identifier, source, of, reference);
+ event = newCollectionDomainEvent(eventType, phase, identifier, source, reference);
// copy over if have
head.getMixedIn()
@@ -344,72 +343,49 @@ public class DomainEventHelper {
<S, T> CollectionDomainEvent<S, T> newCollectionDomainEvent(
final Class<? extends CollectionDomainEvent<S, T>> type,
- final AbstractDomainEvent.Phase phase,
- final Identifier identifier,
- final S source,
- final CollectionDomainEvent.Of of,
- final T value)
- throws NoSuchMethodException, SecurityException, InstantiationException,
- IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+ final AbstractDomainEvent.Phase phase,
+ final Identifier identifier,
+ final S source,
+ final T value)
+ throws NoSuchMethodException, SecurityException,
+ IllegalArgumentException {
val constructors = _Reflect.getPublicConstructors(type);
val noArgConstructors = constructors.filter(paramCount(0));
-
+
for (val constructor : noArgConstructors) {
final Object event = invokeConstructor(constructor);
final CollectionDomainEvent<S, T> cde = uncheckedCast(event);
cde.initSource(source);
cde.setIdentifier(identifier);
- cde.setOf(of);
cde.setValue(value);
return cde;
}
-
+
// else
// search for constructor accepting source, identifier, type, value
val updateEventConstructors = constructors
.filter(paramCount(4)
.and(paramAssignableFrom(0, source.getClass()))
.and(paramAssignableFrom(1, Identifier.class))
- .and(paramAssignableFrom(2, CollectionDomainEvent.Of.class))
- .and(paramAssignableFromValue(3, value))
+ .and(paramAssignableFromValue(2, value))
);
-
+
for (val constructor : updateEventConstructors) {
- val event = invokeConstructor(constructor, source, identifier, of, value);
+ val event = invokeConstructor(constructor, source, identifier, value);
return uncheckedCast(event);
}
-
- // else
- if(phase == AbstractDomainEvent.Phase.EXECUTED) {
- if(of == CollectionDomainEvent.Of.ADD_TO
- || of == CollectionDomainEvent.Of.REMOVE_FROM) {
- // support for annotations @PostsCollectionAddedTo and @PostsCollectionRemovedFrom:
- // search for constructor accepting source, identifier, value
- val eventConstructors = constructors
- .filter(paramCount(3)
- .and(paramAssignableFrom(0, source.getClass()))
- .and(paramAssignableFrom(1, Identifier.class))
- .and(paramAssignableFromValue(2, value))
- );
- for (val constructor : eventConstructors) {
- val event = invokeConstructor(constructor, source, identifier, value);
- return uncheckedCast(event);
- }
- }
- }
-
// else
throw new NoSuchMethodException(type.getName()+".<init>(? super " + source.getClass().getName() + ", " + Identifier.class.getName() + ", java.lang.Object)");
}
private static <T> T invokeConstructor(
- @NonNull final Constructor<T> constructor,
+ @NonNull final Constructor<T> constructor,
final Object... args){
-
+
try {
return constructor.newInstance(args);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException
@@ -418,6 +394,6 @@ public class DomainEventHelper {
"failed to invoke constructor %s", constructor, e);
}
}
-
+
}
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/collections/collection/modify/CollectionDomainEventFacetAbstract.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/collections/collection/modify/CollectionDomainEventFacetAbstract.java
index d63ec04..e400f70 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/collections/collection/modify/CollectionDomainEventFacetAbstract.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/collections/collection/modify/CollectionDomainEventFacetAbstract.java
@@ -76,7 +76,6 @@ public abstract class CollectionDomainEventFacetAbstract
AbstractDomainEvent.Phase.HIDE,
getEventType(), null,
getIdentified(), ic.getHead(),
- CollectionDomainEvent.Of.ACCESS,
null);
if (event != null && event.isHidden()) {
return "Hidden by subscriber";
@@ -92,7 +91,6 @@ public abstract class CollectionDomainEventFacetAbstract
AbstractDomainEvent.Phase.DISABLE,
getEventType(), null,
getIdentified(), ic.getHead(),
- CollectionDomainEvent.Of.ACCESS,
null);
if (event != null && event.isDisabled()) {
final TranslatableString reasonTranslatable = event.getDisabledReasonTranslatable();
diff --git a/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/DomainEventHelperTest_newCollectionDomainEvent_forAdd.java b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/DomainEventHelperTest_newCollectionDomainEvent_forAdd.java
index d586a41..5ae89a1 100644
--- a/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/DomainEventHelperTest_newCollectionDomainEvent_forAdd.java
+++ b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/DomainEventHelperTest_newCollectionDomainEvent_forAdd.java
@@ -48,7 +48,7 @@ public class DomainEventHelperTest_newCollectionDomainEvent_forAdd {
LogicalType.fqcn(SomeDomainObject.class), "references");
final CollectionDomainEvent<Object, Object> ev = Utils.domainEventHelper().newCollectionDomainEvent(
- CollectionDomainEvent.Default.class, null, identifier, sdo, CollectionDomainEvent.Of.ADD_TO, other);
+ CollectionDomainEvent.Default.class, null, identifier, sdo, other);
assertSame(ev.getSource(), sdo);
assertThat(ev.getIdentifier(), is(identifier));
assertThat(ev.getOf(), is(CollectionDomainEvent.Of.ADD_TO));
@@ -63,7 +63,7 @@ public class DomainEventHelperTest_newCollectionDomainEvent_forAdd {
LogicalType.fqcn(SomeDomainObject.class), "references");
final CollectionDomainEvent<Object, Object> ev = Utils.domainEventHelper().newCollectionDomainEvent(
- CollectionDomainEvent.Default.class, AbstractDomainEvent.Phase.EXECUTED, identifier, sdo, CollectionDomainEvent.Of.ADD_TO, other);
+ CollectionDomainEvent.Default.class, AbstractDomainEvent.Phase.EXECUTED, identifier, sdo, other);
assertSame(ev.getSource(), sdo);
assertThat(ev.getIdentifier(), is(identifier));
assertThat(ev.getOf(), is(CollectionDomainEvent.Of.ADD_TO));
@@ -78,7 +78,7 @@ public class DomainEventHelperTest_newCollectionDomainEvent_forAdd {
LogicalType.fqcn(SomeDomainObject.class), "references");
final CollectionDomainEvent<SomeDomainObject, SomeReferencedObject> ev = Utils.domainEventHelper().newCollectionDomainEvent(
- SomeDomainObjectCollectionDomainEvent.class, AbstractDomainEvent.Phase.EXECUTED, identifier, sdo, CollectionDomainEvent.Of.ADD_TO, other);
+ SomeDomainObjectCollectionDomainEvent.class, AbstractDomainEvent.Phase.EXECUTED, identifier, sdo, other);
assertThat(ev.getSource(), is(sdo));
assertThat(ev.getIdentifier(), is(identifier));
assertThat(ev.getOf(), is(CollectionDomainEvent.Of.ADD_TO));
diff --git a/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/DomainEventHelperTest_newCollectionDomainEvent_forRemove.java b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/DomainEventHelperTest_newCollectionDomainEvent_forRemove.java
index b07c9e2..dc2c6d0 100644
--- a/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/DomainEventHelperTest_newCollectionDomainEvent_forRemove.java
+++ b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/DomainEventHelperTest_newCollectionDomainEvent_forRemove.java
@@ -48,7 +48,7 @@ public class DomainEventHelperTest_newCollectionDomainEvent_forRemove {
LogicalType.fqcn(SomeDomainObject.class), "references");
final CollectionDomainEvent<Object, Object> ev = Utils.domainEventHelper().newCollectionDomainEvent(
- CollectionDomainEvent.Default.class, AbstractDomainEvent.Phase.EXECUTED, identifier, sdo, CollectionDomainEvent.Of.REMOVE_FROM, other);
+ CollectionDomainEvent.Default.class, AbstractDomainEvent.Phase.EXECUTED, identifier, sdo, other);
assertSame(ev.getSource(), sdo);
assertThat(ev.getIdentifier(), is(identifier));
assertThat(ev.getOf(), is(CollectionDomainEvent.Of.REMOVE_FROM));
@@ -63,7 +63,7 @@ public class DomainEventHelperTest_newCollectionDomainEvent_forRemove {
LogicalType.fqcn(SomeDomainObject.class), "references");
final CollectionDomainEvent<Object, Object> ev = Utils.domainEventHelper().newCollectionDomainEvent(
- CollectionDomainEvent.Default.class, AbstractDomainEvent.Phase.EXECUTED, identifier, sdo, CollectionDomainEvent.Of.REMOVE_FROM, other);
+ CollectionDomainEvent.Default.class, AbstractDomainEvent.Phase.EXECUTED, identifier, sdo, other);
assertSame(ev.getSource(), sdo);
assertThat(ev.getIdentifier(), is(identifier));
assertThat(ev.getOf(), is(CollectionDomainEvent.Of.REMOVE_FROM));
@@ -78,7 +78,7 @@ public class DomainEventHelperTest_newCollectionDomainEvent_forRemove {
LogicalType.fqcn(SomeDomainObject.class), "references");
final CollectionDomainEvent<SomeDomainObject, SomeReferencedObject> ev = Utils.domainEventHelper().newCollectionDomainEvent(
- SomeDomainObjectCollectionRemovedFromDomainEvent.class, AbstractDomainEvent.Phase.EXECUTED, identifier, sdo, CollectionDomainEvent.Of.REMOVE_FROM, other);
+ SomeDomainObjectCollectionRemovedFromDomainEvent.class, AbstractDomainEvent.Phase.EXECUTED, identifier, sdo, other);
assertThat(ev.getSource(), is(sdo));
assertThat(ev.getIdentifier(), is(identifier));
assertThat(ev.getOf(), is(CollectionDomainEvent.Of.REMOVE_FROM));