From c7c33b133002b8adacdcfd10a9df196ea2b648a8 Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 9 May 2024 10:25:49 -0700 Subject: [PATCH] Add visitor pattern for transition factories. Part of #22248. PiperOrigin-RevId: 632193752 Change-Id: Ic41afbc4ec508ad08615a8861278d5593bb73849 --- .../config/transitions/ComposingTransitionFactory.java | 6 ++++++ .../analysis/config/transitions/TransitionFactory.java | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/main/java/com/google/devtools/build/lib/analysis/config/transitions/ComposingTransitionFactory.java b/src/main/java/com/google/devtools/build/lib/analysis/config/transitions/ComposingTransitionFactory.java index 74c9cf100320f5..055ea54c5b1b21 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/config/transitions/ComposingTransitionFactory.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/config/transitions/ComposingTransitionFactory.java @@ -100,4 +100,10 @@ public boolean isTool() { public boolean isSplit() { return transitionFactory1().isSplit() || transitionFactory2().isSplit(); } + + @Override + public void visit(Visitor visitor) { + this.transitionFactory1().visit(visitor); + this.transitionFactory2().visit(visitor); + } } diff --git a/src/main/java/com/google/devtools/build/lib/analysis/config/transitions/TransitionFactory.java b/src/main/java/com/google/devtools/build/lib/analysis/config/transitions/TransitionFactory.java index 726dd44931e70a..0d15a9a09c0fd1 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/config/transitions/TransitionFactory.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/config/transitions/TransitionFactory.java @@ -76,4 +76,14 @@ default boolean isTool() { default boolean isSplit() { return false; } + + /** Visit this trnsition factory with the given visitor. */ + default void visit(Visitor visitor) { + visitor.visit(this); + } + + /** Interface used to progressively visit transitions. */ + interface Visitor { + void visit(TransitionFactory factory); + } }