⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 abstractscope.java

📁 检查Java程序漏洞
💻 JAVA
字号:
/** * BSD-style license; for more info see http://pmd.sourceforge.net/license.html*/package net.sourceforge.pmd.symboltable;import net.sourceforge.pmd.util.Applier;import java.util.ArrayList;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Map;/** * Provides behavior common to all Scopes */public abstract class AbstractScope implements Scope {    private Scope parent;    protected Map variableNames = new HashMap();    protected Map methodNames = new HashMap();    public ClassScope getEnclosingClassScope() {        return parent.getEnclosingClassScope();    }    public void setParent(Scope parent) {        this.parent = parent;    }    public Scope getParent() {        return parent;    }    public void addDeclaration(VariableNameDeclaration variableDecl) {        if (variableNames.containsKey(variableDecl)) {            throw new RuntimeException("Variable " + variableDecl + " is already in the symbol table");        }        variableNames.put(variableDecl, new ArrayList());    }    public void addDeclaration(MethodNameDeclaration methodDecl) {        parent.addDeclaration(methodDecl);    }    public boolean contains(NameOccurrence occurrence) {        return findVariableHere(occurrence) != null;    }    public Map getVariableDeclarations(boolean lookingForUsed) {        VariableUsageFinderFunction f = new VariableUsageFinderFunction(variableNames, lookingForUsed);        Applier.apply(f, variableNames.keySet().iterator());        return f.getUsed();    }    public NameDeclaration addVariableNameOccurrence(NameOccurrence occurrence) {        NameDeclaration decl = findVariableHere(occurrence);        if (decl != null && !occurrence.isThisOrSuper()) {            List nameOccurrences = (List) variableNames.get(decl);            nameOccurrences.add(occurrence);        }        return decl;    }    protected abstract NameDeclaration findVariableHere(NameOccurrence occurrence);    protected String glomNames() {        String result = "";        for (Iterator i = variableNames.keySet().iterator(); i.hasNext();) {            result += i.next().toString() + ",";        }        return result;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -