@@ -54,19 +54,19 @@ public interface ActionParser<T> {
5454
5555 /**
5656 * Evaluates the matcher against the provided data.
57- * Returns the action config if matched, null otherwise.
57+ * Returns the action configs if matched, null otherwise.
5858 */
5959 @ Nullable
60- public abstract T match (MatchingData data );
60+ public abstract List < T > match (MatchingData data );
6161
6262 public static <T > UnifiedMatcher <T > create (Matcher proto , ActionParser <T > parser ) {
6363 return createRecursive (proto , parser , 0 );
6464 }
6565
6666 private static <T > UnifiedMatcher <T > createRecursive (Matcher proto , ActionParser <T > parser ,
6767 int depth ) {
68- if (depth > 8 ) {
69- throw new IllegalArgumentException ("Maximum recursion depth of 8 exceeded" );
68+ if (depth > 16 ) {
69+ throw new IllegalArgumentException ("Maximum recursion depth of 16 exceeded" );
7070 }
7171 if (proto .hasMatcherList ()) {
7272 return new MatcherList <>(proto .getMatcherList (), parser , depth );
@@ -91,7 +91,7 @@ private static class OnNoMatch<T> extends UnifiedMatcher<T> {
9191 }
9292
9393 @ Override
94- public T match (MatchingData data ) {
94+ public List < T > match (MatchingData data ) {
9595 return delegate != null ? delegate .match (data ) : null ;
9696 }
9797 }
@@ -104,8 +104,8 @@ private static class ActionMatcher<T> extends UnifiedMatcher<T> {
104104 }
105105
106106 @ Override
107- public T match (MatchingData data ) {
108- return action ;
107+ public List < T > match (MatchingData data ) {
108+ return ImmutableList . of ( action ) ;
109109 }
110110 }
111111
@@ -121,24 +121,30 @@ private static class MatcherList<T> extends UnifiedMatcher<T> {
121121 }
122122
123123 @ Override
124- public T match (MatchingData data ) {
124+ public List <T > match (MatchingData data ) {
125+ List <T > results = new ArrayList <>();
125126 for (FieldMatcher <T > matcher : fieldMatchers ) {
126- T result = matcher .match (data );
127- if (result != null ) {
128- return result ;
127+ List <T > result = matcher .match (data );
128+ if (result != null && !result .isEmpty ()) {
129+ results .addAll (result );
130+ if (!matcher .keepMatching ) {
131+ break ;
132+ }
129133 }
130134 }
131- return null ;
135+ return results . isEmpty () ? null : ImmutableList . copyOf ( results ) ;
132136 }
133137 }
134138
135139 private static class FieldMatcher <T > {
136140 private final UnifiedPredicate predicate ;
137141 private final UnifiedMatcher <T > onMatch ;
142+ private final boolean keepMatching ;
138143
139144 FieldMatcher (Matcher .MatcherList .FieldMatcher proto , ActionParser <T > parser , int depth ) {
140145 this .predicate = UnifiedPredicate .create (proto .getPredicate ());
141146 Matcher .OnMatch onMatchProto = proto .getOnMatch ();
147+ this .keepMatching = onMatchProto .getKeepMatching ();
142148 if (onMatchProto .hasAction ()) {
143149 this .onMatch = new ActionMatcher <>(onMatchProto .getAction (), parser );
144150 } else if (onMatchProto .hasMatcher ()) {
@@ -149,7 +155,7 @@ private static class FieldMatcher<T> {
149155 }
150156
151157 @ Nullable
152- T match (MatchingData data ) {
158+ List < T > match (MatchingData data ) {
153159 if (predicate .matches (data )) {
154160 return onMatch .match (data );
155161 }
@@ -164,6 +170,9 @@ private static class MatcherTree<T> extends UnifiedMatcher<T> {
164170
165171 MatcherTree (Matcher .MatcherTree proto , ActionParser <T > parser , int depth ) {
166172 this .input = new MatcherInput (proto .getInput ());
173+ if (proto .hasCustomMatch ()) {
174+ throw new IllegalArgumentException ("custom_match is not supported in MatcherTree" );
175+ }
167176 this .exactMap = parseMap (proto .getExactMatchMap ().getMapMap (), parser , depth );
168177 this .prefixMap = parseMap (proto .getPrefixMatchMap ().getMapMap (), parser , depth );
169178 }
@@ -183,7 +192,7 @@ private Map<String, UnifiedMatcher<T>> parseMap(
183192 }
184193
185194 @ Override
186- public T match (MatchingData data ) {
195+ public List < T > match (MatchingData data ) {
187196 String value = input .get (data );
188197 if (value == null ) {
189198 return null ;
@@ -225,7 +234,7 @@ String get(MatchingData data) {
225234
226235 private static class AlwaysFalseMatcher <T > extends UnifiedMatcher <T > {
227236 @ Override
228- public T match (MatchingData data ) {
237+ public List < T > match (MatchingData data ) {
229238 return null ;
230239 }
231240 }
@@ -260,6 +269,9 @@ private static class SinglePredicate extends UnifiedPredicate {
260269
261270 SinglePredicate (Predicate .SinglePredicate proto ) {
262271 this .input = new MatcherInput (proto .getInput ());
272+ if (proto .hasCustomMatch ()) {
273+ throw new IllegalArgumentException ("custom_match is not supported in SinglePredicate" );
274+ }
263275 if (proto .hasValueMatch ()) {
264276 this .stringMatcher = MatcherParser .parseStringMatcher (proto .getValueMatch ());
265277 } else {
0 commit comments