View Javadoc
1   /**
2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3    */
4   
5   /* Generated By:JJTree: Do not edit this line. ASTVariableOrConstantDeclaratorId.java Version 4.1 */
6   /* JavaCCOptions:MULTI=true,NODE_USES_PARSER=true,VISITOR=true,TRACK_TOKENS=false,NODE_PREFIX=AST,NODE_EXTENDS=,NODE_FACTORY= */
7   package net.sourceforge.pmd.lang.plsql.ast;
8   
9   import java.util.List;
10  
11  import net.sourceforge.pmd.lang.ast.Node;
12  import net.sourceforge.pmd.lang.symboltable.NameDeclaration;
13  import net.sourceforge.pmd.lang.symboltable.NameOccurrence;
14  
15  public class ASTVariableOrConstantDeclaratorId extends net.sourceforge.pmd.lang.plsql.ast.AbstractPLSQLNode{
16    public ASTVariableOrConstantDeclaratorId(int id) {
17      super(id);
18    }
19  
20    public ASTVariableOrConstantDeclaratorId(PLSQLParser p, int id) {
21      super(p, id);
22    }
23  
24  
25    /** Accept the visitor. **/
26    public Object jjtAccept(PLSQLParserVisitor visitor, Object data) {
27      return visitor.visit(this, data);
28    }
29  
30    private int arrayDepth;
31    private NameDeclaration nameDeclaration;
32  
33    public NameDeclaration getNameDeclaration() {
34        return nameDeclaration;
35    }
36  
37    public void setNameDeclaration(NameDeclaration decl) {
38        nameDeclaration = decl;
39    }
40  
41    public List<NameOccurrence> getUsages() {
42        return getScope().getDeclarations().get(nameDeclaration);
43    }
44  
45    public void bumpArrayDepth() {
46        arrayDepth++;
47    }
48  
49    public int getArrayDepth() {
50        return arrayDepth;
51    }
52  
53    public boolean isArray() {
54        return arrayDepth > 0;
55    }
56  
57    public Node getTypeNameNode() {
58        if (jjtGetParent() instanceof ASTFormalParameter) {
59            return findTypeNameNode(jjtGetParent());
60        } 
61  	else if (jjtGetParent().jjtGetParent() instanceof ASTVariableOrConstantDeclaration 
62  		|| 
63  		jjtGetParent().jjtGetParent() instanceof ASTFieldDeclaration
64  		) 
65  	{
66            return findTypeNameNode(jjtGetParent().jjtGetParent());
67        }
68        throw new RuntimeException("Don't know how to get the type for anything other than ASTLocalVariableDeclaration/ASTFormalParameter/ASTFieldDeclaration");
69    }
70  
71    public ASTDatatype getTypeNode() {
72        if (jjtGetParent() instanceof ASTFormalParameter) {
73            return ((ASTFormalParameter) jjtGetParent()).getTypeNode();
74        } else {
75            Node n = jjtGetParent().jjtGetParent();
76            if (n instanceof ASTVariableOrConstantDeclaration || n instanceof ASTFieldDeclaration) {
77                return n.getFirstChildOfType(ASTDatatype.class);
78            }
79        }
80        throw new RuntimeException("Don't know how to get the type for anything other than ASTLocalVariableDeclaration/ASTFormalParameter/ASTFieldDeclaration");
81    }
82  
83    private Node findTypeNameNode(Node node) {
84        ASTDatatype typeNode = (ASTDatatype) node.jjtGetChild(0);
85        return typeNode.jjtGetChild(0);
86    }
87  
88  }
89  /* JavaCC - OriginalChecksum=935037739d9116b8c87f25deb4faa2d0 (do not edit this line) */