@Override public void visitNode(Tree node) { if (LiteralUtils.isEmptyString(node)) { return; } String value = LiteralUtils.trimQuotes(((LiteralTree) node).value()); // replace \\ with nothing just to differentiate \u0000 and \\u0000 Matcher matcher = UNICODE_ESCAPED_CHAR.matcher(value.replaceAll("\\\\\\\\","")); List<String> matches = getAllMatches(matcher); if (!matches.isEmpty()) { boolean notOnlyUnicodeEscaped = !matcher.replaceAll("").isEmpty(); if (notOnlyUnicodeEscaped && matches.stream().anyMatch(IS_PRINTABLE_ESCAPED_UNICODE)) { reportIssue(node, "Remove this Unicode escape sequence and use the character instead."); } } }
@Override public void visitNode(Tree node) { if (LiteralUtils.isEmptyString(node)) { return; } String value = LiteralUtils.trimQuotes(((LiteralTree) node).value()); // replace \\ with nothing just to differentiate \u0000 and \\u0000 Matcher matcher = UNICODE_ESCAPED_CHAR.matcher(value.replaceAll("\\\\\\\\","")); List<String> matches = getAllMatches(matcher); if (!matches.isEmpty()) { boolean notOnlyUnicodeEscaped = !matcher.replaceAll("").isEmpty(); if (notOnlyUnicodeEscaped && matches.stream().anyMatch(IS_PRINTABLE_ESCAPED_UNICODE)) { reportIssue(node, "Remove this Unicode escape sequence and use the character instead."); } } }
private static boolean isUsualDefaultValue(ExpressionTree tree) { ExpressionTree expr = ExpressionUtils.skipParentheses(tree); switch (expr.kind()) { case BOOLEAN_LITERAL: case NULL_LITERAL: return true; case STRING_LITERAL: return LiteralUtils.isEmptyString(expr); case INT_LITERAL: String value = ((LiteralTree) expr).value(); return "0".equals(value) || "1".equals(value); case UNARY_MINUS: case UNARY_PLUS: return isUsualDefaultValue(((UnaryExpressionTree) expr).expression()); default: return false; } }
private static boolean isUsualDefaultValue(ExpressionTree tree) { ExpressionTree expr = ExpressionUtils.skipParentheses(tree); switch (expr.kind()) { case BOOLEAN_LITERAL: case NULL_LITERAL: return true; case STRING_LITERAL: return LiteralUtils.isEmptyString(expr); case INT_LITERAL: String value = ((LiteralTree) expr).value(); return "0".equals(value) || "1".equals(value); case UNARY_MINUS: case UNARY_PLUS: return isUsualDefaultValue(((UnaryExpressionTree) expr).expression()); default: return false; } }