ASTName name = node.getFirstDescendantOfType(ASTName.class);
@Override public Object visit(ASTAllocationExpression node, Object data) { Node type = node.jjtGetChild(0); if (!(type instanceof ASTClassOrInterfaceType)) { return super.visit(node, data); } boolean jdk15 = ((RuleContext) data).getLanguageVersion() .compareTo(LanguageRegistry.getLanguage(JavaLanguageModule.NAME).getVersion("1.5")) >= 0; if ((TypeHelper.isA((ASTClassOrInterfaceType) type, BigInteger.class) || jdk15 && TypeHelper.isA((ASTClassOrInterfaceType) type, BigDecimal.class)) && !node.hasDescendantOfType(ASTArrayDimsAndInits.class)) { ASTArguments args = node.getFirstChildOfType(ASTArguments.class); if (args.getArgumentCount() == 1) { ASTLiteral literal = node.getFirstDescendantOfType(ASTLiteral.class); if (literal == null || literal.jjtGetParent().jjtGetParent().jjtGetParent().jjtGetParent().jjtGetParent() != args) { return super.visit(node, data); } String img = literal.getImage(); if (literal.isStringLiteral()) { img = img.substring(1, img.length() - 1); } if ("0".equals(img) || "1".equals(img) || jdk15 && "10".equals(img)) { addViolation(data, node); return data; } } } return super.visit(node, data); }
/** * Determine if the constructor contains (or ends with) a String Literal * * @param node * @return 1 if the constructor contains string argument, else 0 */ private int checkConstructor(ASTVariableDeclaratorId node, Object data) { Node parent = node.jjtGetParent(); if (parent.jjtGetNumChildren() >= 2) { ASTAllocationExpression allocationExpression = parent.jjtGetChild(1) .getFirstDescendantOfType(ASTAllocationExpression.class); ASTArgumentList list = null; if (allocationExpression != null) { list = allocationExpression.getFirstDescendantOfType(ASTArgumentList.class); } if (list != null) { ASTLiteral literal = list.getFirstDescendantOfType(ASTLiteral.class); if (!isAdditive(list) && literal != null && literal.isStringLiteral()) { return 1; } return processAdditive(data, 0, list, node); } } return 0; }
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); }
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); }
ASTName name = node.getFirstDescendantOfType(ASTName.class);
@Override public Object visit(ASTAllocationExpression node, Object data) { Node type = node.jjtGetChild(0); if (!(type instanceof ASTClassOrInterfaceType)) { return super.visit(node, data); } boolean jdk15 = ((RuleContext) data).getLanguageVersion() .compareTo(LanguageRegistry.getLanguage(JavaLanguageModule.NAME).getVersion("1.5")) >= 0; if ((TypeHelper.isA((ASTClassOrInterfaceType) type, BigInteger.class) || jdk15 && TypeHelper.isA((ASTClassOrInterfaceType) type, BigDecimal.class)) && !node.hasDescendantOfType(ASTArrayDimsAndInits.class)) { ASTArguments args = node.getFirstChildOfType(ASTArguments.class); if (args.getArgumentCount() == 1) { ASTLiteral literal = node.getFirstDescendantOfType(ASTLiteral.class); if (literal == null || literal.jjtGetParent().jjtGetParent().jjtGetParent().jjtGetParent().jjtGetParent() != args) { return super.visit(node, data); } String img = literal.getImage(); if (literal.isStringLiteral()) { img = img.substring(1, img.length() - 1); } if ("0".equals(img) || "1".equals(img) || jdk15 && "10".equals(img)) { addViolation(data, node); return data; } } } return super.visit(node, data); }
/** * Determine if the constructor contains (or ends with) a String Literal * * @param node * @return 1 if the constructor contains string argument, else 0 */ private int checkConstructor(ASTVariableDeclaratorId node, Object data) { Node parent = node.jjtGetParent(); if (parent.jjtGetNumChildren() >= 2) { ASTAllocationExpression allocationExpression = parent.jjtGetChild(1) .getFirstDescendantOfType(ASTAllocationExpression.class); ASTArgumentList list = null; if (allocationExpression != null) { list = allocationExpression.getFirstDescendantOfType(ASTArgumentList.class); } if (list != null) { ASTLiteral literal = list.getFirstDescendantOfType(ASTLiteral.class); if (!isAdditive(list) && literal != null && literal.isStringLiteral()) { return 1; } return processAdditive(data, 0, list, node); } } return 0; }