1
2
3
4 package net.sourceforge.pmd.lang.plsql.symboltable;
5
6 import java.util.List;
7 import java.util.logging.Level;
8 import java.util.logging.Logger;
9
10 import net.sourceforge.pmd.lang.plsql.ast.ASTPrimaryExpression;
11 import net.sourceforge.pmd.lang.plsql.ast.PLSQLParserVisitorAdapter;
12 import net.sourceforge.pmd.lang.symboltable.NameDeclaration;
13 import net.sourceforge.pmd.lang.symboltable.Scope;
14
15 public class OccurrenceFinder extends PLSQLParserVisitorAdapter {
16 private final static Logger LOGGER = Logger.getLogger(OccurrenceFinder.class.getName());
17
18 public Object visit(ASTPrimaryExpression node, Object data) {
19 NameFinder nameFinder = new NameFinder(node);
20
21
22
23 NameDeclaration decl = null;
24
25 List<PLSQLNameOccurrence> names = nameFinder.getNames();
26 for (PLSQLNameOccurrence occ: names) {
27 Search search = new Search(occ);
28 if (decl == null) {
29
30 search.execute();
31 decl = search.getResult();
32 if (decl == null) {
33
34
35
36 break;
37 }
38 } else {
39
40 Scope scope = decl.getScope();
41 if (null == scope)
42 {
43 if (LOGGER.isLoggable(Level.FINEST)) {
44 LOGGER.finest("NameOccurrence has no Scope:"
45 + decl.getClass().getCanonicalName()
46 +"=>"+decl.getImage()
47 );
48 }
49 break;
50 }
51 search.execute(scope);
52 decl = search.getResult();
53
54 if (decl == null) {
55
56
57
58
59
60
61
62
63
64 break;
65 }
66 }
67 }
68 return super.visit(node, data);
69 }
70
71 }