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