View Javadoc

1   /**
2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3    */
4   package net.sourceforge.pmd.lang.dfa;
5   
6   import java.util.HashMap;
7   import java.util.Map;
8   
9   /**
10   * @author raik
11   */
12  // TODO This should be an enum?
13  public class NodeType {
14  
15      public static final int IF_EXPR = 1;
16      public static final int IF_LAST_STATEMENT = 2;
17      public static final int IF_LAST_STATEMENT_WITHOUT_ELSE = 3;
18      public static final int ELSE_LAST_STATEMENT = 4;
19  
20      public static final int WHILE_EXPR = 10;
21      public static final int WHILE_LAST_STATEMENT = 11;
22  
23      public static final int SWITCH_START = 20;
24      public static final int CASE_LAST_STATEMENT = 21;
25      public static final int SWITCH_LAST_DEFAULT_STATEMENT = 22;
26      public static final int SWITCH_END = 23;
27  
28      public static final int FOR_INIT = 30;
29      public static final int FOR_EXPR = 31;
30      public static final int FOR_UPDATE = 32;
31      public static final int FOR_BEFORE_FIRST_STATEMENT = 33;
32      public static final int FOR_END = 34;
33  
34      public static final int DO_BEFORE_FIRST_STATEMENT = 40;
35      public static final int DO_EXPR = 41;
36  
37      public static final int RETURN_STATEMENT = 50;
38      public static final int BREAK_STATEMENT = 51;
39      public static final int CONTINUE_STATEMENT = 52;
40  
41      public static final int LABEL_STATEMENT = 60;
42      public static final int LABEL_LAST_STATEMENT = 61;
43  
44      // TODO - throw statements?
45      public static final int THROW_STATEMENT = 70;
46  
47      //Poor Man's Enum until we convert the class to real enum
48      private static final Map<Integer, String> typeMap = new HashMap<Integer, String>();
49      static {
50              typeMap.put(NodeType.IF_EXPR, "IF_EXPR");
51  	    typeMap.put(NodeType.IF_LAST_STATEMENT, "IF_LAST_STATEMENT");
52  	    typeMap.put(NodeType.IF_LAST_STATEMENT_WITHOUT_ELSE, "IF_LAST_STATEMENT_WITHOUT_ELSE");
53  	    typeMap.put(NodeType.ELSE_LAST_STATEMENT, "ELSE_LAST_STATEMENT");
54  	    typeMap.put(NodeType.WHILE_LAST_STATEMENT, "WHILE_LAST_STATEMENT");
55  	    typeMap.put(NodeType.WHILE_EXPR, "WHILE_EXPR");
56  	    typeMap.put(NodeType.SWITCH_START, "SWITCH_START");
57  	    typeMap.put(NodeType.CASE_LAST_STATEMENT, "CASE_LAST_STATEMENT");
58  	    typeMap.put(NodeType.SWITCH_LAST_DEFAULT_STATEMENT, "SWITCH_LAST_DEFAULT_STATEMENT");
59  	    typeMap.put(NodeType.SWITCH_END, "SWITCH_END");
60  	    typeMap.put(NodeType.FOR_INIT, "FOR_INIT");
61  	    typeMap.put(NodeType.FOR_EXPR, "FOR_EXPR");
62  	    typeMap.put(NodeType.FOR_UPDATE, "FOR_UPDATE");
63  	    typeMap.put(NodeType.FOR_BEFORE_FIRST_STATEMENT, "FOR_BEFORE_FIRST_STATEMENT");
64  	    typeMap.put(NodeType.FOR_END, "FOR_END");
65  	    typeMap.put(NodeType.DO_BEFORE_FIRST_STATEMENT, "DO_BEFORE_FIRST_STATEMENT");
66  	    typeMap.put(NodeType.DO_EXPR, "DO_EXPR");
67  	    typeMap.put(NodeType.RETURN_STATEMENT, "RETURN_STATEMENT");
68  	    typeMap.put(NodeType.BREAK_STATEMENT, "BREAK_STATEMENT");
69  	    typeMap.put(NodeType.CONTINUE_STATEMENT, "CONTINUE_STATEMENT");
70  	    typeMap.put(NodeType.LABEL_STATEMENT, "LABEL_STATEMENT");
71  	    typeMap.put(NodeType.LABEL_LAST_STATEMENT, "LABEL_END");
72  	    typeMap.put(NodeType.THROW_STATEMENT, "THROW_STATEMENT");
73      }
74  
75  
76      public static Map<Integer, String> getTypeMap() {
77  	return typeMap;
78      } 
79      public static String stringFromType(int intype) {
80          if(-1 == intype) { return "<ROOT>" ; }
81  	if (!typeMap.containsKey(intype) ) {
82  	    throw new RuntimeException("Couldn't find NodeType type id " + intype);
83  	}
84  	return typeMap.get(intype);
85      } 
86  }