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

net.sourceforge.pmd.lang.modelica.ast.AbstractModelicaNode Maven / Gradle / Ivy

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

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

import net.sourceforge.pmd.lang.ast.AstVisitor;
import net.sourceforge.pmd.lang.ast.impl.javacc.AbstractJjtreeNode;
import net.sourceforge.pmd.lang.modelica.resolver.ModelicaScope;

/**
 * Abstract base class for all nodes parsed by {@link ModelicaParser}.
 *
 * Please note that some of these nodes are autogenerated and placed to
 * pmd-modelica/target/generated-sources/javacc by the build script. Those
 * located here are deleted from autogenerated sources after build.
 *
 * @see ModelicaNode for public API.
 */
abstract class AbstractModelicaNode extends AbstractJjtreeNode implements ModelicaNode {

    private ModelicaScope ownScope;

    AbstractModelicaNode(int id) {
        super(id);
    }


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

    protected abstract  R acceptModelicaVisitor(ModelicaVisitor visitor, P data);

    @Override
    public String getXPathNodeName() {
        return getClass().getSimpleName().substring(3);
    }

    @Override
    public ModelicaScope getContainingScope() {
        return getParent().getMostSpecificScope();
    }

    @Override
    public ModelicaScope getMostSpecificScope() {
        if (ownScope == null) {
            return getContainingScope();
        } else {
            return ownScope;
        }
    }

    /**
     * For resolver, set the lexical scope defined by this node, if any.
     *
     * @param scope Scope defined by this specific node
     */
    void setOwnScope(ModelicaScope scope) {
        ownScope = scope;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy