@Override public void visitMethodCallExpression(final MethodCallExpression call) { super.visitMethodCallExpression(call); MethodNode target = (MethodNode) call.getNodeMetaData(DIRECT_METHOD_CALL_TARGET); if (target != null) { call.setMethodTarget(target); memorizeInitialExpressions(target); } if (call.getMethodTarget() == null && call.getLineNumber() > 0) { addError("Target method for method call expression hasn't been set", call); } }
/** * 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); } }