1.1 --- a/javap/src/main/java/sun/tools/javap/JavapPrinter.java Fri Nov 09 21:33:22 2012 +0100
1.2 +++ b/javap/src/main/java/sun/tools/javap/JavapPrinter.java Sat Nov 10 07:27:09 2012 +0100
1.3 @@ -37,874 +37,4 @@
1.4 * @author Sucheta Dambalkar
1.5 */
1.6 public class JavapPrinter {
1.7 - JavapEnvironment env;
1.8 - ClassData cls;
1.9 - byte[] code;
1.10 - String lP= "";
1.11 - PrintWriter out;
1.12 -
1.13 - public JavapPrinter(InputStream cname, PrintWriter out, JavapEnvironment env){
1.14 - this.out = out;
1.15 - this.cls = new ClassData(cname);
1.16 - this.env = env;
1.17 - }
1.18 -
1.19 - /**
1.20 - * Entry point to print class file information.
1.21 - */
1.22 - public void print(){
1.23 - printclassHeader();
1.24 - printfields();
1.25 - printMethods();
1.26 - printend();
1.27 - }
1.28 -
1.29 - /**
1.30 - * Print a description of the class (not members).
1.31 - */
1.32 - public void printclassHeader(){
1.33 - String srcName="";
1.34 - if ((srcName = cls.getSourceName()) != "null") // requires debug info
1.35 - out.println("Compiled from " + javaclassname(srcName));
1.36 -
1.37 - if(cls.isInterface()) {
1.38 - // The only useful access modifier of an interface is
1.39 - // public; interfaces are always marked as abstract and
1.40 - // cannot be final.
1.41 - out.print((cls.isPublic()?"public ":"") +
1.42 - "interface "+ javaclassname(cls.getClassName()));
1.43 - }
1.44 - else if(cls.isClass()) {
1.45 - String []accflags = cls.getAccess();
1.46 - printAccess(accflags);
1.47 - out.print("class "+ javaclassname(cls.getClassName()));
1.48 -
1.49 - if(cls.getSuperClassName() != null){
1.50 - out.print(" extends " + javaclassname(cls.getSuperClassName()));
1.51 - }
1.52 - }
1.53 -
1.54 - String []interfacelist = cls.getSuperInterfaces();
1.55 - if(interfacelist.length > 0){
1.56 - if(cls.isClass()) {
1.57 - out.print(" implements ");
1.58 - }
1.59 - else if(cls.isInterface()){
1.60 - out.print(" extends ");
1.61 - }
1.62 -
1.63 - for(int j = 0; j < interfacelist.length; j++){
1.64 - out.print(javaclassname(interfacelist[j]));
1.65 -
1.66 - if((j+1) < interfacelist.length) {
1.67 - out.print(",");
1.68 - }
1.69 - }
1.70 - }
1.71 -
1.72 - // Print class attribute information.
1.73 - if((env.showallAttr) || (env.showVerbose)){
1.74 - printClassAttributes();
1.75 - }
1.76 - // Print verbose output.
1.77 - if(env.showVerbose){
1.78 - printverbosecls();
1.79 - }
1.80 - out.println("{");
1.81 - }
1.82 -
1.83 - /**
1.84 - * Print verbose output.
1.85 - */
1.86 - public void printverbosecls(){
1.87 - out.println(" minor version: "+cls.getMinor_version());
1.88 - out.println(" major version: "+cls.getMajor_version());
1.89 - out.println(" Constant pool:");
1.90 - printcp();
1.91 - env.showallAttr = true;
1.92 - }
1.93 -
1.94 - /**
1.95 - * Print class attribute information.
1.96 - */
1.97 - public void printClassAttributes(){
1.98 - out.println();
1.99 - AttrData[] clsattrs = cls.getAttributes();
1.100 - for(int i = 0; i < clsattrs.length; i++){
1.101 - String clsattrname = clsattrs[i].getAttrName();
1.102 - if(clsattrname.equals("SourceFile")){
1.103 - out.println(" SourceFile: "+ cls.getSourceName());
1.104 - }else if(clsattrname.equals("InnerClasses")){
1.105 - printInnerClasses();
1.106 - }else {
1.107 - printAttrData(clsattrs[i]);
1.108 - }
1.109 - }
1.110 - }
1.111 -
1.112 - /**
1.113 - * Print the fields
1.114 - */
1.115 - public void printfields(){
1.116 - FieldData[] fields = cls.getFields();
1.117 - for(int f = 0; f < fields.length; f++){
1.118 - String[] accflags = fields[f].getAccess();
1.119 - if(checkAccess(accflags)){
1.120 - if(!(env. showLineAndLocal || env.showDisassembled || env.showVerbose
1.121 - || env.showInternalSigs || env.showallAttr)){
1.122 - out.print(" ");
1.123 - }
1.124 - printAccess(accflags);
1.125 - out.println(fields[f].getType()+" " +fields[f].getName()+";");
1.126 - if (env.showInternalSigs) {
1.127 - out.println(" Signature: " + (fields[f].getInternalSig()));
1.128 - }
1.129 -
1.130 - // print field attribute information.
1.131 - if (env.showallAttr){
1.132 - printFieldAttributes(fields[f]);
1.133 -
1.134 - }
1.135 - if((env.showDisassembled) || (env.showLineAndLocal)){
1.136 - out.println();
1.137 - }
1.138 - }
1.139 - }
1.140 - }
1.141 -
1.142 -
1.143 - /* print field attribute information. */
1.144 - public void printFieldAttributes(FieldData field){
1.145 - Vector fieldattrs = field.getAttributes();
1.146 - for(int j = 0; j < fieldattrs.size(); j++){
1.147 - String fieldattrname = ((AttrData)fieldattrs.elementAt(j)).getAttrName();
1.148 - if(fieldattrname.equals("ConstantValue")){
1.149 - printConstantValue(field);
1.150 - }else if (fieldattrname.equals("Deprecated")){
1.151 - out.println("Deprecated: "+ field.isDeprecated());
1.152 - }else if (fieldattrname.equals("Synthetic")){
1.153 - out.println(" Synthetic: "+ field.isSynthetic());
1.154 - }else {
1.155 - printAttrData((AttrData)fieldattrs.elementAt(j));
1.156 - }
1.157 - }
1.158 - out.println();
1.159 - }
1.160 -
1.161 - /**
1.162 - * Print the methods
1.163 - */
1.164 - public void printMethods(){
1.165 - MethodData[] methods = cls.getMethods();
1.166 - for(int m = 0; m < methods.length; m++){
1.167 - String[] accflags = methods[m].getAccess();
1.168 - if(checkAccess(accflags)){
1.169 - if(!(env. showLineAndLocal || env.showDisassembled || env.showVerbose
1.170 - || env.showInternalSigs || env.showallAttr)){
1.171 - out.print(" ");
1.172 - }
1.173 - printMethodSignature(methods[m], accflags);
1.174 - printExceptions(methods[m]);
1.175 - out.println(";");
1.176 -
1.177 - // Print internal signature of method.
1.178 - if (env.showInternalSigs){
1.179 - out.println(" Signature: " + (methods[m].getInternalSig()));
1.180 - }
1.181 -
1.182 - //Print disassembled code.
1.183 - if(env.showDisassembled && ! env.showallAttr) {
1.184 - printcodeSequence(methods[m]);
1.185 - printExceptionTable(methods[m]);
1.186 - out.println();
1.187 - }
1.188 -
1.189 - // Print line and local variable attribute information.
1.190 - if (env.showLineAndLocal) {
1.191 - printLineNumTable(methods[m]);
1.192 - printLocVarTable(methods[m]);
1.193 - out.println();
1.194 - }
1.195 -
1.196 - // Print method attribute information.
1.197 - if (env.showallAttr){
1.198 - printMethodAttributes(methods[m]);
1.199 - }
1.200 - }
1.201 - }
1.202 - }
1.203 -
1.204 - /**
1.205 - * Print method signature.
1.206 - */
1.207 - public void printMethodSignature(MethodData method, String[] accflags){
1.208 - printAccess(accflags);
1.209 -
1.210 - if((method.getName()).equals("<init>")){
1.211 - out.print(javaclassname(cls.getClassName()));
1.212 - out.print(method.getParameters());
1.213 - }else if((method.getName()).equals("<clinit>")){
1.214 - out.print("{}");
1.215 - }else{
1.216 - out.print(method.getReturnType()+" ");
1.217 - out.print(method.getName());
1.218 - out.print(method.getParameters());
1.219 - }
1.220 - }
1.221 -
1.222 - /**
1.223 - * print method attribute information.
1.224 - */
1.225 - public void printMethodAttributes(MethodData method){
1.226 - Vector methodattrs = method.getAttributes();
1.227 - Vector codeattrs = method.getCodeAttributes();
1.228 - for(int k = 0; k < methodattrs.size(); k++){
1.229 - String methodattrname = ((AttrData)methodattrs.elementAt(k)).getAttrName();
1.230 - if(methodattrname.equals("Code")){
1.231 - printcodeSequence(method);
1.232 - printExceptionTable(method);
1.233 - for(int c = 0; c < codeattrs.size(); c++){
1.234 - String codeattrname = ((AttrData)codeattrs.elementAt(c)).getAttrName();
1.235 - if(codeattrname.equals("LineNumberTable")){
1.236 - printLineNumTable(method);
1.237 - }else if(codeattrname.equals("LocalVariableTable")){
1.238 - printLocVarTable(method);
1.239 - }else if(codeattrname.equals("StackMapTable")) {
1.240 - // Java SE JSR 202 stack map tables
1.241 - printStackMapTable(method);
1.242 - }else if(codeattrname.equals("StackMap")) {
1.243 - // Java ME CLDC stack maps
1.244 - printStackMap(method);
1.245 - } else {
1.246 - printAttrData((AttrData)codeattrs.elementAt(c));
1.247 - }
1.248 - }
1.249 - }else if(methodattrname.equals("Exceptions")){
1.250 - out.println(" Exceptions: ");
1.251 - printExceptions(method);
1.252 - }else if (methodattrname.equals("Deprecated")){
1.253 - out.println(" Deprecated: "+ method.isDeprecated());
1.254 - }else if (methodattrname.equals("Synthetic")){
1.255 - out.println(" Synthetic: "+ method.isSynthetic());
1.256 - }else {
1.257 - printAttrData((AttrData)methodattrs.elementAt(k));
1.258 - }
1.259 - }
1.260 - out.println();
1.261 - }
1.262 -
1.263 - /**
1.264 - * Print exceptions.
1.265 - */
1.266 - public void printExceptions(MethodData method){
1.267 - int []exc_index_table = method.get_exc_index_table();
1.268 - if (exc_index_table != null) {
1.269 - if(!(env. showLineAndLocal || env.showDisassembled || env.showVerbose
1.270 - || env.showInternalSigs || env.showallAttr)){
1.271 - out.print(" ");
1.272 - }
1.273 - out.print(" throws ");
1.274 - int k;
1.275 - int l = exc_index_table.length;
1.276 -
1.277 - for (k=0; k<l; k++) {
1.278 - out.print(javaclassname(cls.getClassName(exc_index_table[k])));
1.279 - if (k<l-1) out.print(", ");
1.280 - }
1.281 - }
1.282 - }
1.283 -
1.284 - /**
1.285 - * Print code sequence.
1.286 - */
1.287 - public void printcodeSequence(MethodData method){
1.288 - code = method.getCode();
1.289 - if(code != null){
1.290 - out.println(" Code:");
1.291 - if(env.showVerbose){
1.292 - printVerboseHeader(method);
1.293 - }
1.294 -
1.295 - for (int pc=0; pc < code.length; ) {
1.296 - out.print(" "+pc+":\t");
1.297 - pc=pc+printInstr(pc);
1.298 - out.println();
1.299 - }
1.300 - }
1.301 - }
1.302 -
1.303 - /**
1.304 - * Print instructions.
1.305 - */
1.306 - public int printInstr(int pc){
1.307 - int opcode = getUbyte(pc);
1.308 - int opcode2;
1.309 - String mnem;
1.310 - switch (opcode) {
1.311 - case opc_nonpriv:
1.312 - case opc_priv:
1.313 - opcode2 = getUbyte(pc+1);
1.314 - mnem=Tables.opcName((opcode<<8)+opcode2);
1.315 - if (mnem==null)
1.316 - // assume all (even nonexistent) priv and nonpriv instructions
1.317 - // are 2 bytes long
1.318 - mnem=Tables.opcName(opcode)+" "+opcode2;
1.319 - out.print(mnem);
1.320 - return 2;
1.321 - case opc_wide: {
1.322 - opcode2 = getUbyte(pc+1);
1.323 - mnem=Tables.opcName((opcode<<8)+opcode2);
1.324 - if (mnem==null) {
1.325 - // nonexistent opcode - but we have to print something
1.326 - out.print("bytecode "+opcode);
1.327 - return 1;
1.328 - }
1.329 - out.print(mnem+" "+getUShort(pc+2));
1.330 - if (opcode2==opc_iinc) {
1.331 - out.print(", "+getShort(pc+4));
1.332 - return 6;
1.333 - }
1.334 - return 4;
1.335 - }
1.336 - }
1.337 - mnem=Tables.opcName(opcode);
1.338 - if (mnem==null) {
1.339 - // nonexistent opcode - but we have to print something
1.340 - out.print("bytecode "+opcode);
1.341 - return 1;
1.342 - }
1.343 - if (opcode>opc_jsr_w) {
1.344 - // pseudo opcodes should be printed as bytecodes
1.345 - out.print("bytecode "+opcode);
1.346 - return 1;
1.347 - }
1.348 - out.print(Tables.opcName(opcode));
1.349 - switch (opcode) {
1.350 - case opc_aload: case opc_astore:
1.351 - case opc_fload: case opc_fstore:
1.352 - case opc_iload: case opc_istore:
1.353 - case opc_lload: case opc_lstore:
1.354 - case opc_dload: case opc_dstore:
1.355 - case opc_ret:
1.356 - out.print("\t"+getUbyte(pc+1));
1.357 - return 2;
1.358 - case opc_iinc:
1.359 - out.print("\t"+getUbyte(pc+1)+", "+getbyte(pc+2));
1.360 - return 3;
1.361 - case opc_tableswitch:{
1.362 - int tb=align(pc+1);
1.363 - int default_skip = getInt(tb); /* default skip pamount */
1.364 - int low = getInt(tb+4);
1.365 - int high = getInt(tb+8);
1.366 - int count = high - low;
1.367 - out.print("{ //"+low+" to "+high);
1.368 - for (int i = 0; i <= count; i++)
1.369 - out.print( "\n\t\t" + (i+low) + ": "+lP+(pc+getInt(tb+12+4*i))+";");
1.370 - out.print("\n\t\tdefault: "+lP+(default_skip + pc) + " }");
1.371 - return tb-pc+16+count*4;
1.372 - }
1.373 -
1.374 - case opc_lookupswitch:{
1.375 - int tb=align(pc+1);
1.376 - int default_skip = getInt(tb);
1.377 - int npairs = getInt(tb+4);
1.378 - out.print("{ //"+npairs);
1.379 - for (int i = 1; i <= npairs; i++)
1.380 - out.print("\n\t\t"+getInt(tb+i*8)
1.381 - +": "+lP+(pc+getInt(tb+4+i*8))+";"
1.382 - );
1.383 - out.print("\n\t\tdefault: "+lP+(default_skip + pc) + " }");
1.384 - return tb-pc+(npairs+1)*8;
1.385 - }
1.386 - case opc_newarray:
1.387 - int type=getUbyte(pc+1);
1.388 - switch (type) {
1.389 - case T_BOOLEAN:out.print(" boolean");break;
1.390 - case T_BYTE: out.print(" byte"); break;
1.391 - case T_CHAR: out.print(" char"); break;
1.392 - case T_SHORT: out.print(" short"); break;
1.393 - case T_INT: out.print(" int"); break;
1.394 - case T_LONG: out.print(" long"); break;
1.395 - case T_FLOAT: out.print(" float"); break;
1.396 - case T_DOUBLE: out.print(" double"); break;
1.397 - case T_CLASS: out.print(" class"); break;
1.398 - default: out.print(" BOGUS TYPE:"+type);
1.399 - }
1.400 - return 2;
1.401 -
1.402 - case opc_anewarray: {
1.403 - int index = getUShort(pc+1);
1.404 - out.print("\t#"+index+"; //");
1.405 - PrintConstant(index);
1.406 - return 3;
1.407 - }
1.408 -
1.409 - case opc_sipush:
1.410 - out.print("\t"+getShort(pc+1));
1.411 - return 3;
1.412 -
1.413 - case opc_bipush:
1.414 - out.print("\t"+getbyte(pc+1));
1.415 - return 2;
1.416 -
1.417 - case opc_ldc: {
1.418 - int index = getUbyte(pc+1);
1.419 - out.print("\t#"+index+"; //");
1.420 - PrintConstant(index);
1.421 - return 2;
1.422 - }
1.423 -
1.424 - case opc_ldc_w: case opc_ldc2_w:
1.425 - case opc_instanceof: case opc_checkcast:
1.426 - case opc_new:
1.427 - case opc_putstatic: case opc_getstatic:
1.428 - case opc_putfield: case opc_getfield:
1.429 - case opc_invokevirtual:
1.430 - case opc_invokespecial:
1.431 - case opc_invokestatic: {
1.432 - int index = getUShort(pc+1);
1.433 - out.print("\t#"+index+"; //");
1.434 - PrintConstant(index);
1.435 - return 3;
1.436 - }
1.437 -
1.438 - case opc_invokeinterface: {
1.439 - int index = getUShort(pc+1), nargs=getUbyte(pc+3);
1.440 - out.print("\t#"+index+", "+nargs+"; //");
1.441 - PrintConstant(index);
1.442 - return 5;
1.443 - }
1.444 -
1.445 - case opc_multianewarray: {
1.446 - int index = getUShort(pc+1), dimensions=getUbyte(pc+3);
1.447 - out.print("\t#"+index+", "+dimensions+"; //");
1.448 - PrintConstant(index);
1.449 - return 4;
1.450 - }
1.451 - case opc_jsr: case opc_goto:
1.452 - case opc_ifeq: case opc_ifge: case opc_ifgt:
1.453 - case opc_ifle: case opc_iflt: case opc_ifne:
1.454 - case opc_if_icmpeq: case opc_if_icmpne: case opc_if_icmpge:
1.455 - case opc_if_icmpgt: case opc_if_icmple: case opc_if_icmplt:
1.456 - case opc_if_acmpeq: case opc_if_acmpne:
1.457 - case opc_ifnull: case opc_ifnonnull:
1.458 - out.print("\t"+lP+(pc + getShort(pc+1)) );
1.459 - return 3;
1.460 -
1.461 - case opc_jsr_w:
1.462 - case opc_goto_w:
1.463 - out.print("\t"+lP+(pc + getInt(pc+1)));
1.464 - return 5;
1.465 -
1.466 - default:
1.467 - return 1;
1.468 - }
1.469 - }
1.470 - /**
1.471 - * Print code attribute details.
1.472 - */
1.473 - public void printVerboseHeader(MethodData method) {
1.474 - int argCount = method.getArgumentlength();
1.475 - if (!method.isStatic())
1.476 - ++argCount; // for 'this'
1.477 -
1.478 - out.println(" Stack=" + method.getMaxStack()
1.479 - + ", Locals=" + method.getMaxLocals()
1.480 - + ", Args_size=" + argCount);
1.481 -
1.482 - }
1.483 -
1.484 -
1.485 - /**
1.486 - * Print the exception table for this method code
1.487 - */
1.488 - void printExceptionTable(MethodData method){//throws IOException
1.489 - Vector exception_table = method.getexception_table();
1.490 - if (exception_table.size() > 0) {
1.491 - out.println(" Exception table:");
1.492 - out.println(" from to target type");
1.493 - for (int idx = 0; idx < exception_table.size(); ++idx) {
1.494 - TrapData handler = (TrapData)exception_table.elementAt(idx);
1.495 - printFixedWidthInt(handler.start_pc, 6);
1.496 - printFixedWidthInt(handler.end_pc, 6);
1.497 - printFixedWidthInt(handler.handler_pc, 6);
1.498 - out.print(" ");
1.499 - int catch_cpx = handler.catch_cpx;
1.500 - if (catch_cpx == 0) {
1.501 - out.println("any");
1.502 - }else {
1.503 - out.print("Class ");
1.504 - out.println(cls.getClassName(catch_cpx));
1.505 - out.println("");
1.506 - }
1.507 - }
1.508 - }
1.509 - }
1.510 -
1.511 - /**
1.512 - * Print LineNumberTable attribute information.
1.513 - */
1.514 - public void printLineNumTable(MethodData method) {
1.515 - int numlines = method.getnumlines();
1.516 - Vector lin_num_tb = method.getlin_num_tb();
1.517 - if( lin_num_tb.size() > 0){
1.518 - out.println(" LineNumberTable: ");
1.519 - for (int i=0; i<numlines; i++) {
1.520 - LineNumData linnumtb_entry=(LineNumData)lin_num_tb.elementAt(i);
1.521 - out.println(" line " + linnumtb_entry.line_number + ": "
1.522 - + linnumtb_entry.start_pc);
1.523 - }
1.524 - }
1.525 - out.println();
1.526 - }
1.527 -
1.528 - /**
1.529 - * Print LocalVariableTable attribute information.
1.530 - */
1.531 - public void printLocVarTable(MethodData method){
1.532 - int siz = method.getloc_var_tbsize();
1.533 - if(siz > 0){
1.534 - out.println(" LocalVariableTable: ");
1.535 - out.print(" ");
1.536 - out.println("Start Length Slot Name Signature");
1.537 - }
1.538 - Vector loc_var_tb = method.getloc_var_tb();
1.539 -
1.540 - for (int i=0; i<siz; i++) {
1.541 - LocVarData entry=(LocVarData)loc_var_tb.elementAt(i);
1.542 -
1.543 - out.println(" "+entry.start_pc+" "+entry.length+" "+
1.544 - entry.slot+" "+cls.StringValue(entry.name_cpx) +
1.545 - " "+cls.StringValue(entry.sig_cpx));
1.546 - }
1.547 - out.println();
1.548 - }
1.549 -
1.550 - /**
1.551 - * Print StackMap attribute information.
1.552 - */
1.553 - public void printStackMap(MethodData method) {
1.554 - StackMapData[] stack_map_tb = method.getStackMap();
1.555 - int number_of_entries = stack_map_tb.length;
1.556 - if (number_of_entries > 0) {
1.557 - out.println(" StackMap: number_of_entries = " + number_of_entries);
1.558 -
1.559 - for (StackMapData frame : stack_map_tb) {
1.560 - frame.print(this);
1.561 - }
1.562 - }
1.563 - out.println();
1.564 - }
1.565 -
1.566 - /**
1.567 - * Print StackMapTable attribute information.
1.568 - */
1.569 - public void printStackMapTable(MethodData method) {
1.570 - StackMapTableData[] stack_map_tb = method.getStackMapTable();
1.571 - int number_of_entries = stack_map_tb.length;
1.572 - if (number_of_entries > 0) {
1.573 - out.println(" StackMapTable: number_of_entries = " + number_of_entries);
1.574 -
1.575 - for (StackMapTableData frame : stack_map_tb) {
1.576 - frame.print(this);
1.577 - }
1.578 - }
1.579 - out.println();
1.580 - }
1.581 -
1.582 - void printMap(String name, int[] map) {
1.583 - out.print(name);
1.584 - for (int i=0; i<map.length; i++) {
1.585 - int fulltype = map[i];
1.586 - int type = fulltype & 0xFF;
1.587 - int argument = fulltype >> 8;
1.588 - switch (type) {
1.589 - case ITEM_Object:
1.590 - out.print(" ");
1.591 - PrintConstant(argument);
1.592 - break;
1.593 - case ITEM_NewObject:
1.594 - out.print(" " + Tables.mapTypeName(type));
1.595 - out.print(" " + argument);
1.596 - break;
1.597 - default:
1.598 - out.print(" " + Tables.mapTypeName(type));
1.599 - }
1.600 - out.print( (i==(map.length-1)? ' ' : ','));
1.601 - }
1.602 - out.println("]");
1.603 - }
1.604 -
1.605 - /**
1.606 - * Print ConstantValue attribute information.
1.607 - */
1.608 - public void printConstantValue(FieldData field){
1.609 - out.print(" Constant value: ");
1.610 - int cpx = (field.getConstantValueIndex());
1.611 - byte tag=0;
1.612 - try {
1.613 - tag=cls.getTag(cpx);
1.614 -
1.615 - } catch (IndexOutOfBoundsException e) {
1.616 - out.print("Error:");
1.617 - return;
1.618 - }
1.619 - switch (tag) {
1.620 - case CONSTANT_METHOD:
1.621 - case CONSTANT_INTERFACEMETHOD:
1.622 - case CONSTANT_FIELD: {
1.623 - CPX2 x = (CPX2)(cls.getCpoolEntry(cpx));
1.624 - if (x.cpx1 == cls.getthis_cpx()) {
1.625 - // don't print class part for local references
1.626 - cpx=x.cpx2;
1.627 - }
1.628 - }
1.629 - }
1.630 - out.print(cls.TagString(tag)+" "+ cls.StringValue(cpx));
1.631 - }
1.632 -
1.633 - /**
1.634 - * Print InnerClass attribute information.
1.635 - */
1.636 - public void printInnerClasses(){//throws ioexception
1.637 -
1.638 - InnerClassData[] innerClasses = cls.getInnerClasses();
1.639 - if(innerClasses != null){
1.640 - if(innerClasses.length > 0){
1.641 - out.print(" ");
1.642 - out.println("InnerClass: ");
1.643 - for(int i = 0 ; i < innerClasses.length; i++){
1.644 - out.print(" ");
1.645 - //access
1.646 - String[] accflags = innerClasses[i].getAccess();
1.647 - if(checkAccess(accflags)){
1.648 - printAccess(accflags);
1.649 - if (innerClasses[i].inner_name_index!=0) {
1.650 - out.print("#"+innerClasses[i].inner_name_index+"= ");
1.651 - }
1.652 - out.print("#"+innerClasses[i].inner_class_info_index);
1.653 - if (innerClasses[i].outer_class_info_index!=0) {
1.654 - out.print(" of #"+innerClasses[i].outer_class_info_index);
1.655 - }
1.656 - out.print("; //");
1.657 - if (innerClasses[i].inner_name_index!=0) {
1.658 - out.print(cls.getName(innerClasses[i].inner_name_index)+"=");
1.659 - }
1.660 - PrintConstant(innerClasses[i].inner_class_info_index);
1.661 - if (innerClasses[i].outer_class_info_index!=0) {
1.662 - out.print(" of ");
1.663 - PrintConstant(innerClasses[i].outer_class_info_index);
1.664 - }
1.665 - out.println();
1.666 - }
1.667 - }
1.668 -
1.669 - }
1.670 - }
1.671 - }
1.672 -
1.673 - /**
1.674 - * Print constant pool information.
1.675 - */
1.676 - public void printcp(){
1.677 - int cpx = 1 ;
1.678 -
1.679 - while (cpx < cls.getCpoolCount()) {
1.680 - out.print("const #"+cpx+" = ");
1.681 - cpx+=PrintlnConstantEntry(cpx);
1.682 - }
1.683 - out.println();
1.684 - }
1.685 -
1.686 - /**
1.687 - * Print constant pool entry information.
1.688 - */
1.689 - public int PrintlnConstantEntry(int cpx) {
1.690 - int size=1;
1.691 - byte tag=0;
1.692 - try {
1.693 - tag=cls.getTag(cpx);
1.694 - } catch (IndexOutOfBoundsException e) {
1.695 - out.println(" <Incorrect CP index>");
1.696 - return 1;
1.697 - }
1.698 - out.print(cls.StringTag(cpx)+"\t");
1.699 - Object x=cls.getCpoolEntryobj(cpx);
1.700 - if (x==null) {
1.701 - switch (tag) {
1.702 - case CONSTANT_LONG:
1.703 - case CONSTANT_DOUBLE:
1.704 - size=2;
1.705 - }
1.706 - out.println("null;");
1.707 - return size;
1.708 - }
1.709 - String str=cls.StringValue(cpx);
1.710 -
1.711 - switch (tag) {
1.712 - case CONSTANT_CLASS:
1.713 - case CONSTANT_STRING:
1.714 - out.println("#"+(((CPX)x).cpx)+";\t// "+str);
1.715 - break;
1.716 - case CONSTANT_FIELD:
1.717 - case CONSTANT_METHOD:
1.718 - case CONSTANT_INTERFACEMETHOD:
1.719 - out.println("#"+((CPX2)x).cpx1+".#"+((CPX2)x).cpx2+";\t// "+str);
1.720 - break;
1.721 - case CONSTANT_NAMEANDTYPE:
1.722 - out.println("#"+((CPX2)x).cpx1+":#"+((CPX2)x).cpx2+";// "+str);
1.723 - break;
1.724 - case CONSTANT_LONG:
1.725 - case CONSTANT_DOUBLE:
1.726 - size=2;
1.727 - default:
1.728 - out.println(str+";");
1.729 - }
1.730 - return size;
1.731 - }
1.732 -
1.733 - /**
1.734 - * Checks access of class, field or method.
1.735 - */
1.736 - public boolean checkAccess(String accflags[]){
1.737 -
1.738 - boolean ispublic = false;
1.739 - boolean isprotected = false;
1.740 - boolean isprivate = false;
1.741 - boolean ispackage = false;
1.742 -
1.743 - for(int i= 0; i < accflags.length; i++){
1.744 - if(accflags[i].equals("public")) ispublic = true;
1.745 - else if (accflags[i].equals("protected")) isprotected = true;
1.746 - else if (accflags[i].equals("private")) isprivate = true;
1.747 - }
1.748 -
1.749 - if(!(ispublic || isprotected || isprivate)) ispackage = true;
1.750 -
1.751 - if((env.showAccess == env.PUBLIC) && (isprotected || isprivate || ispackage)) return false;
1.752 - else if((env.showAccess == env.PROTECTED) && (isprivate || ispackage)) return false;
1.753 - else if((env.showAccess == env.PACKAGE) && (isprivate)) return false;
1.754 - else return true;
1.755 - }
1.756 -
1.757 - /**
1.758 - * Prints access of class, field or method.
1.759 - */
1.760 - public void printAccess(String []accflags){
1.761 - for(int j = 0; j < accflags.length; j++){
1.762 - out.print(accflags[j]+" ");
1.763 - }
1.764 - }
1.765 -
1.766 - /**
1.767 - * Print an integer so that it takes 'length' characters in
1.768 - * the output. Temporary until formatting code is stable.
1.769 - */
1.770 - public void printFixedWidthInt(long x, int length) {
1.771 - CharArrayWriter baStream = new CharArrayWriter();
1.772 - PrintWriter pStream = new PrintWriter(baStream);
1.773 - pStream.print(x);
1.774 - String str = baStream.toString();
1.775 - for (int cnt = length - str.length(); cnt > 0; --cnt)
1.776 - out.print(' ');
1.777 - out.print(str);
1.778 - }
1.779 -
1.780 - protected int getbyte (int pc) {
1.781 - return code[pc];
1.782 - }
1.783 -
1.784 - protected int getUbyte (int pc) {
1.785 - return code[pc]&0xFF;
1.786 - }
1.787 -
1.788 - int getShort (int pc) {
1.789 - return (code[pc]<<8) | (code[pc+1]&0xFF);
1.790 - }
1.791 -
1.792 - int getUShort (int pc) {
1.793 - return ((code[pc]<<8) | (code[pc+1]&0xFF))&0xFFFF;
1.794 - }
1.795 -
1.796 - protected int getInt (int pc) {
1.797 - return (getShort(pc)<<16) | (getShort(pc+2)&0xFFFF);
1.798 - }
1.799 -
1.800 - /**
1.801 - * Print constant value at that index.
1.802 - */
1.803 - void PrintConstant(int cpx) {
1.804 - if (cpx==0) {
1.805 - out.print("#0");
1.806 - return;
1.807 - }
1.808 - byte tag=0;
1.809 - try {
1.810 - tag=cls.getTag(cpx);
1.811 -
1.812 - } catch (IndexOutOfBoundsException e) {
1.813 - out.print("#"+cpx);
1.814 - return;
1.815 - }
1.816 - switch (tag) {
1.817 - case CONSTANT_METHOD:
1.818 - case CONSTANT_INTERFACEMETHOD:
1.819 - case CONSTANT_FIELD: {
1.820 - // CPX2 x=(CPX2)(cpool[cpx]);
1.821 - CPX2 x = (CPX2)(cls.getCpoolEntry(cpx));
1.822 - if (x.cpx1 == cls.getthis_cpx()) {
1.823 - // don't print class part for local references
1.824 - cpx=x.cpx2;
1.825 - }
1.826 - }
1.827 - }
1.828 - out.print(cls.TagString(tag)+" "+ cls.StringValue(cpx));
1.829 - }
1.830 -
1.831 - protected static int align (int n) {
1.832 - return (n+3) & ~3 ;
1.833 - }
1.834 -
1.835 - public void printend(){
1.836 - out.println("}");
1.837 - out.println();
1.838 - }
1.839 -
1.840 - public String javaclassname(String name){
1.841 - return name.replace('/','.');
1.842 - }
1.843 -
1.844 - /**
1.845 - * Print attribute data in hex.
1.846 - */
1.847 - public void printAttrData(AttrData attr){
1.848 - byte []data = attr.getData();
1.849 - int i = 0;
1.850 - int j = 0;
1.851 - out.print(" "+attr.getAttrName()+": ");
1.852 - out.println("length = " + cls.toHex(attr.datalen));
1.853 -
1.854 - out.print(" ");
1.855 -
1.856 -
1.857 - while (i < data.length){
1.858 - String databytestring = cls.toHex(data[i]);
1.859 - if(databytestring.equals("0x")) out.print("00");
1.860 - else if(databytestring.substring(2).length() == 1){
1.861 - out.print("0"+databytestring.substring(2));
1.862 - } else{
1.863 - out.print(databytestring.substring(2));
1.864 - }
1.865 -
1.866 - j++;
1.867 - if(j == 16) {
1.868 - out.println();
1.869 - out.print(" ");
1.870 - j = 0;
1.871 - }
1.872 - else out.print(" ");
1.873 - i++;
1.874 - }
1.875 - out.println();
1.876 - }
1.877 }