nameoccurrence.java

来自「检查Java程序漏洞」· Java 代码 · 共 85 行

JAVA
85
字号
/** * BSD-style license; for more info see http://pmd.sourceforge.net/license.html*/package net.sourceforge.pmd.symboltable;import net.sourceforge.pmd.ast.ASTAssignmentOperator;import net.sourceforge.pmd.ast.ASTPrimaryExpression;import net.sourceforge.pmd.ast.SimpleNode;public class NameOccurrence {    private SimpleNode location;    private String image;    private NameOccurrence qualifiedName;    private boolean isMethodOrConstructorInvocation;    public NameOccurrence(SimpleNode location, String image) {        this.location = location;        this.image = image;    }    public void setIsMethodOrConstructorInvocation() {        isMethodOrConstructorInvocation = true;    }    public boolean isMethodOrConstructorInvocation() {        return isMethodOrConstructorInvocation;    }    public void setNameWhichThisQualifies(NameOccurrence qualifiedName) {        this.qualifiedName = qualifiedName;    }    public NameOccurrence getNameForWhichThisIsAQualifier() {        return qualifiedName;    }    public SimpleNode getLocation() {      return location;    }    public boolean isOnLeftHandSide() {        SimpleNode primaryExpression;        if (location.jjtGetParent() instanceof ASTPrimaryExpression) {            primaryExpression = (SimpleNode) location.jjtGetParent().jjtGetParent();        } else if (location.jjtGetParent().jjtGetParent() instanceof ASTPrimaryExpression) {            primaryExpression = (SimpleNode) location.jjtGetParent().jjtGetParent().jjtGetParent();        } else {            throw new RuntimeException("Found a NameOccurrence that didn't have an ASTPrimary Expression as parent or grandparent.  Parent = " + location.jjtGetParent() + " and grandparent = " + location.jjtGetParent().jjtGetParent());        }        return primaryExpression.jjtGetNumChildren() > 1 && primaryExpression.jjtGetChild(1) instanceof ASTAssignmentOperator;    }    public Scope getScope() {        return location.getScope();    }    public int getBeginLine() {        return location.getBeginLine();    }    public boolean isThisOrSuper() {        return image.equals("this") || image.equals("super");    }    public boolean equals(Object o) {        NameOccurrence n = (NameOccurrence) o;        return n.getImage().equals(getImage());    }    public String getImage() {        return image;    }    public int hashCode() {        return getImage().hashCode();    }    public String toString() {        return getImage() + ":" + location.getBeginLine() + ":" + location.getClass();    }}

⌨️ 快捷键说明

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