private int getArgumentListArity(ASTArgumentList argList) { if (argList != null) { return argList.jjtGetNumChildren(); } return 0; }
/** * Determines the log level, that is used. It is either the called method name * itself or - in case java util logging is used, then it is the first argument of * the method call (if it exists). * * @param node the method call * @param methodCallName the called method name previously determined * @return the log level or <code>null</code> if it could not be determined */ private String getLogLevelName(Node node, String methodCallName) { if (!JAVA_UTIL_LOG_METHOD.equals(methodCallName) && !JAVA_UTIL_LOG_GUARD_METHOD.equals(methodCallName)) { return methodCallName; } String logLevel = null; ASTPrimarySuffix suffix = node.getFirstDescendantOfType(ASTPrimarySuffix.class); if (suffix != null) { ASTArgumentList argumentList = suffix.getFirstDescendantOfType(ASTArgumentList.class); if (argumentList != null && argumentList.jjtGetNumChildren() > 0) { // at least one argument - the log level. If the method call is "log", then a message might follow ASTName name = GuardLogStatementRule.<ASTName>getFirstChild(argumentList.jjtGetChild(0), ASTPrimaryExpression.class, ASTPrimaryPrefix.class, ASTName.class); String lastPart = getLastPartOfName(name); lastPart = lastPart.toLowerCase(Locale.ROOT); if (!lastPart.isEmpty()) { logLevel = lastPart; } } } return logLevel; }
final int argCount = argList == null ? 0 : argList.jjtGetNumChildren();
} else { for (int argIndex = 0; argIndex < argList.jjtGetNumChildren(); ++argIndex) { JavaTypeDefinition parameterType = argIndex < methodParameters.size() - 1 ? methodParameters.get(argIndex) : varargComponentType;
final int argCount = argList == null ? 0 : argList.jjtGetNumChildren();
protected static boolean isInStringBufferOperation(Node node, int length, String methodName) { if (!(node.getNthParent(length) instanceof ASTStatementExpression)) { return false; } ASTStatementExpression s = node.getFirstParentOfType(ASTStatementExpression.class); if (s == null) { return false; } ASTName n = s.getFirstDescendantOfType(ASTName.class); if (n == null || n.getImage().indexOf(methodName) == -1 || !(n.getNameDeclaration() instanceof TypedNameDeclaration)) { return false; } // TODO having to hand-code this kind of dredging around is ridiculous // we need something to support this in the framework // but, "for now" (tm): // if more than one arg to append(), skip it ASTArgumentList argList = s.getFirstDescendantOfType(ASTArgumentList.class); if (argList == null || argList.jjtGetNumChildren() > 1) { return false; } return TypeHelper.isExactlyAny((TypedNameDeclaration) n.getNameDeclaration(), StringBuffer.class, StringBuilder.class); }
ASTArgumentList argumentList = args.getFirstChildOfType(ASTArgumentList.class); if (argumentList != null) { for (int a = 0; a < argumentList.jjtGetNumChildren(); a++) { Node expression = argumentList.jjtGetChild(a); ASTPrimaryPrefix arg = expression.getFirstDescendantOfType(ASTPrimaryPrefix.class);
List<TypedNameDeclaration> argumentTypes = new ArrayList<>(arguments.jjtGetNumChildren()); Map<String, Node> qualifiedTypeNames = getEnclosingScope(SourceFileScope.class).getQualifiedTypeNames(); for (int i = 0; i < arguments.jjtGetNumChildren(); i++) { Node argument = arguments.jjtGetChild(i); Node child = null;
} else { ASTArgumentList argumentList = (ASTArgumentList) arguments.jjtGetChild(0); for (int i = 0; i < argumentList.jjtGetNumChildren(); i++) { Node expressionChild = argumentList.jjtGetChild(i).jjtGetChild(0); if (!(expressionChild instanceof ASTPrimaryExpression) || expressionChild.jjtGetNumChildren() != 1) {
private int getArgumentListArity(ASTArgumentList argList) { if (argList != null) { return argList.jjtGetNumChildren(); } return 0; }
/** * Determines the log level, that is used. It is either the called method name * itself or - in case java util logging is used, then it is the first argument of * the method call (if it exists). * * @param node the method call * @param methodCallName the called method name previously determined * @return the log level or <code>null</code> if it could not be determined */ private String getLogLevelName(Node node, String methodCallName) { if (!JAVA_UTIL_LOG_METHOD.equals(methodCallName) && !JAVA_UTIL_LOG_GUARD_METHOD.equals(methodCallName)) { return methodCallName; } String logLevel = null; ASTPrimarySuffix suffix = node.getFirstDescendantOfType(ASTPrimarySuffix.class); if (suffix != null) { ASTArgumentList argumentList = suffix.getFirstDescendantOfType(ASTArgumentList.class); if (argumentList != null && argumentList.jjtGetNumChildren() > 0) { // at least one argument - the log level. If the method call is "log", then a message might follow ASTName name = GuardLogStatementRule.<ASTName>getFirstChild(argumentList.jjtGetChild(0), ASTPrimaryExpression.class, ASTPrimaryPrefix.class, ASTName.class); String lastPart = getLastPartOfName(name); lastPart = lastPart.toLowerCase(Locale.ROOT); if (!lastPart.isEmpty()) { logLevel = lastPart; } } } return logLevel; }
final int argCount = argList == null ? 0 : argList.jjtGetNumChildren();
} else { for (int argIndex = 0; argIndex < argList.jjtGetNumChildren(); ++argIndex) { JavaTypeDefinition parameterType = argIndex < methodParameters.size() - 1 ? methodParameters.get(argIndex) : varargComponentType;
private Object checkThreadPoolExecutor(ASTAllocationExpression node, Object data) { ASTArgumentList argumentList = node.getFirstDescendantOfType(ASTArgumentList.class); if (argumentList.jjtGetNumChildren() < ARGUMENT_LENGTH_6 || !checkThreadFactoryArgument((ASTExpression)argumentList.jjtGetChild(ARGUMENT_LENGTH_6 - INDEX_1))) { addViolationWithMessage(data, node, MESSAGE_KEY_PREFIX + ".ThreadPoolExecutor"); } return super.visit(node, data); }
private Object checkSchedulePoolExecutor(ASTAllocationExpression node, Object data) { ASTArgumentList argumentList = node.getFirstDescendantOfType(ASTArgumentList.class); if (argumentList.jjtGetNumChildren() < ARGUMENT_LENGTH_2 || !checkThreadFactoryArgument((ASTExpression)argumentList.jjtGetChild(ARGUMENT_LENGTH_2 - INDEX_1))) { addViolationWithMessage(data, node, MESSAGE_KEY_PREFIX + ".ScheduledThreadPoolExecutor"); } return super.visit(node, data); }
final int argCount = argList == null ? 0 : argList.jjtGetNumChildren();
protected static boolean isInStringBufferOperation(Node node, int length, String methodName) { if (!(node.getNthParent(length) instanceof ASTStatementExpression)) { return false; } ASTStatementExpression s = node.getFirstParentOfType(ASTStatementExpression.class); if (s == null) { return false; } ASTName n = s.getFirstDescendantOfType(ASTName.class); if (n == null || n.getImage().indexOf(methodName) == -1 || !(n.getNameDeclaration() instanceof TypedNameDeclaration)) { return false; } // TODO having to hand-code this kind of dredging around is ridiculous // we need something to support this in the framework // but, "for now" (tm): // if more than one arg to append(), skip it ASTArgumentList argList = s.getFirstDescendantOfType(ASTArgumentList.class); if (argList == null || argList.jjtGetNumChildren() > 1) { return false; } return TypeHelper.isExactlyAny((TypedNameDeclaration) n.getNameDeclaration(), StringBuffer.class, StringBuilder.class); }
ASTArgumentList argumentList = args.getFirstChildOfType(ASTArgumentList.class); if (argumentList != null) { for (int a = 0; a < argumentList.jjtGetNumChildren(); a++) { Node expression = argumentList.jjtGetChild(a); ASTPrimaryPrefix arg = expression.getFirstDescendantOfType(ASTPrimaryPrefix.class);
List<TypedNameDeclaration> argumentTypes = new ArrayList<>(arguments.jjtGetNumChildren()); Map<String, Node> qualifiedTypeNames = getEnclosingScope(SourceFileScope.class).getQualifiedTypeNames(); for (int i = 0; i < arguments.jjtGetNumChildren(); i++) { Node argument = arguments.jjtGetChild(i); Node child = null;
} else { ASTArgumentList argumentList = (ASTArgumentList) arguments.jjtGetChild(0); for (int i = 0; i < argumentList.jjtGetNumChildren(); i++) { Node expressionChild = argumentList.jjtGetChild(i).jjtGetChild(0); if (!(expressionChild instanceof ASTPrimaryExpression) || expressionChild.jjtGetNumChildren() != 1) {