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

net.sourceforge.pmd.lang.ecmascript.ast.AbstractEcmascriptNode Maven / Gradle / Ivy

There is a newer version: 7.7.0
Show newest version
/*
 * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
 */

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

import org.mozilla.javascript.ast.AstNode;

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

abstract class AbstractEcmascriptNode extends AbstractNode, EcmascriptNode> implements EcmascriptNode {

    protected final T node;

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

    @Override
    protected void addChild(AbstractEcmascriptNode child, int index) {
        super.addChild(child, index);
    }

    @Override
    public TextRegion getTextRegion() {
        return TextRegion.fromOffsetLength(node.getAbsolutePosition(), node.getLength());
    }

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

    protected abstract  R acceptJsVisitor(EcmascriptVisitor visitor, P data);

    @Override
    public String getJsDoc() {
        return node.getJsDoc();
    }

    @Override
    public boolean hasSideEffects() {
        return node.hasSideEffects();
    }

    @Override
    public String getXPathNodeName() {
        return node.shortName();
    }

    protected void setTrailingCommaExists(boolean b) {
        // empty. Only needed for ASTArrayLiteral and ASTObjectLiteral
        // This method is protected to not clutter the public API via a interface
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy