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

📄 localscopetest.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.ASTName;import net.sourceforge.pmd.ast.ASTPrimaryPrefix;import net.sourceforge.pmd.ast.ASTVariableDeclaratorId;import net.sourceforge.pmd.symboltable.LocalScope;import net.sourceforge.pmd.symboltable.NameOccurrence;import net.sourceforge.pmd.symboltable.VariableNameDeclaration;public class LocalScopeTest extends TestCase {    private class MyASTVariableDeclaratorId extends ASTVariableDeclaratorId {        public MyASTVariableDeclaratorId(int x) {            super(x);        }        public boolean isExceptionBlockParameter() {            return true;        }    }    public void testNameWithThisOrSuperIsNotFlaggedAsUnused() {        LocalScope scope = new LocalScope();        ASTName name = new ASTName(1);        name.setImage("foo");        ASTPrimaryPrefix prefix = new ASTPrimaryPrefix(2);        prefix.setUsesThisModifier();        name.jjtAddChild(prefix, 1);        NameOccurrence occ = new NameOccurrence(name, "foo");        scope.addVariableNameOccurrence(occ);        assertTrue(!scope.getVariableDeclarations(false).keySet().iterator().hasNext());    }    public void testNameWithSuperIsNotFlaggedAsUnused() {        LocalScope scope = new LocalScope();        ASTName name = new ASTName(1);        name.setImage("foo");        ASTPrimaryPrefix prefix = new ASTPrimaryPrefix(2);        prefix.setUsesSuperModifier();        name.jjtAddChild(prefix, 1);        NameOccurrence occ = new NameOccurrence(name, "foo");        scope.addVariableNameOccurrence(occ);        assertTrue(!scope.getVariableDeclarations(false).keySet().iterator().hasNext());    }    public void testExceptionParamNameIsDiscarded() {        ASTVariableDeclaratorId node = new MyASTVariableDeclaratorId(1);        VariableNameDeclaration decl = new VariableNameDeclaration(node);        LocalScope scope = new LocalScope();        scope.addDeclaration(decl);        assertTrue(!scope.getVariableDeclarations(false).keySet().iterator().hasNext());    }}

⌨️ 快捷键说明

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