-
-
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.
add more utility methods/functionality
mainly just qol stuff I found when re-implementing Commodore
- Loading branch information
1 parent
578117b
commit faa3e98
Showing
20 changed files
with
169 additions
and
82 deletions.
There are no files selected for viewing
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
47 changes: 6 additions & 41 deletions
47
src/main/java/io/papermc/asm/rules/builder/matcher/field/FieldMatcher.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,51 +1,16 @@ | ||
package io.papermc.asm.rules.builder.matcher.field; | ||
|
||
import java.lang.constant.ClassDesc; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.function.Predicate; | ||
|
||
import static java.util.function.Predicate.isEqual; | ||
|
||
@FunctionalInterface | ||
public interface FieldMatcher { | ||
|
||
boolean matchesName(String name); | ||
static FieldMatcherBuilderImpl builder() { | ||
return new FieldMatcherBuilderImpl(); | ||
} | ||
|
||
boolean matches(String name, String descriptor); | ||
|
||
static Builder builder() { | ||
return new Builder(); | ||
default FieldMatcher or(final FieldMatcher other) { | ||
return (name, descriptor) -> this.matches(name, descriptor) || other.matches(name, descriptor); | ||
} | ||
|
||
final class Builder implements io.papermc.asm.util.Builder<FieldMatcher> { | ||
|
||
private Predicate<String> byName = $ -> false; | ||
private Predicate<? super ClassDesc> byType = $ -> true; | ||
|
||
private Builder() { | ||
} | ||
|
||
public Builder names(final String... names) { | ||
return this.names(List.of(names)); | ||
} | ||
|
||
public Builder names(final Collection<String> names) { | ||
this.byName = this.byName.or(names::contains); | ||
return this; | ||
} | ||
|
||
public Builder desc(final ClassDesc desc) { | ||
return this.desc(isEqual(desc)); | ||
} | ||
|
||
public Builder desc(final Predicate<? super ClassDesc> predicate) { | ||
this.byType = predicate; | ||
return this; | ||
} | ||
|
||
@Override | ||
public FieldMatcher build() { | ||
return new FieldMatcherImpl(this.byName, this.byType); | ||
} | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/main/java/io/papermc/asm/rules/builder/matcher/field/FieldMatcherBuilder.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,47 @@ | ||
package io.papermc.asm.rules.builder.matcher.field; | ||
|
||
import io.papermc.asm.util.Builder; | ||
import java.lang.constant.ClassDesc; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.function.Predicate; | ||
|
||
import static java.util.function.Predicate.isEqual; | ||
|
||
public interface FieldMatcherBuilder extends Builder<FieldMatcher> { | ||
|
||
default FieldMatcherBuilder match(final String fieldName) { | ||
return this.match(fieldName, $ -> true); | ||
} | ||
|
||
default FieldMatcherBuilder match(final String fieldName, final ClassDesc fieldDesc) { | ||
return this.match(fieldName, isEqual(fieldDesc)); | ||
} | ||
|
||
default FieldMatcherBuilder match(final String fieldName, final Predicate<ClassDesc> fieldDescPredicate) { | ||
return this.match(isEqual(fieldName), fieldDescPredicate); | ||
} | ||
|
||
default FieldMatcherBuilder match(final Collection<String> fieldNames) { | ||
return this.match(fieldNames, $ -> true); | ||
} | ||
|
||
default FieldMatcherBuilder match(final Collection<String> fieldNames, final ClassDesc fieldDesc) { | ||
return this.match(fieldNames, isEqual(fieldDesc)); | ||
} | ||
|
||
default FieldMatcherBuilder match(final Collection<String> fieldNames, final Predicate<ClassDesc> fieldDescPredicate) { | ||
final List<String> copy = List.copyOf(fieldNames); | ||
return this.match(copy::contains, fieldDescPredicate); | ||
} | ||
|
||
default FieldMatcherBuilder match(final Predicate<String> fieldNamePredicate) { | ||
return this.match(fieldNamePredicate, $ -> true); | ||
} | ||
|
||
default FieldMatcherBuilder match(final Predicate<String> fieldNamePredicate, final ClassDesc fieldDesc) { | ||
return this.match(fieldNamePredicate, isEqual(fieldDesc)); | ||
} | ||
|
||
FieldMatcherBuilder match(Predicate<String> fieldNamePredicate, Predicate<ClassDesc> fieldDescPredicate); | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/io/papermc/asm/rules/builder/matcher/field/FieldMatcherBuilderImpl.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,23 @@ | ||
package io.papermc.asm.rules.builder.matcher.field; | ||
|
||
import java.lang.constant.ClassDesc; | ||
import java.util.function.Predicate; | ||
|
||
public final class FieldMatcherBuilderImpl implements FieldMatcherBuilder { | ||
|
||
private FieldMatcher matcher = (name, descriptor) -> false; | ||
|
||
FieldMatcherBuilderImpl() { | ||
} | ||
|
||
@Override | ||
public FieldMatcherBuilder match(final Predicate<String> fieldNamePredicate, final Predicate<ClassDesc> fieldDescPredicate) { | ||
this.matcher = this.matcher.or((name, descriptor) -> fieldNamePredicate.test(name) && fieldDescPredicate.test(ClassDesc.ofDescriptor(descriptor))); | ||
return this; | ||
} | ||
|
||
@Override | ||
public FieldMatcher build() { | ||
return this.matcher; | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.