/** * Add a new Violation to the list of violations found by this visitor. Only add the violation if * the node lineNumber >= 0. * * @param node - the Groovy AST Node * @param message - the message for the violation; defaults to null */ protected void addViolation(MethodCallExpression node, String message) { if (node.getLineNumber() >= 0) { int lineNumber = AstUtil.findFirstNonAnnotationLine(node, sourceCode); String sourceLine = sourceCode.line(AstUtil.findFirstNonAnnotationLine(node, sourceCode) - 1); Violation violation = new Violation(); violation.setRule(rule); violation.setLineNumber(lineNumber); violation.setSourceLine(sourceLine); if (currentClassNode != null) { violation.setMessage( String.format("Violation in class %s. %s", currentClassNode.getName(), message)); } else { violation.setMessage(message); } violations.add(violation); } }
public void visitMethodCallExpression(MethodCallExpression call) { call.getObjectExpression().visit(this); call.getMethod().visit(this); call.getArguments().visit(this); }