use of com.sun.source.tree.ExpressionTree in project error-prone by google.
the class ProtoFieldPreconditionsCheckNotNull method isGetMethodInvocation.
private static boolean isGetMethodInvocation(ExpressionTree tree, VisitorState state) {
if (tree.getKind() == Tree.Kind.METHOD_INVOCATION) {
MethodInvocationTree method = (MethodInvocationTree) tree;
if (!method.getArguments().isEmpty()) {
return false;
}
if (returnsListMatcher.matches(method, state)) {
return false;
}
ExpressionTree expressionTree = method.getMethodSelect();
if (expressionTree instanceof JCFieldAccess) {
JCFieldAccess access = (JCFieldAccess) expressionTree;
String methodName = access.sym.getQualifiedName().toString();
return isFieldGetMethod(methodName);
}
return true;
}
return false;
}
use of com.sun.source.tree.ExpressionTree in project error-prone by google.
the class ProtoFieldPreconditionsCheckNotNull method isGetListMethodInvocation.
private static boolean isGetListMethodInvocation(ExpressionTree tree, VisitorState state) {
if (tree.getKind() == Tree.Kind.METHOD_INVOCATION) {
MethodInvocationTree method = (MethodInvocationTree) tree;
if (!method.getArguments().isEmpty()) {
return false;
}
if (!returnsListMatcher.matches(method, state)) {
return false;
}
ExpressionTree expressionTree = method.getMethodSelect();
if (expressionTree instanceof JCFieldAccess) {
JCFieldAccess access = (JCFieldAccess) expressionTree;
String methodName = access.sym.getQualifiedName().toString();
return isFieldGetMethod(methodName);
}
return true;
}
return false;
}
use of com.sun.source.tree.ExpressionTree in project error-prone by google.
the class ProtoStringFieldReferenceEquality method matchBinary.
@Override
public Description matchBinary(BinaryTree tree, VisitorState state) {
switch(tree.getKind()) {
case EQUAL_TO:
case NOT_EQUAL_TO:
break;
default:
return NO_MATCH;
}
ExpressionTree lhs = tree.getLeftOperand();
ExpressionTree rhs = tree.getRightOperand();
if (match(lhs, rhs, state) || match(rhs, lhs, state)) {
String result = String.format("%s.equals(%s)", state.getSourceForNode(lhs), state.getSourceForNode(rhs));
if (tree.getKind() == Kind.NOT_EQUAL_TO) {
result = "!" + result;
}
return describeMatch(tree, SuggestedFix.replace(tree, result));
}
return NO_MATCH;
}
use of com.sun.source.tree.ExpressionTree in project error-prone by google.
the class ASTHelpersTest method expressionStatementMatches.
private Scanner expressionStatementMatches(final String expectedExpression, final Matcher<ExpressionTree> matcher) {
return new TestScanner() {
@Override
public Void visitExpressionStatement(ExpressionStatementTree node, VisitorState state) {
ExpressionTree expression = node.getExpression();
if (expression.toString().equals(expectedExpression)) {
assertMatch(node.getExpression(), state, matcher);
setAssertionsComplete();
}
return super.visitExpressionStatement(node, state);
}
};
}
use of com.sun.source.tree.ExpressionTree in project error-prone by google.
the class DescendantOfAbstractTest method memberSelectMatches.
protected Scanner memberSelectMatches(final boolean shouldMatch, final DescendantOf toMatch) {
ScannerTest test = new ScannerTest() {
private boolean matched = false;
@Override
public Void visitMethodInvocation(MethodInvocationTree node, VisitorState visitorState) {
visitorState = visitorState.withPath(getCurrentPath());
ExpressionTree methodSelect = node.getMethodSelect();
if (toMatch.matches(methodSelect, visitorState)) {
matched = true;
}
return super.visitMethodInvocation(node, visitorState);
}
@Override
public void assertDone() {
assertEquals(matched, shouldMatch);
}
};
tests.add(test);
return test;
}
Aggregations