-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
acddd00
commit eaea479
Showing
4 changed files
with
53 additions
and
50 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
23 changes: 2 additions & 21 deletions
23
...in/java/tech/picnic/errorprone/refaster/matchers/IsLambdaExpressionOrMethodReference.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,39 +1,20 @@ | ||
package tech.picnic.errorprone.refaster.matchers; | ||
|
||
import static com.google.errorprone.matchers.Matchers.anyOf; | ||
import static com.sun.source.tree.MemberReferenceTree.ReferenceMode.INVOKE; | ||
|
||
import com.google.errorprone.VisitorState; | ||
import com.google.errorprone.matchers.Matcher; | ||
import com.sun.source.tree.ExpressionTree; | ||
import com.sun.source.tree.LambdaExpressionTree; | ||
import com.sun.source.tree.MemberReferenceTree; | ||
import com.sun.source.tree.Tree; | ||
|
||
/** A matcher of lambda expressions or method references. */ | ||
/** A matcher of lambda expressions and method references. */ | ||
public final class IsLambdaExpressionOrMethodReference implements Matcher<ExpressionTree> { | ||
private static final long serialVersionUID = 1L; | ||
|
||
private static final Matcher<ExpressionTree> DELEGATE = | ||
anyOf(isLambdaExpression(), isMethodReference()); | ||
|
||
/** Instantiates a new {@link IsLambdaExpressionOrMethodReference} instance. */ | ||
public IsLambdaExpressionOrMethodReference() {} | ||
|
||
@Override | ||
public boolean matches(ExpressionTree tree, VisitorState state) { | ||
return DELEGATE.matches(tree, state); | ||
} | ||
|
||
/** Returns a matcher that matches lambda expressions. */ | ||
public static <T extends Tree> Matcher<T> isLambdaExpression() { | ||
return (tree, state) -> tree instanceof LambdaExpressionTree; | ||
} | ||
|
||
/** Returns a matcher that matches method references. */ | ||
public static <T extends Tree> Matcher<T> isMethodReference() { | ||
return (tree, state) -> | ||
tree instanceof MemberReferenceTree | ||
&& ((MemberReferenceTree) tree).getMode().equals(INVOKE); | ||
return tree instanceof LambdaExpressionTree || tree instanceof MemberReferenceTree; | ||
} | ||
} |
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