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

📄 abstractscopetest.java

📁 检查Java程序漏洞
💻 JAVA
字号:
/** * BSD-style license; for more info see http://pmd.sourceforge.net/license.html*/package test.net.sourceforge.pmd.symboltable;import junit.framework.TestCase;import net.sourceforge.pmd.ast.ASTVariableDeclaratorId;import net.sourceforge.pmd.ast.SimpleNode;import net.sourceforge.pmd.symboltable.AbstractScope;import net.sourceforge.pmd.symboltable.ClassScope;import net.sourceforge.pmd.symboltable.NameDeclaration;import net.sourceforge.pmd.symboltable.NameOccurrence;import net.sourceforge.pmd.symboltable.Scope;import net.sourceforge.pmd.symboltable.VariableNameDeclaration;import java.util.Iterator;public class AbstractScopeTest extends TestCase {    // A helper class to stub out AbstractScope's abstract stuff    private class MyScope extends AbstractScope {        protected NameDeclaration findVariableHere(NameOccurrence occ) {            for (Iterator i = variableNames.keySet().iterator(); i.hasNext();) {                NameDeclaration decl = (NameDeclaration) i.next();                if (decl.getImage().equals(occ.getImage())) {                    return decl;                }            }            return null;        }    }    // Another helper class to test the search for a class scope behavior    private class IsEnclosingClassScope extends ClassScope {        public IsEnclosingClassScope(String name) {            super(name);        }        protected NameDeclaration findVariableHere(NameOccurrence occ) {            return null;        }        public ClassScope getEnclosingClassScope() {            return this;        }    }    public void testAccessors() {        Scope scope = new MyScope();        MyScope parent = new MyScope();        scope.setParent(parent);        assertEquals(parent, scope.getParent());        assertTrue(!scope.getVariableDeclarations(false).keySet().iterator().hasNext());        assertTrue(scope.getVariableDeclarations(true).isEmpty());    }    public void testEnclClassScopeGetsDelegatedRight() {        Scope scope = new MyScope();        Scope isEncl = new IsEnclosingClassScope("Foo");        scope.setParent(isEncl);        assertEquals(isEncl, scope.getEnclosingClassScope());    }    public void testAdd() {        Scope scope = new MyScope();        ASTVariableDeclaratorId node = new ASTVariableDeclaratorId(1);        node.setImage("foo");        VariableNameDeclaration decl = new VariableNameDeclaration(node);        scope.addDeclaration(decl);        assertTrue(scope.contains(new NameOccurrence(new SimpleNode(1), "foo")));    }}

⌨️ 快捷键说明

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