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

net.sourceforge.pmd.lang.plsql.symboltable.MethodScope 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.plsql.symboltable;

import java.util.Set;

import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.plsql.ast.ASTName;
import net.sourceforge.pmd.lang.plsql.ast.InternalApiBridge;
import net.sourceforge.pmd.lang.plsql.ast.PLSQLNode;
import net.sourceforge.pmd.lang.symboltable.NameDeclaration;
import net.sourceforge.pmd.lang.symboltable.NameOccurrence;

public class MethodScope extends MethodOrLocalScope {

    private final PLSQLNode node;

    public MethodScope(PLSQLNode node) {
        this.node = node;
    }

    public MethodScope getEnclosingMethodScope() {
        return this;
    }

    @Override
    public Set addNameOccurrence(NameOccurrence occ) {
        PLSQLNameOccurrence occurrence = (PLSQLNameOccurrence) occ;
        Set declarations = findVariableHere(occurrence);
        if (!declarations.isEmpty() && !occurrence.isThisOrSuper()) {
            for (NameDeclaration decl : declarations) {
                getVariableDeclarations().get(decl).add(occurrence);
                Node n = occurrence.getLocation();
                if (n instanceof ASTName) {
                    InternalApiBridge.setNameDeclaration((ASTName) n, decl);
                } // TODO what to do with PrimarySuffix case?
            }
        }
        return declarations;
    }

    public String getName() {
        return node.getChild(1).getCanonicalImage();
    }

    @Override
    public String toString() {
        return "MethodScope:" + getVariableDeclarations().keySet();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy