-
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.
Annotate mapper with @matches(IsLambdaExpressionOrMethodReference.class)
- Loading branch information
1 parent
adc1d2b
commit f6cf53e
Showing
4 changed files
with
62 additions
and
12 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
29 changes: 29 additions & 0 deletions
29
...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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package tech.picnic.errorprone.refaster.matchers; | ||
|
||
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; | ||
|
||
/** A matcher of lambda expressions or method references. */ | ||
public final class IsLambdaExpressionOrMethodReference implements Matcher<ExpressionTree> { | ||
private static final long serialVersionUID = 1L; | ||
|
||
/** Instantiates a new {@link IsLambdaExpressionOrMethodReference} instance. */ | ||
public IsLambdaExpressionOrMethodReference() {} | ||
|
||
@Override | ||
public boolean matches(ExpressionTree tree, VisitorState state) { | ||
return isLambdaExpression(tree) || isMethodReference(tree); | ||
} | ||
|
||
private static boolean isLambdaExpression(ExpressionTree tree) { | ||
return tree instanceof LambdaExpressionTree; | ||
} | ||
|
||
private static boolean isMethodReference(ExpressionTree tree) { | ||
return tree instanceof MemberReferenceTree | ||
&& ((MemberReferenceTree) tree).getMode() == MemberReferenceTree.ReferenceMode.INVOKE; | ||
} | ||
} |