1 23 24 25 26 31 32 package com.sun.jdo.spi.persistence.support.ejb.ejbqlc; 33 34 import persistence.antlr.Token; 35 import persistence.antlr.CommonAST; 36 import persistence.antlr.collections.AST; 37 38 52 public class EJBQLAST 53 extends CommonAST 54 implements Cloneable 55 { 56 57 private static char SEPARATOR = '\n'; 58 59 60 private static String INDENT = " "; 62 63 protected int line = 0; 64 65 66 protected int column = 0; 67 68 69 protected transient Object typeInfo; 70 71 72 public EJBQLAST() {} 73 74 75 public EJBQLAST(int type, String text, Object typeInfo) 76 { 77 initialize(type, text, typeInfo); 78 } 79 80 81 public EJBQLAST(EJBQLAST ast) 82 { 83 initialize(ast); 84 } 85 86 87 public void initialize(Token t) 88 { 89 setType(t.getType()); 90 setText(t.getText()); 91 setLine(t.getLine()); 92 setColumn(t.getColumn()); 93 } 94 95 96 public void initialize(int type, String text, Object typeInfo) 97 { 98 setType(type); 99 setText(text); 100 setTypeInfo(typeInfo); 101 } 102 103 104 public void initialize(AST _ast) 105 { 106 EJBQLAST ast = (EJBQLAST)_ast; 107 setType(ast.getType()); 108 setText(ast.getText()); 109 setLine(ast.getLine()); 110 setColumn(ast.getColumn()); 111 setTypeInfo(ast.getTypeInfo()); 112 } 113 114 115 public void setLine(int line) 116 { 117 this.line = line; 118 } 119 120 121 public int getLine() 122 { 123 return line; 124 } 125 126 127 public void setColumn(int column) 128 { 129 this.column = column; 130 } 131 132 133 public int getColumn() 134 { 135 return column; 136 } 137 138 139 public void setTypeInfo(Object typeInfo) 140 { 141 this.typeInfo = typeInfo; 142 } 143 144 145 public Object getTypeInfo() 146 { 147 return typeInfo; 148 } 149 150 154 public String toString() 155 { 156 Object typeInfo = getTypeInfo(); 157 StringBuffer repr = new StringBuffer (); 158 repr.append((getText() == null ? "null" : getText())); repr.append(" ["); repr.append(getType()); 163 repr.append(", ("); repr.append(getLine() + "/" + getColumn()); repr.append(")"); repr.append(", "); repr.append(typeInfo); 170 repr.append("]"); return repr.toString(); 172 } 173 174 184 public String getTreeRepr(String title) 185 { 186 return title + this.getTreeRepr(0); 187 } 188 189 190 private String getTreeRepr(int level) 191 { 192 StringBuffer repr = new StringBuffer (); 193 repr.append(SEPARATOR); 195 repr.append(getIndent(level)); 196 repr.append(this.toString()); 197 for (EJBQLAST node = (EJBQLAST)this.getFirstChild(); 199 node != null; 200 node = (EJBQLAST)node.getNextSibling()) { 201 repr.append(node.getTreeRepr(level+1)); 202 } 203 return repr.toString(); 204 } 205 206 207 private String getIndent(int level) 208 { 209 StringBuffer buf = new StringBuffer (); 210 for (int i = 0; i < level; i++) { 211 buf.append(INDENT); 212 } 213 return buf.toString(); 214 } 215 216 224 protected Object clone() 225 throws CloneNotSupportedException 226 { 227 EJBQLAST clone = (EJBQLAST)super.clone(); 228 clone.setFirstChild(null); 229 clone.setNextSibling(null); 230 return clone; 231 } 232 233 } 234 235 | Popular Tags |