Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -126,25 +126,39 @@ static <T> boolean anyMatch(T[] candidates, Predicate<T> matcher) {
return false;
}

/** Optimized for {@link MethodMatcher#method()} to avoid unnecessary object creation. */
/** Matches all methods, excluding {@code <init>} and {@code <clinit>}. */
static final MethodMatcher ALL_METHODS =
new MethodMatcher() {
@Override
public boolean test(MethodOutline outline) {
return true;
return outline.methodName.charAt(0) != '<';
}

@Override
public MethodMatcher and(MethodMatcher other) {
return other; // no need for MethodConjunction
}

@Override
public MethodMatcher or(MethodMatcher other) {
return this; // no need for MethodDisjunction
return new RegularMethod(other); // make it easier to inline name check
}
};

/** Matches regular methods that also match the given matcher. */
static final class RegularMethod implements MethodMatcher {
private final MethodMatcher matcher;

RegularMethod(MethodMatcher matcher) {
this.matcher = matcher;
}

@Override
public boolean test(MethodOutline outline) {
return outline.methodName.charAt(0) != '<' && matcher.test(outline);
}

@Override
public MethodMatcher and(MethodMatcher other) {
return new RegularMethod(matcher.and(other));
}
}

/** Logical AND of two {@link ClassMatcher}s; nested conjunctions will be collapsed. */
static final class ClassConjunction extends MatcherUnion<ClassMatcher> implements ClassMatcher {
ClassConjunction(ClassMatcher lhs, ClassMatcher rhs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
public interface MethodMatcher extends Predicate<MethodOutline> {

/**
* Matches all methods.
* Matches all methods, excluding constructors and static initializers.
*
* @return matcher of all methods
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,19 @@ void namesSpecialMethodsAndAccess() {
assertMatches(staticInitializer(), clinit, true);
assertMatches(constructor(), clinit, false);
assertMatches(staticInitializer(), init, false);
assertMatches(method(), init, true);
assertMatches(method(), clinit, true);
assertMatches(method(), ordinary, true);
assertMatches(method(), init, false);
assertMatches(method(), clinit, false);
assertMatches(method().noParameters(), init, false);
assertMatches(method().noParameters(), clinit, false);
assertMatches(method().and(constructor()), init, false);
assertMatches(method().or(constructor()), init, true);
assertMatches(method().or(constructor()), clinit, false);
assertMatches(method().or(staticInitializer()), clinit, true);
assertMatches(method().or(staticInitializer()), init, false);
MethodMatcher unexpected =
m -> {
throw new AssertionError("all methods should short circuit");
throw new AssertionError("ordinary methods should short circuit");
};
assertMatches(method().or(unexpected), ordinary, true);
}
Expand Down
Loading