private int checkType() { if (jjtGetNumChildren() == 0 || !(jjtGetChild(0) instanceof ASTType)) { return 0; } return ((ASTType) jjtGetChild(0)).getArrayDepth(); }
private int checkDecl() { if (jjtGetNumChildren() < 2 || !(jjtGetChild(1) instanceof ASTVariableDeclarator)) { return 0; } return ((ASTVariableDeclaratorId) jjtGetChild(1).jjtGetChild(0)).getArrayDepth(); }
@Override public Object visit(ASTFieldDeclaration node, Object data) { for (int x = 0; x < node.jjtGetNumChildren(); ++x) { Node firstStmt = node.jjtGetChild(x); if (firstStmt instanceof ASTType) { ASTType tp = (ASTType) firstStmt; Node nd = tp.jjtGetChild(0); checkVariableType(nd, nd.getImage()); } } return super.visit(node, data); }
Node type = fieldDeclaration.jjtGetChild(0).jjtGetChild(0); if (type instanceof ASTReferenceType) {
private int checkType() { if (jjtGetNumChildren() == 0 || !(jjtGetChild(0) instanceof ASTType)) { return 0; } return ((ASTType) jjtGetChild(0)).getArrayDepth(); }
private int checkDecl() { if (jjtGetNumChildren() < 2 || !(jjtGetChild(1) instanceof ASTVariableDeclarator)) { return 0; } return ((ASTVariableDeclaratorId) jjtGetChild(1).jjtGetChild(0)).getArrayDepth(); }
Node type = fieldDeclaration.jjtGetChild(0).jjtGetChild(0); if (type instanceof ASTReferenceType) {
@Override public Object visit(ASTFieldDeclaration node, Object data) { for (int x = 0; x < node.jjtGetNumChildren(); ++x) { Node firstStmt = node.jjtGetChild(x); if (firstStmt instanceof ASTType) { ASTType tp = (ASTType) firstStmt; Node nd = tp.jjtGetChild(0); checkVariableType(nd, nd.getImage()); } } return super.visit(node, data); }
@Override public Object visit(ASTFieldDeclaration node, Object data) { if (!(node.isStatic() && node.isFinal())) { return super.visit(node, data); } //If the variable is of type Log or Logger,do not check ASTClassOrInterfaceType classOrInterfaceType = node.getFirstDescendantOfType(ASTClassOrInterfaceType.class); if (classOrInterfaceType != null && LOG_VARIABLE_TYPE_SET.contains(classOrInterfaceType.getImage())) { return super.visit(node, data); } //filter by white list,such as the serialVersionUID String constantName = node.jjtGetChild(1).jjtGetChild(0).getImage(); boolean inWhiteList = StringUtils.isEmpty(constantName) || WHITE_LIST.contains(constantName) || constantName.endsWith(SERVICE_SUFFIX); if (inWhiteList) { return super.visit(node, data); } //Constant should be upper if (!(constantName.equals(constantName.toUpperCase()))) { ViolationUtils.addViolationWithPrecisePosition(this, node, data, I18nResources.getMessage("java.naming.ConstantFieldShouldBeUpperCaseRule.violation.msg", constantName)); } return super.visit(node, data); } }