1 32 33 package com.jeantessier.classreader; 34 35 import java.io.*; 36 import java.util.*; 37 38 public class TextPrinter extends Printer { 39 private boolean top = true; 40 41 public TextPrinter(PrintWriter out) { 42 super(out); 43 } 44 45 public void visitClassfile(Classfile classfile) { 46 classfile.getConstantPool().accept(this); 47 48 append(classfile.getDeclaration()).append(" {").eol(); 49 50 Iterator i; 51 52 i = classfile.getAllFields().iterator(); 53 while (i.hasNext()) { 54 ((Visitable) i.next()).accept(this); 55 } 56 57 i = classfile.getAllMethods().iterator(); 58 while (i.hasNext()) { 59 ((Visitable) i.next()).accept(this); 60 } 61 62 append("}").eol(); 63 } 64 65 public void visitClass_info(Class_info entry) { 66 if (top) { 67 top = false; 68 append(currentCount()).append(": "); 69 append("Class "); 70 entry.getRawName().accept(this); 71 eol(); 72 top = true; 73 } else { 74 entry.getRawName().accept(this); 75 } 76 } 77 78 public void visitFieldRef_info(FieldRef_info entry) { 79 Class_info c = entry.getRawClass(); 80 NameAndType_info nat = entry.getRawNameAndType(); 81 82 if (top) { 83 top = false; 84 append(currentCount()).append(": "); 85 append("Field "); 86 nat.getRawType().accept(this); 87 append(" "); 88 c.accept(this); 89 append("."); 90 nat.getRawName().accept(this); 91 eol(); 92 top = true; 93 } else { 94 nat.getRawType().accept(this); 95 append(" "); 96 c.accept(this); 97 append("."); 98 nat.getRawName().accept(this); 99 } 100 } 101 102 public void visitMethodRef_info(MethodRef_info entry) { 103 Class_info c = entry.getRawClass(); 104 NameAndType_info nat = entry.getRawNameAndType(); 105 106 if (top) { 107 top = false; 108 append(currentCount()).append(": "); 109 append("Method "); 110 c.accept(this); 111 append("."); 112 nat.getRawName().accept(this); 113 nat.getRawType().accept(this); 114 eol(); 115 top = true; 116 } else { 117 c.accept(this); 118 append("."); 119 nat.getRawName().accept(this); 120 nat.getRawType().accept(this); 121 } 122 } 123 124 public void visitInterfaceMethodRef_info(InterfaceMethodRef_info entry) { 125 Class_info c = entry.getRawClass(); 126 NameAndType_info nat = entry.getRawNameAndType(); 127 128 if (top) { 129 top = false; 130 append(currentCount()).append(": "); 131 append("Interface Method "); 132 c.accept(this); 133 append("."); 134 nat.getRawName().accept(this); 135 nat.getRawType().accept(this); 136 eol(); 137 top = true; 138 } else { 139 c.accept(this); 140 append("."); 141 nat.getRawName().accept(this); 142 nat.getRawType().accept(this); 143 } 144 } 145 146 public void visitString_info(String_info entry) { 147 if (top) { 148 top = false; 149 append(currentCount()).append(": String "); 150 entry.getRawValue().accept(this); 151 eol(); 152 top = true; 153 } else { 154 entry.getRawValue().accept(this); 155 } 156 } 157 158 public void visitInteger_info(Integer_info entry) { 159 if (top) { 160 append(currentCount()).append(": Integer ").append(entry.getValue()).eol(); 161 } else { 162 append(entry.getValue()); 163 } 164 } 165 166 public void visitFloat_info(Float_info entry) { 167 if (top) { 168 append(currentCount()).append(": Float ").append(entry.getValue()).eol(); 169 } else { 170 append(entry.getValue()); 171 } 172 } 173 174 public void visitLong_info(Long_info entry) { 175 if (top) { 176 append(currentCount()).append(": Long ").append(entry.getValue()).eol(); 177 } else { 178 append(entry.getValue()); 179 } 180 } 181 182 public void visitDouble_info(Double_info entry) { 183 if (top) { 184 append(currentCount()).append(": Double ").append(entry.getValue()).eol(); 185 } else { 186 append(entry.getValue()); 187 } 188 } 189 190 public void visitNameAndType_info(NameAndType_info entry) { 191 if (top) { 192 top = false; 193 append(currentCount()).append(": Name and Type "); 194 entry.getRawName().accept(this); 195 append(" "); 196 entry.getRawType().accept(this); 197 eol(); 198 top = true; 199 } else { 200 entry.getRawName().accept(this); 201 append(" "); 202 entry.getRawType().accept(this); 203 } 204 } 205 206 public void visitUTF8_info(UTF8_info entry) { 207 if (top) { 208 append(currentCount()).append(": \"").append(entry.getValue()).append("\"").eol(); 209 } else { 210 append(entry.getValue()); 211 } 212 } 213 214 public void visitField_info(Field_info entry) { 215 append(" ").append(entry.getDeclaration()).append(";").eol(); 216 } 217 218 public void visitMethod_info(Method_info entry) { 219 append(" ").append(entry.getDeclaration()).append(";").eol(); 220 } 221 } 222 | Popular Tags |