private void checkThreadLocal(ASTFieldDeclaration fieldDeclaration, ASTCompilationUnit node, Object data) { try { List<Node> nodes = node.findChildNodesWithXPath(String.format(XPATH_TPL, fieldDeclaration.getVariableName())); if (nodes == null || nodes.isEmpty()) { ViolationUtils.addViolationWithPrecisePosition(this, fieldDeclaration, data, I18nResources.getMessage("java.concurrent.ThreadLocalShouldRemoveRule.violation.msg", fieldDeclaration.getVariableName())); } } catch (JaxenException ignore) { } } }
/** * An undefined that belongs to non-looped if statements * * @param node compilation unit * @param data rule context */ @Override public Object visit(ASTCompilationUnit node, Object data) { // removed repeat magic value , to prevent the parent class to find sub-variable nodes when there is a repeat List<ASTLiteral> currentLiterals = new ArrayList<ASTLiteral>(); try { // Find the parent node of the undefined variable List<Node> parentNodes = node.findChildNodesWithXPath(XPATH); for (Node parentItem : parentNodes) { List<ASTLiteral> literals = parentItem.findDescendantsOfType(ASTLiteral.class); for (ASTLiteral literal : literals) { if (inBlackList(literal) && !currentLiterals.contains(literal)) { currentLiterals.add(literal); String imageReplace = StringUtil.replaceString(literal.getImage(), "{", "'{"); addViolationWithMessage(data, literal, "java.constant.UndefineMagicConstantRule.violation.msg", new Object[] {imageReplace}); } } } } catch (JaxenException e) { e.printStackTrace(); } return super.visit(node, data); }
@Override public Object visit(ASTCompilationUnit node, Object data) { try { List<Node> equalsInvocations = node.findChildNodesWithXPath(XPATH); if (equalsInvocations == null || equalsInvocations.isEmpty()) { return super.visit(node, data);