@@ -754,48 +754,41 @@ private <S> void triggerCascade(Reference<S> effectiveScope, @Nullable R priorRo
754754 action .accept (effectiveScope );
755755 }
756756 } else {
757- try {
758- // There's at least one parameter that hasn't been bound yet. This means
759- // we need to locate all the matching objects that may have changed.
760- // We do so by filling in the first parameter with all possible values that
761- // could correspond to changed objects and then recursing.
762- //
763- Path containerPath = effectiveScope .path ().truncatedTo (effectiveScope .path ().firstParameterIndex ());
764- Reference <EnumerableByIdentifier <?>> containerRef = rootReference ().then (enumerableByIdentifierClass (), containerPath );
765- EnumerableByIdentifier <?> priorContainer = refValueIfExists (containerRef , priorRoot );
766- EnumerableByIdentifier <?> newContainer = refValueIfExists (containerRef , newRoot );
757+ // There's at least one parameter that hasn't been bound yet. This means
758+ // we need to locate all the matching objects that may have changed.
759+ // We do so by filling in the first parameter with all possible values that
760+ // could correspond to changed objects and then recursing.
761+ //
762+ Reference <EnumerableByIdentifier <?>> containerRef = effectiveScope .truncatedBeforeFirstParameter ();
763+ EnumerableByIdentifier <?> priorContainer = refValueIfExists (containerRef , priorRoot );
764+ EnumerableByIdentifier <?> newContainer = refValueIfExists (containerRef , newRoot );
767765
768- // TODO: If priorContainer == newContainer, can we stop immediately?
766+ // TODO: If priorContainer == newContainer, can we stop immediately?
769767
770- // Process any deleted items first. This can allow the hook to free some memory
771- // that can be used by subsequent hooks.
772- // We do them in reverse order just because that's likely to be the preferred
773- // order for cleanup activities.
774- //
775- // TODO: Should we actually process the hooks themselves in reverse order for the same reason?
776- //
777- if (priorContainer != null ) {
778- List <Identifier > priorIDs = priorContainer .ids ();
779- for (Identifier id : priorIDs .reversed ()) {
780- if (newContainer == null || newContainer .get (id ) == null ) {
781- triggerCascade (effectiveScope .boundTo (id ), priorRoot , newRoot , action );
782- }
768+ // Process any deleted items first. This can allow the hook to free some memory
769+ // that can be used by subsequent hooks.
770+ // We do them in reverse order just because that's likely to be the preferred
771+ // order for cleanup activities.
772+ //
773+ // TODO: Should we actually process the hooks themselves in reverse order for the same reason?
774+ //
775+ if (priorContainer != null ) {
776+ List <Identifier > priorIDs = priorContainer .ids ();
777+ for (Identifier id : priorIDs .reversed ()) {
778+ if (newContainer == null || newContainer .get (id ) == null ) {
779+ triggerCascade (effectiveScope .boundTo (id ), priorRoot , newRoot , action );
783780 }
784781 }
782+ }
785783
786- // Then process updated items
787- //
788- if (newContainer != null ) {
789- for (Identifier id : newContainer .ids ()) {
790- if (priorContainer == null || priorContainer .get (id ) != newContainer .get (id )) {
791- triggerCascade (effectiveScope .boundTo (id ), priorRoot , newRoot , action );
792- }
784+ // Then process updated items
785+ //
786+ if (newContainer != null ) {
787+ for (Identifier id : newContainer .ids ()) {
788+ if (priorContainer == null || priorContainer .get (id ) != newContainer .get (id )) {
789+ triggerCascade (effectiveScope .boundTo (id ), priorRoot , newRoot , action );
793790 }
794791 }
795- } catch (InvalidTypeException e ) {
796- // TODO: Add truncation methods to Reference so we can refactor this to create
797- // the container reference without risking an InvalidTypeException
798- throw new AssertionError ("Parameterized reference must be truncatable at the location of the parameter" , e );
799792 }
800793 }
801794 }
0 commit comments