private void checkShiftWithoutByteSecuring(ExpressionTree shiftExpr, ExpressionTree byteExpr) { if (shifts.contains(shiftExpr) && !byteContainments.contains(byteExpr) && byteExpr.symbolType().isPrimitive(Primitives.BYTE)) { context.reportIssue( this, byteExpr, "Prevent \"int\" promotion by adding \"& 0xff\" to this expression."); } }
@Override public void scanFile(JavaFileScannerContext context) { Multimap<Tree, String> issues = ((DefaultJavaFileScannerContext) context).getSEIssues(UnclosedResourcesCheck.class); for (Map.Entry<Tree, String> issue : issues.entries()) { context.reportIssue(this, issue.getKey(), issue.getValue()); } }
private void checkStatements(List<StatementTree> statements) { for (StatementTree statement : statements) { if (statement.is(Tree.Kind.BLOCK)) { context.reportIssue( this, ((BlockTree) statement).openBraceToken(), "Extract this nested code block into a method."); } } }
@Override public void visitCatch(CatchTree tree) { if (!isExcludedType(tree.parameter().type())) { Symbol exception = tree.parameter().symbol(); validUsagesStack.addFirst(exception.usages()); super.visitCatch(tree); Collection<IdentifierTree> usages = validUsagesStack.pop(); if (usages.isEmpty()) { context.reportIssue(this, tree.parameter(), "Either log or rethrow this exception."); } } }
@Override public void visitNewClass(NewClassTree tree) { if (TARGETED_CLASS.contains(getclassName(tree)) && tree.arguments().size() == 1) { ExpressionTree argument = tree.arguments().get(0); if (argument.is(Tree.Kind.CHAR_LITERAL)) { String character = ((LiteralTree) argument).value(); context.reportIssue( this, argument, "Replace the constructor character parameter " + character + " with string parameter " + character.replace("'", "\"") + "."); } } }
private void createIssue(Tree reportingTree, String wrapperName) { context.reportIssue(this, reportingTree, "Use \"" + wrapperName + ".toString\" instead."); }