String suppression = state.getTreeMaker().Literal(CLASS, warningToSuppress).toString();
@Override public Description matchMethodInvocation(MethodInvocationTree tree, final VisitorState state) { if (!METHOD_MATCHER.matches(tree, state)) { return Description.NO_MATCH; } String value = ASTHelpers.constValue(tree.getArguments().get(0), String.class); if (value == null) { // Value isn't a compile-time constant, so we can't know if it's unsafe. return Description.NO_MATCH; } Replacement replacement = getReplacement(value, isInJodaTimeContext(state)); if (replacement.replacements.isEmpty()) { return Description.NO_MATCH; } Description.Builder builder = buildDescription(tree).setMessage(replacement.message); for (String r : replacement.replacements) { builder.addFix( SuggestedFix.replace( tree.getArguments().get(0), state.getTreeMaker().Literal(r).toString())); } return builder.build(); }
/** * Prints a literal. */ @Override public void visitLiteral(JCLiteral literal) { String s = literal.toString(); switch (literal.typetag) { case FLOAT: if (s.endsWith("F")) { s = s.substring(0, s.length() - 1); } break; case LONG: if (s.endsWith("L")) { s = s.substring(0, s.length() - 1); } break; default: } print(s); }
String suppression = state.getTreeMaker().Literal(CLASS, warningToSuppress).toString();
@Override public Description matchMethodInvocation(MethodInvocationTree tree, final VisitorState state) { if (!METHOD_MATCHER.matches(tree, state)) { return Description.NO_MATCH; } String value = ASTHelpers.constValue(tree.getArguments().get(0), String.class); if (value == null) { // Value isn't a compile-time constant, so we can't know if it's unsafe. return Description.NO_MATCH; } Replacement replacement = getReplacement(value, isInJodaTimeContext(state)); if (replacement.replacements.isEmpty()) { return Description.NO_MATCH; } Description.Builder builder = buildDescription(tree).setMessage(replacement.message); for (String r : replacement.replacements) { builder.addFix( SuggestedFix.replace( tree.getArguments().get(0), state.getTreeMaker().Literal(r).toString())); } return builder.build(); }