use of com.sun.source.tree.MethodInvocationTree in project error-prone by google.
the class DefaultCharset method matchMethodInvocation.
@Override
public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) {
if (state.isAndroidCompatible()) {
return NO_MATCH;
}
if (STRING_GET_BYTES.matches(tree, state)) {
Description.Builder description = buildDescription(tree);
Tree parent = state.getPath().getParentPath().getLeaf();
if (parent instanceof ExpressionTree && BYTESTRING_COPY_FROM.matches((ExpressionTree) parent, state)) {
byteStringFixes(description, tree, (ExpressionTree) parent, state);
} else {
appendCharsets(description, tree, tree.getMethodSelect(), tree.getArguments(), state);
}
return description.build();
}
if (FILE_NEW_WRITER.matches(tree, state)) {
Description.Builder description = buildDescription(tree);
appendCharsets(description, tree, tree.getMethodSelect(), tree.getArguments(), state);
return description.build();
}
return NO_MATCH;
}
use of com.sun.source.tree.MethodInvocationTree in project error-prone by google.
the class IsInstanceOfClass method classify.
static Operand classify(JCTree tree, VisitorState state) {
CharSequence source = state.getSourceForNode(tree);
if (tree instanceof MethodInvocationTree) {
// expr.getClass() -> "expr"
MethodInvocationTree receiverInvocation = (MethodInvocationTree) tree;
MethodSymbol sym = ASTHelpers.getSymbol(receiverInvocation);
if (sym != null) {
if (sym.getSimpleName().contentEquals("getClass") && sym.params().isEmpty()) {
if (receiverInvocation.getMethodSelect() instanceof IdentifierTree) {
// unqualified `getClass()`
return Operand.create(Kind.EXPR, state.getSourceForNode(tree), source);
}
return Operand.create(Kind.GET_CLASS, state.getSourceForNode((JCTree) ASTHelpers.getReceiver(receiverInvocation)), source);
}
}
} else if (tree instanceof MemberSelectTree) {
// Foo.class -> "Foo"
MemberSelectTree select = (MemberSelectTree) tree;
if (select.getIdentifier().contentEquals("class")) {
return Operand.create(Kind.LITERAL, state.getSourceForNode((JCTree) select.getExpression()), source);
}
}
return Operand.create(Kind.EXPR, source, source);
}
use of com.sun.source.tree.MethodInvocationTree in project error-prone by google.
the class ProtoFieldNullComparison 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.MethodInvocationTree in project error-prone by google.
the class ProtoFieldNullComparison 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.MethodInvocationTree in project error-prone by google.
the class RandomModInteger method matchBinary.
@Override
public Description matchBinary(BinaryTree tree, VisitorState state) {
if (tree.getKind() == Kind.REMAINDER && tree.getLeftOperand() instanceof MethodInvocationTree && RANDOM_NEXT_INT.matches(tree.getLeftOperand(), state)) {
ExpressionTree randomExpr = ASTHelpers.getReceiver(tree.getLeftOperand());
ExpressionTree modulus = tree.getRightOperand();
return describeMatch(tree, SuggestedFix.replace(tree, String.format("%s.nextInt(%s)", state.getSourceForNode(randomExpr), state.getSourceForNode(modulus))));
}
return Description.NO_MATCH;
}
Aggregations