All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sourceforge.pmd.lang.html.ast.AbstractHtmlNode Maven / Gradle / Ivy

The newest version!
/*
 * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
 */


package net.sourceforge.pmd.lang.html.ast;

import org.jsoup.nodes.Node;

import net.sourceforge.pmd.lang.ast.AstVisitor;
import net.sourceforge.pmd.lang.ast.impl.AbstractNode;
import net.sourceforge.pmd.lang.document.TextRegion;

abstract class AbstractHtmlNode extends AbstractNode, HtmlNode> implements HtmlNode {

    protected final T node;
    protected int startOffset;
    protected int endOffset;

    AbstractHtmlNode(T node) {
        this.node = node;
    }

    public String getNodeName() {
        return node.nodeName();
    }

    @Override
    public String getXPathNodeName() {
        // note: this might return "#text" or "#comment" as well
        return node.nodeName();
    }

    @Override
    public TextRegion getTextRegion() {
        return TextRegion.fromBothOffsets(startOffset, endOffset);
    }

    @Override
    @SuppressWarnings("unchecked")
    public final  R acceptVisitor(AstVisitor visitor, P data) {
        if (visitor instanceof HtmlVisitor) {
            return this.acceptHtmlVisitor((HtmlVisitor) visitor, data);
        }
        return visitor.cannotVisit(this, data);
    }

    protected abstract  R acceptHtmlVisitor(HtmlVisitor visitor, P data);

    // overridden to make them visible
    @Override
    protected void addChild(AbstractHtmlNode child, int index) {
        super.addChild(child, index);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy