11package io .papermc .asm .rules .builder .matcher .method ;
22
3+ import io .papermc .asm .rules .builder .matcher .method .targeted .MethodMatcherPredicate ;
34import java .lang .constant .MethodTypeDesc ;
5+ import java .util .Collection ;
6+ import java .util .Set ;
47import java .util .function .Consumer ;
58import java .util .function .Predicate ;
9+ import org .jetbrains .annotations .Unmodifiable ;
610
7- @ FunctionalInterface
8- public interface MethodMatcher {
11+ import static io .papermc .asm .util .DescriptorUtils .methodDesc ;
12+
13+ public interface MethodMatcher extends MethodMatcherPredicate {
914
1015 static MethodMatcherBuilder builder () {
1116 return new MethodMatcherBuilderImpl ();
1217 }
1318
19+ static MethodMatcher falseMatcher () {
20+ return MethodMatcherImpl .FALSE ;
21+ }
22+
1423 static MethodMatcher single (final String name , final Consumer <MethodMatcherBuilder .MatchBuilder > matchBuilderConsumer ) {
1524 return builder ().match (name , matchBuilderConsumer ).build ();
1625 }
1726
18- boolean matches (int opcode , boolean isInvokeDynamic , String name , String descriptor );
27+ static MethodMatcher create (final Collection <String > methodNames , final Predicate <? super MethodTypeDesc > bytecodeDescPredicate ) {
28+ return new MethodMatcherImpl (methodNames , bytecodeDescPredicate , (opcode , isInvokeDynamic ) -> true );
29+ }
30+
31+ static MethodMatcher create (final Collection <String > methodNames , final Predicate <? super MethodTypeDesc > bytecodeDescPredicate , final OpcodePredicate opcodePredicate ) {
32+ return new MethodMatcherImpl (methodNames , bytecodeDescPredicate , opcodePredicate );
33+ }
1934
20- default boolean matches (final int opcode , final boolean isInvokeDynamic , final String name , final MethodTypeDesc descriptor ) {
21- return this .matches (opcode , isInvokeDynamic , name , descriptor . descriptorString ( ));
35+ default boolean matches (final String name , final String descriptor ) {
36+ return this .matches (name , methodDesc ( descriptor ));
2237 }
2338
39+ boolean matches (String name , MethodTypeDesc descriptor );
40+
41+ @ Override
42+ default boolean matches (final int opcode , final boolean isInvokeDynamic , final String name , final String descriptor ) {
43+ return this .matches (opcode , isInvokeDynamic , name , methodDesc (descriptor ));
44+ }
45+
46+ boolean matches (int opcode , boolean isInvokeDynamic , String name , MethodTypeDesc descriptor );
47+
48+ @ Unmodifiable Set <String > methodNames ();
49+
50+ Predicate <? super MethodTypeDesc > bytecodeDescPredicate ();
51+
52+ OpcodePredicate opcodePredicate ();
53+
2454 /**
2555 * Creates a method matcher that matches if either matcher passes.
2656 *
2757 * @param other the other matcher
2858 * @return a new "or" matcher
2959 */
30- default MethodMatcher or (final MethodMatcher other ) {
31- return (opcode , isInvokeDynamic , name , descriptor ) -> this .matches (opcode , isInvokeDynamic , name , descriptor ) || other .matches (opcode , isInvokeDynamic , name , descriptor );
32- }
60+ MethodMatcher or (final MethodMatcher other );
3361
3462 /**
3563 * Creates a method matcher that matches if both matcher pass.
@@ -38,9 +66,7 @@ default MethodMatcher or(final MethodMatcher other) {
3866 * @return a new "and" matcher
3967 * @see #and(Predicate)
4068 */
41- default MethodMatcher and (final MethodMatcher other ) {
42- return (opcode , isInvokeDynamic , name , descriptor ) -> this .matches (opcode , isInvokeDynamic , name , descriptor ) && other .matches (opcode , isInvokeDynamic , name , descriptor );
43- }
69+ MethodMatcher and (final MethodMatcher other );
4470
4571 /**
4672 * Creates a method matcher tha matches if both this matcher
@@ -49,16 +75,5 @@ default MethodMatcher and(final MethodMatcher other) {
4975 * @param descPredicate the method descriptor predicate
5076 * @return a new "and" matcher
5177 */
52- default MethodMatcher and (final Predicate <? super MethodTypeDesc > descPredicate ) {
53- return (opcode , isInvokeDynamic , name , descriptor ) -> this .matches (opcode , isInvokeDynamic , name , descriptor ) && descPredicate .test (MethodTypeDesc .ofDescriptor (descriptor ));
54- }
55-
56- /**
57- * Creates a method matcher that is the inverse of this matcher.
58- *
59- * @return the inverse matcher
60- */
61- default MethodMatcher negate () {
62- return (opcode , isInvokeDynamic , name , descriptor ) -> !this .matches (opcode , isInvokeDynamic , name , descriptor );
63- }
78+ MethodMatcher and (final Predicate <? super MethodTypeDesc > descPredicate );
6479}
0 commit comments