class WhileLoopRules extends TimedDelegate {

    @Override
    protected Set<Violation> doMeasuredAnalysis() throws JDOMException {
        final Set<Violation> violations = new HashSet<Violation>();

        final List<Element> whileLoops = selectNodesByName("WHILE.");
        // Potential false positives:
        // condition value is passed by reference into a function or subroutine in the condition or the body.
        // condition calls a subroutine that references higher scope variables that are set in the body.

        for (final Element whileLoop : whileLoops) {
            // The way I am going to do this check is pretty good but not perfect. Basically I will look at the
            // conditional portion of the while loop and locate all NAME variables. At least one of those name variables
            // will be by conditional, so I will then scan the body of the while loop looking for instances where the
            // conditional is referenced on the left hand side of an operator to ensure that something in the
            // conditional is getting a new value periodically.
            List<Attribute> nameAttributes = selectAttributes(whileLoop, "./*[1]/descendant-or-self::NAME/@text");

            boolean found = false;
            for (Attribute nameAttribute : nameAttributes) {
                // Search for this name within a Z_SET command to see if it's used there
                if (!selectNodes(whileLoop, "./COMMA.//Z_SET./NAME[1][@text = '" + nameAttribute.getValue() + "']")
                        .isEmpty()) {
                    found = true;
                    break;
                }

                // Search for this name within a IS. command to see if it's used within a report writer section
                if (!selectNodes(whileLoop, "./COMMA.//IS./NAME[1][@text = '" + nameAttribute.getValue() + "']")
                        .isEmpty()) {
                    found = true;
                    break;
                }
            }

            if (!found) {
                violations.add(new InfiniteLoopViolation(getLineNumber(whileLoop)));
            }
        }

        return violations;
    }

    public  WhileLoopRules(final Document document);

}