1 package net.sourceforge.pmd.symboltable;
2
3 import net.sourceforge.pmd.ast.ASTAssignmentOperator;
4 import net.sourceforge.pmd.ast.ASTPrimaryExpression;
5 import net.sourceforge.pmd.ast.SimpleNode;
6
7 public class NameOccurrence {
8
9 private SimpleNode location;
10 private String image;
11 private NameOccurrence qualifiedName;
12 private boolean isMethodOrConstructorInvocation;
13
14 public NameOccurrence(SimpleNode location, String image) {
15 this.location = location;
16 this.image = image;
17 }
18
19 public void setIsMethodOrConstructorInvocation() {
20 isMethodOrConstructorInvocation = true;
21 }
22
23 public boolean isMethodOrConstructorInvocation() {
24 return isMethodOrConstructorInvocation;
25 }
26
27 public void setNameWhichThisQualifies(NameOccurrence qualifiedName) {
28 this.qualifiedName = qualifiedName;
29 }
30
31 public NameOccurrence getNameForWhichThisIsAQualifier() {
32 return qualifiedName;
33 }
34
35 public SimpleNode getLocation() {
36 return location;
37 }
38
39 public boolean isOnLeftHandSide() {
40 SimpleNode primaryExpression;
41 if (location.jjtGetParent() instanceof ASTPrimaryExpression) {
42 primaryExpression = (SimpleNode) location.jjtGetParent().jjtGetParent();
43 } else if (location.jjtGetParent().jjtGetParent() instanceof ASTPrimaryExpression) {
44 primaryExpression = (SimpleNode) location.jjtGetParent().jjtGetParent().jjtGetParent();
45 } else {
46 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());
47 }
48
49 return primaryExpression.jjtGetNumChildren() > 1 && primaryExpression.jjtGetChild(1) instanceof ASTAssignmentOperator;
50 }
51
52 public Scope getScope() {
53 return location.getScope();
54 }
55
56
57 public int getBeginLine() {
58 return location.getBeginLine();
59 }
60
61 public boolean isThisOrSuper() {
62 return image.equals("this") || image.equals("super");
63 }
64
65 public boolean equals(Object o) {
66 NameOccurrence n = (NameOccurrence) o;
67 return n.getImage().equals(getImage());
68 }
69
70 public String getImage() {
71 return image;
72 }
73
74 public int hashCode() {
75 return getImage().hashCode();
76 }
77
78 public String toString() {
79 return getImage() + ":" + location.getBeginLine() + ":" + location.getClass();
80 }
81 }
This page was automatically generated by Maven