use of com.sun.source.tree.LiteralTree in project error-prone by google.
the class SizeGreaterThanOrEqualsZero method isGreaterThanEqualToZero.
private ExpressionType isGreaterThanEqualToZero(BinaryTree tree) {
ExpressionTree literalOperand;
ExpressionType returnType;
switch(tree.getKind()) {
case GREATER_THAN_EQUAL:
literalOperand = tree.getRightOperand();
returnType = ExpressionType.GREATER_THAN_EQUAL;
break;
case LESS_THAN_EQUAL:
literalOperand = tree.getLeftOperand();
returnType = ExpressionType.LESS_THAN_EQUAL;
break;
default:
return ExpressionType.MISMATCH;
}
if (literalOperand.getKind() != Kind.INT_LITERAL) {
return ExpressionType.MISMATCH;
}
if (!((LiteralTree) literalOperand).getValue().equals(0)) {
return ExpressionType.MISMATCH;
}
return returnType;
}
use of com.sun.source.tree.LiteralTree in project error-prone by google.
the class DivZero method matchDivZero.
private Description matchDivZero(Tree tree, ExpressionTree operand, VisitorState state) {
if (!anyOf(kindIs(Kind.DIVIDE), kindIs(Kind.DIVIDE_ASSIGNMENT)).matches(tree, state)) {
return Description.NO_MATCH;
}
if (!kindIs(Kind.INT_LITERAL).matches(operand, state)) {
return Description.NO_MATCH;
}
LiteralTree rightOperand = (LiteralTree) operand;
if (((Integer) rightOperand.getValue()) != 0) {
return Description.NO_MATCH;
}
// Find and replace enclosing Statement.
StatementTree enclosingStmt = ASTHelpers.findEnclosingNode(state.getPath(), StatementTree.class);
return (enclosingStmt != null) ? describeMatch(tree, SuggestedFix.replace(enclosingStmt, "throw new ArithmeticException(\"/ by zero\");")) : describeMatch(tree);
}
use of com.sun.source.tree.LiteralTree in project error-prone by google.
the class PreconditionsInvalidPlaceholder method matchMethodInvocation.
@Override
public Description matchMethodInvocation(MethodInvocationTree t, VisitorState state) {
if (PRECONDITIONS_CHECK.matches(t, state) && t.getArguments().size() >= 2 && t.getArguments().get(1) instanceof LiteralTree) {
LiteralTree formatStringTree = (LiteralTree) t.getArguments().get(1);
if (formatStringTree.getValue() instanceof String) {
String formatString = (String) formatStringTree.getValue();
int expectedArgs = expectedArguments(formatString);
if (expectedArgs < t.getArguments().size() - 2 && BAD_PLACEHOLDER_REGEX.matcher(formatString).find()) {
return describe(t, state);
}
}
}
return Description.NO_MATCH;
}
use of com.sun.source.tree.LiteralTree in project error-prone by google.
the class StringLiteral method matches.
@Override
public boolean matches(ExpressionTree expressionTree, VisitorState state) {
if (expressionTree instanceof LiteralTree) {
LiteralTree literalTree = (LiteralTree) expressionTree;
Object actualValue = literalTree.getValue();
return actualValue instanceof String && pattern.matcher((String) actualValue).matches();
} else {
return false;
}
}
use of com.sun.source.tree.LiteralTree in project checker-framework by typetools.
the class TreeParserTest method parsesNumbers.
@Test
public void parsesNumbers() {
String value = "23";
ExpressionTree parsed = parser.parseTree(value);
Assert.assertTrue(parsed instanceof LiteralTree);
}
Aggregations