/* Generated By:JJTree: Do not edit this line. ASTAnnotation.java */

package net.sourceforge.pmd.ast;

import net.sourceforge.pmd.Rule;

import java.util.Iterator;
import java.util.List;

public class ASTAnnotation extends SimpleJavaNode {
    public ASTAnnotation(int id) {
        super(id);
    }

    public ASTAnnotation(JavaParser p, int id) {
        super(p, id);
    }

    public boolean suppresses(Rule rule) {
        final String ruleAnno = "\"PMD." + rule.getName() + "\"";

        if (jjtGetChild(0) instanceof ASTSingleMemberAnnotation) {
            ASTSingleMemberAnnotation n = (ASTSingleMemberAnnotation) jjtGetChild(0);

            if (n.jjtGetChild(0) instanceof ASTName) {
                ASTName annName = ((ASTName) n.jjtGetChild(0));

                if (annName.getImage().equals("SuppressWarnings")) {
                    List nodes = n.findChildrenOfType(ASTLiteral.class);
                    for (Iterator iter = nodes.iterator(); iter.hasNext();) {
                        ASTLiteral element = (ASTLiteral) iter.next();
                        if (element.hasImageEqualTo("\"PMD\"")
                                || element.hasImageEqualTo(ruleAnno)) {
                            return true;
                        }
                    }
                }
            }
        }
        return false;
    }

    /**
     * Accept the visitor.
     */
    public Object jjtAccept(JavaParserVisitor visitor, Object data) {
        return visitor.visit(this, data);
    }
}
