private boolean checkArgumentNumber(MethodInvocationTree mit, int nbReadParams, int nbArgs) { if (nbReadParams > nbArgs) { reportIssue(mit, "Not enough arguments."); return true; } return false; }
private boolean checkArgumentNumber(MethodInvocationTree mit, int nbReadParams, int nbArgs) { if (nbReadParams > nbArgs) { reportIssue(mit, "Not enough arguments."); return true; } return false; }
@Override protected void reportMissingPrevious(MethodInvocationTree mit) { reportIssue(mit, "The argument index '<' refers to the previous format specifier but there isn't one."); }
@Override protected void reportMissingPrevious(MethodInvocationTree mit) { reportIssue(mit, "The argument index '<' refers to the previous format specifier but there isn't one."); }
private void verifyParameters(MethodInvocationTree mit, List<ExpressionTree> args, Set<Integer> indexes) { for (int index : indexes) { if (index >= args.size()) { reportIssue(mit, "Not enough arguments."); return; } } }
private void verifyParameters(MethodInvocationTree mit, List<ExpressionTree> args, Set<Integer> indexes) { for (int index : indexes) { if (index >= args.size()) { reportIssue(mit, "Not enough arguments."); return; } } }
private void checkNumerical(MethodInvocationTree mit, String param, Type argType) { if (param.charAt(0) == 'd' && !isNumerical(argType)) { reportIssue(mit, "An 'int' is expected rather than a " + argType + "."); } }
private void checkTimeConversion(MethodInvocationTree mit, String param, Type argType) { if (param.charAt(0) == 't' || param.charAt(0) == 'T') { String timeConversion = param.substring(1); if (timeConversion.isEmpty()) { reportIssue(mit, "Time conversion requires a second character."); checkTimeTypeArgument(mit, argType); return; } if (!TIME_CONVERSIONS.contains(timeConversion)) { reportIssue(mit, timeConversion + " is not a supported time conversion character"); } checkTimeTypeArgument(mit, argType); } }
private void checkNumerical(MethodInvocationTree mit, String param, Type argType) { if (param.charAt(0) == 'd' && !isNumerical(argType)) { reportIssue(mit, "An 'int' is expected rather than a " + argType + "."); } }
private void checkTimeConversion(MethodInvocationTree mit, String param, Type argType) { if (param.charAt(0) == 't' || param.charAt(0) == 'T') { String timeConversion = param.substring(1); if (timeConversion.isEmpty()) { reportIssue(mit, "Time conversion requires a second character."); checkTimeTypeArgument(mit, argType); return; } if (!TIME_CONVERSIONS.contains(timeConversion)) { reportIssue(mit, timeConversion + " is not a supported time conversion character"); } checkTimeTypeArgument(mit, argType); } }
private boolean checkUnbalancedBraces(MethodInvocationTree mit, String formatString) { String withoutParam = MESSAGE_FORMAT_PATTERN.matcher(formatString).replaceAll(""); int numberOpenBrace = 0; for (int i = 0; i < withoutParam.length(); ++i) { char ch = withoutParam.charAt(i); switch (ch) { case '{': numberOpenBrace++; break; case '}': numberOpenBrace--; break; default: break; } } boolean unbalancedBraces = numberOpenBrace > 0; if (unbalancedBraces) { reportIssue(mit.arguments().get(0), "Single left curly braces \"{\" must be escaped."); } return unbalancedBraces; }
private boolean checkUnbalancedBraces(MethodInvocationTree mit, String formatString) { String withoutParam = MESSAGE_FORMAT_PATTERN.matcher(formatString).replaceAll(""); int numberOpenBrace = 0; for (int i = 0; i < withoutParam.length(); ++i) { char ch = withoutParam.charAt(i); switch (ch) { case '{': numberOpenBrace++; break; case '}': numberOpenBrace--; break; default: break; } } boolean unbalancedBraces = numberOpenBrace > 0; if (unbalancedBraces) { reportIssue(mit.arguments().get(0), "Single left curly braces \"{\" must be escaped."); } return unbalancedBraces; }
private boolean checkUnbalancedQuotes(MethodInvocationTree mit, String formatString) { if(LEVELS.contains(mit.symbol().name())) { return false; } String withoutParam = MESSAGE_FORMAT_PATTERN.matcher(formatString).replaceAll(""); int numberQuote = 0; for (int i = 0; i < withoutParam.length(); ++i) { if (withoutParam.charAt(i) == '\'') { numberQuote++; } } boolean unbalancedQuotes = (numberQuote % 2) != 0; if (unbalancedQuotes) { reportIssue(mit.arguments().get(0), "Single quote \"'\" must be escaped."); } return unbalancedQuotes; }
private boolean checkUnbalancedQuotes(MethodInvocationTree mit, String formatString) { if(LEVELS.contains(mit.symbol().name())) { return false; } String withoutParam = MESSAGE_FORMAT_PATTERN.matcher(formatString).replaceAll(""); int numberQuote = 0; for (int i = 0; i < withoutParam.length(); ++i) { if (withoutParam.charAt(i) == '\'') { numberQuote++; } } boolean unbalancedQuotes = (numberQuote % 2) != 0; if (unbalancedQuotes) { reportIssue(mit.arguments().get(0), "Single quote \"'\" must be escaped."); } return unbalancedQuotes; }
private void verifyParameters(MethodInvocationTree mit, List<ExpressionTree> args, List<String> params) { int index = 0; for (String rawParam : params) { String param = rawParam; int argIndex = index; if (param.contains("$")) { argIndex = getIndex(param) - 1; if (argIndex == -1) { reportIssue(mit, "Arguments are numbered starting from 1."); return; } param = param.substring(param.indexOf('$') + 1); } else if (param.charAt(0) == '<') { //refers to previous argument argIndex = Math.max(0, argIndex - 1); }else { index++; } ExpressionTree argExpressionTree = args.get(argIndex); Type argType = argExpressionTree.symbolType(); checkNumerical(mit, param, argType); checkTimeConversion(mit, param, argType); } }
private void checkTimeTypeArgument(MethodInvocationTree mit, Type argType) { if (!(argType.isNumerical() || argType.is("java.lang.Long") || isSubtypeOfAny(argType, "java.util.Date", "java.util.Calendar", "java.time.temporal.TemporalAccessor"))) { reportIssue(mit, "Time argument is expected (long, Long, Calendar, Date and TemporalAccessor)."); } }
private void verifyParameters(MethodInvocationTree mit, List<ExpressionTree> args, List<String> params) { int index = 0; for (String rawParam : params) { String param = rawParam; int argIndex = index; if (param.contains("$")) { argIndex = getIndex(param) - 1; if (argIndex == -1) { reportIssue(mit, "Arguments are numbered starting from 1."); return; } param = param.substring(param.indexOf('$') + 1); } else if (param.charAt(0) == '<') { //refers to previous argument argIndex = Math.max(0, argIndex - 1); }else { index++; } ExpressionTree argExpressionTree = args.get(argIndex); Type argType = argExpressionTree.symbolType(); checkNumerical(mit, param, argType); checkTimeConversion(mit, param, argType); } }
private void checkTimeTypeArgument(MethodInvocationTree mit, Type argType) { if (!(argType.isNumerical() || argType.is("java.lang.Long") || isSubtypeOfAny(argType, "java.util.Date", "java.util.Calendar", "java.time.temporal.TemporalAccessor"))) { reportIssue(mit, "Time argument is expected (long, Long, Calendar, Date and TemporalAccessor)."); } }