-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
further improve various builders for clarity
- Loading branch information
1 parent
0acc5a8
commit 2d9f9af
Showing
8 changed files
with
101 additions
and
101 deletions.
There are no files selected for viewing
35 changes: 10 additions & 25 deletions
35
src/main/java/io/papermc/asm/rules/builder/matcher/method/MethodMatcherBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,30 @@ | ||
package io.papermc.asm.rules.builder.matcher.method; | ||
|
||
import io.papermc.asm.util.Builder; | ||
import java.lang.constant.ClassDesc; | ||
import java.lang.constant.MethodTypeDesc; | ||
import java.util.Collection; | ||
import java.util.function.Consumer; | ||
import java.util.function.Predicate; | ||
|
||
public interface MethodMatcherBuilder extends Builder<MethodMatcher> { | ||
public interface MethodMatcherBuilder extends MethodParamMatcherBuilder<MethodMatcherBuilder>, Builder<MethodMatcher> { | ||
|
||
MethodMatcherBuilder ctor(final Consumer<MatchBuilder> matchBuilderConsumer); | ||
|
||
MethodMatcherBuilder match(final String name, final Consumer<MatchBuilder> matchBuilderConsumer); | ||
default MethodMatcherBuilder match(final String name) { | ||
return this.match(name, b -> {}); | ||
} | ||
|
||
MethodMatcherBuilder match(final Collection<String> names, final Consumer<MatchBuilder> matchBuilderConsumer); | ||
MethodMatcherBuilder match(final String name, final Consumer<MatchBuilder> matchBuilderConsumer); | ||
|
||
MethodMatcherBuilder hasParam(final ClassDesc paramClassDesc); | ||
default MethodMatcherBuilder match(final Collection<String> names) { | ||
return this.match(names, b -> {}); | ||
} | ||
|
||
MethodMatcherBuilder hasReturn(final ClassDesc returnClassDesc); | ||
MethodMatcherBuilder match(final Collection<String> names, final Consumer<MatchBuilder> matchBuilderConsumer); | ||
|
||
/** | ||
* Used to match methods with specific names. | ||
* | ||
* @see MethodMatcherBuilder#match(String, Consumer) | ||
*/ | ||
interface MatchBuilder { | ||
|
||
MatchBuilder virtual(); | ||
|
||
MatchBuilder statik(); | ||
|
||
MatchBuilder type(final MethodType... types); | ||
|
||
MatchBuilder hasParam(final ClassDesc paramClassDesc); | ||
|
||
MatchBuilder hasReturn(final ClassDesc returnClassDesc); | ||
|
||
MatchBuilder desc(final String... descriptors); | ||
|
||
MatchBuilder desc(final MethodTypeDesc... descriptors); | ||
|
||
MatchBuilder desc(final Predicate<? super MethodTypeDesc> descPredicate); | ||
interface MatchBuilder extends MethodParamMatcherBuilder<MatchBuilder>, MethodTypeMatcherBuilder<MatchBuilder> { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/main/java/io/papermc/asm/rules/builder/matcher/method/MethodParamMatcherBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.papermc.asm.rules.builder.matcher.method; | ||
|
||
import java.lang.constant.ClassDesc; | ||
import java.lang.constant.MethodTypeDesc; | ||
import java.util.Arrays; | ||
import java.util.function.Predicate; | ||
|
||
public interface MethodParamMatcherBuilder<B> { | ||
|
||
default B hasParam(final ClassDesc paramClassDesc) { | ||
return this.desc(d -> d.parameterList().contains(paramClassDesc)); | ||
} | ||
|
||
default B hasParam(final ClassDesc paramClassDesc, final int paramIdx) { | ||
return this.desc(d -> d.parameterType(paramIdx).equals(paramClassDesc)); | ||
} | ||
|
||
default B hasReturn(final ClassDesc returnClassDesc) { | ||
return this.desc(d -> d.returnType().equals(returnClassDesc)); | ||
} | ||
|
||
default B desc(final String... descriptors) { | ||
return this.desc(desc -> Arrays.stream(descriptors).anyMatch(d -> desc.descriptorString().equals(d))); | ||
} | ||
|
||
default B desc(final MethodTypeDesc... descriptors) { | ||
return this.desc(desc -> Arrays.asList(descriptors).contains(desc)); | ||
} | ||
|
||
B desc(final Predicate<? super MethodTypeDesc> descPredicate); | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/io/papermc/asm/rules/builder/matcher/method/MethodTypeMatcherBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package io.papermc.asm.rules.builder.matcher.method; | ||
|
||
public interface MethodTypeMatcherBuilder<B> { | ||
|
||
default B virtual() { | ||
return this.type(MethodType.VIRTUAL); | ||
} | ||
|
||
default B statik() { | ||
return this.type(MethodType.STATIC); | ||
} | ||
|
||
default B itf() { | ||
return this.type(MethodType.INTERFACE); | ||
} | ||
|
||
B type(final MethodType... types); | ||
} |
25 changes: 14 additions & 11 deletions
25
...va/io/papermc/asm/rules/builder/matcher/method/targeted/TargetedMethodMatcherBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,32 @@ | ||
package io.papermc.asm.rules.builder.matcher.method.targeted; | ||
|
||
import io.papermc.asm.rules.builder.matcher.method.MethodType; | ||
import io.papermc.asm.rules.builder.matcher.method.MethodParamMatcherBuilder; | ||
import io.papermc.asm.rules.builder.matcher.method.MethodTypeMatcherBuilder; | ||
import io.papermc.asm.util.Builder; | ||
import java.lang.constant.ClassDesc; | ||
import java.util.Collection; | ||
import java.util.function.Consumer; | ||
|
||
public interface TargetedMethodMatcherBuilder extends Builder<TargetedMethodMatcher> { | ||
public interface TargetedMethodMatcherBuilder extends MethodParamMatcherBuilder<TargetedMethodMatcherBuilder>, Builder<TargetedMethodMatcher> { | ||
|
||
TargetedMethodMatcherBuilder ctor(); | ||
|
||
TargetedMethodMatcherBuilder match(final String name, final Consumer<MatchBuilder> matchBuilderConsumer); | ||
|
||
TargetedMethodMatcherBuilder match(final Collection<String> names, final Consumer<MatchBuilder> matchBuilderConsumer); | ||
default TargetedMethodMatcherBuilder match(final String name) { | ||
return this.match(name, b -> {}); | ||
} | ||
|
||
TargetedMethodMatcherBuilder hasParam(final ClassDesc paramClassDesc); | ||
TargetedMethodMatcherBuilder match(final String name, final Consumer<MatchBuilder> matchBuilderConsumer); | ||
|
||
TargetedMethodMatcherBuilder hasReturn(final ClassDesc returnClassDesc); | ||
default TargetedMethodMatcherBuilder match(final Collection<String> names) { | ||
return this.match(names, b -> {}); | ||
} | ||
|
||
interface MatchBuilder { | ||
TargetedMethodMatcherBuilder match(final Collection<String> names, final Consumer<MatchBuilder> matchBuilderConsumer); | ||
|
||
MatchBuilder virtual(); | ||
TargetedMethodMatcherBuilder targetParam(final ClassDesc paramClassDesc); | ||
|
||
MatchBuilder statik(); | ||
TargetedMethodMatcherBuilder targetReturn(final ClassDesc returnClassDesc); | ||
|
||
MatchBuilder type(final MethodType... types); | ||
interface MatchBuilder extends MethodParamMatcherBuilder<MatchBuilder>, MethodTypeMatcherBuilder<MatchBuilder> { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters