1 package antlr.preprocessor; 2 3 9 10 import antlr.collections.impl.IndexedVector; 11 12 import java.util.Hashtable ; 13 import java.util.Enumeration ; 14 15 class Rule { 16 protected String name; 17 protected String block; 18 protected String args; 19 protected String returnValue; 20 protected String throwsSpec; 21 protected String initAction; 22 protected IndexedVector options; 23 protected String visibility; 24 protected Grammar enclosingGrammar; 25 protected boolean bang = false; 26 27 public Rule(String n, String b, IndexedVector options, Grammar gr) { 28 name = n; 29 block = b; 30 this.options = options; 31 setEnclosingGrammar(gr); 32 } 33 34 public String getArgs() { 35 return args; 36 } 37 38 public boolean getBang() { 39 return bang; 40 } 41 42 public String getName() { 43 return name; 44 } 45 46 public String getReturnValue() { 47 return returnValue; 48 } 49 50 public String getVisibility() { 51 return visibility; 52 } 53 54 59 public boolean narrowerVisibility(Rule rule) { 60 if (visibility.equals("public")) { 61 if (!rule.equals("public")) { 62 return true; } 64 return false; 65 } 66 else if (visibility.equals("protected")) { 67 if (rule.equals("private")) { 68 return true; } 70 return false; 71 } 72 else if (visibility.equals("private")) { 73 return false; } 75 return false; 76 } 77 78 86 public boolean sameSignature(Rule rule) { 87 boolean nSame = true; 88 boolean aSame = true; 89 boolean rSame = true; 90 91 nSame = name.equals(rule.getName()); 92 if (args != null) { 93 aSame = args.equals(rule.getArgs()); 94 } 95 if (returnValue != null) { 96 rSame = returnValue.equals(rule.getReturnValue()); 97 } 98 return nSame && aSame && rSame; 99 } 100 101 public void setArgs(String a) { 102 args = a; 103 } 104 105 public void setBang() { 106 bang = true; 107 } 108 109 public void setEnclosingGrammar(Grammar g) { 110 enclosingGrammar = g; 111 } 112 113 public void setInitAction(String a) { 114 initAction = a; 115 } 116 117 public void setOptions(IndexedVector options) { 118 this.options = options; 119 } 120 121 public void setReturnValue(String ret) { 122 returnValue = ret; 123 } 124 125 public void setThrowsSpec(String t) { 126 throwsSpec = t; 127 } 128 129 public void setVisibility(String v) { 130 visibility = v; 131 } 132 133 public String toString() { 134 String s = ""; 135 String retString = returnValue == null ? "" : "returns " + returnValue; 136 String argString = args == null ? "" : args; 137 String bang = getBang() ? "!" : ""; 138 139 s += visibility == null ? "" : visibility + " "; 140 s += name + bang + argString + " " + retString + throwsSpec; 141 if (options != null) { 142 s += System.getProperty("line.separator") + 143 "options {" + 144 System.getProperty("line.separator"); 145 for (Enumeration e = options.elements(); e.hasMoreElements();) { 146 s += (Option)e.nextElement() + System.getProperty("line.separator"); 147 } 148 s += "}" + System.getProperty("line.separator"); 149 } 150 if (initAction != null) { 151 s += initAction + System.getProperty("line.separator"); 152 } 153 s += block; 154 return s; 155 } 156 } 157 | Popular Tags |