1 21 package proguard.classfile.visitor; 22 23 import proguard.classfile.*; 24 import proguard.classfile.attribute.*; 25 import proguard.classfile.attribute.annotation.*; 26 import proguard.classfile.attribute.annotation.visitor.*; 27 import proguard.classfile.attribute.preverification.*; 28 import proguard.classfile.attribute.preverification.visitor.*; 29 import proguard.classfile.attribute.visitor.*; 30 import proguard.classfile.constant.*; 31 import proguard.classfile.constant.visitor.ConstantVisitor; 32 import proguard.classfile.instruction.*; 33 import proguard.classfile.instruction.visitor.InstructionVisitor; 34 import proguard.classfile.util.*; 35 36 import java.io.PrintStream ; 37 38 39 45 public class ClassPrinter 46 extends SimplifiedVisitor 47 implements ClassVisitor, 48 ConstantVisitor, 49 MemberVisitor, 50 AttributeVisitor, 51 ExceptionInfoVisitor, 52 InnerClassesInfoVisitor, 53 StackMapFrameVisitor, 54 VerificationTypeVisitor, 55 LineNumberInfoVisitor, 56 LocalVariableInfoVisitor, 57 LocalVariableTypeInfoVisitor, 58 AnnotationVisitor, 59 ElementValueVisitor, 60 InstructionVisitor 61 { 62 private static final String INDENTATION = " "; 63 64 private PrintStream ps; 65 private int indentation; 66 67 68 71 public ClassPrinter() 72 { 73 this(System.out); 74 } 75 76 77 81 public ClassPrinter(PrintStream printStream) 82 { 83 ps = printStream; 84 } 85 86 87 89 public void visitProgramClass(ProgramClass programClass) 90 { 91 println("_____________________________________________________________________"); 92 println(visitorInfo(programClass) + " " + 93 "Program class: " + programClass.getName()); 94 indent(); 95 println("Superclass: " + programClass.getSuperName()); 96 println("Major version: 0x" + Integer.toHexString(ClassUtil.internalMajorClassVersion(programClass.u4version))); 97 println("Minor version: 0x" + Integer.toHexString(ClassUtil.internalMinorClassVersion(programClass.u4version))); 98 println("Access flags: 0x" + Integer.toHexString(programClass.u2accessFlags)); 99 println(" = " + 100 ClassUtil.externalClassAccessFlags(programClass.u2accessFlags) + 101 ((programClass.u2accessFlags & ClassConstants.INTERNAL_ACC_INTERFACE) == 0 ? "class " : "") + 102 ClassUtil.externalClassName(programClass.getName()) + 103 (programClass.u2superClass == 0 ? "" : " extends " + 104 ClassUtil.externalClassName(programClass.getSuperName()))); 105 outdent(); 106 println(); 107 108 println("Interfaces (count = " + programClass.u2interfacesCount + "):"); 109 indent(); 110 for (int index = 0; index < programClass.u2interfacesCount; index++) 111 { 112 println("+ " + programClass.getClassName(programClass.u2interfaces[index])); 113 } 114 outdent(); 115 println(); 116 117 println("Constant Pool (count = " + programClass.u2constantPoolCount + "):"); 118 indent(); 119 programClass.constantPoolEntriesAccept(this); 120 outdent(); 121 println(); 122 123 println("Fields (count = " + programClass.u2fieldsCount + "):"); 124 indent(); 125 programClass.fieldsAccept(this); 126 outdent(); 127 println(); 128 129 println("Methods (count = " + programClass.u2methodsCount + "):"); 130 indent(); 131 programClass.methodsAccept(this); 132 outdent(); 133 println(); 134 135 println("Class file attributes (count = " + programClass.u2attributesCount + "):"); 136 indent(); 137 programClass.attributesAccept(this); 138 outdent(); 139 println(); 140 } 141 142 143 public void visitLibraryClass(LibraryClass libraryClass) 144 { 145 println("_____________________________________________________________________"); 146 println(visitorInfo(libraryClass) + " " + 147 "Library class: " + libraryClass.getName()); 148 indent(); 149 println("Superclass: " + libraryClass.getSuperName()); 150 println("Access flags: 0x" + Integer.toHexString(libraryClass.u2accessFlags)); 151 println(" = " + 152 ClassUtil.externalClassAccessFlags(libraryClass.u2accessFlags) + 153 ((libraryClass.u2accessFlags & ClassConstants.INTERNAL_ACC_INTERFACE) == 0 ? "class " : "") + 154 ClassUtil.externalClassName(libraryClass.getName()) + " extends " + 155 ClassUtil.externalClassName(libraryClass.getSuperName())); 156 outdent(); 157 println(); 158 159 println("Interfaces (count = " + libraryClass.interfaceClasses.length + "):"); 160 for (int index = 0; index < libraryClass.interfaceClasses.length; index++) 161 { 162 Clazz interfaceClass = libraryClass.interfaceClasses[index]; 163 if (interfaceClass != null) 164 { 165 println(" + " + interfaceClass.getName()); 166 } 167 } 168 169 println("Fields (count = " + libraryClass.fields.length + "):"); 170 libraryClass.fieldsAccept(this); 171 172 println("Methods (count = " + libraryClass.methods.length + "):"); 173 libraryClass.methodsAccept(this); 174 } 175 176 177 179 public void visitIntegerConstant(Clazz clazz, IntegerConstant integerConstant) 180 { 181 println(visitorInfo(integerConstant) + " Integer [" + 182 integerConstant.getValue() + "]"); 183 } 184 185 186 public void visitLongConstant(Clazz clazz, LongConstant longConstant) 187 { 188 println(visitorInfo(longConstant) + " Long [" + 189 longConstant.getValue() + "]"); 190 } 191 192 193 public void visitFloatConstant(Clazz clazz, FloatConstant floatConstant) 194 { 195 println(visitorInfo(floatConstant) + " Float [" + 196 floatConstant.getValue() + "]"); 197 } 198 199 200 public void visitDoubleConstant(Clazz clazz, DoubleConstant doubleConstant) 201 { 202 println(visitorInfo(doubleConstant) + " Double [" + 203 doubleConstant.getValue() + "]"); 204 } 205 206 207 public void visitStringConstant(Clazz clazz, StringConstant stringConstant) 208 { 209 println(visitorInfo(stringConstant) + " String [" + 210 clazz.getString(stringConstant.u2stringIndex) + "]"); 211 } 212 213 214 public void visitUtf8Constant(Clazz clazz, Utf8Constant utf8Constant) 215 { 216 println(visitorInfo(utf8Constant) + " Utf8 [" + 217 utf8Constant.getString() + "]"); 218 } 219 220 221 public void visitFieldrefConstant(Clazz clazz, FieldrefConstant fieldrefConstant) 222 { 223 println(visitorInfo(fieldrefConstant) + " Fieldref [" + 224 clazz.getClassName(fieldrefConstant.u2classIndex) + "." + 225 clazz.getName(fieldrefConstant.u2nameAndTypeIndex) + " " + 226 clazz.getType(fieldrefConstant.u2nameAndTypeIndex) + "]"); 227 } 228 229 230 public void visitInterfaceMethodrefConstant(Clazz clazz, InterfaceMethodrefConstant interfaceMethodrefConstant) 231 { 232 println(visitorInfo(interfaceMethodrefConstant) + " InterfaceMethodref [" + 233 clazz.getClassName(interfaceMethodrefConstant.u2classIndex) + "." + 234 clazz.getName(interfaceMethodrefConstant.u2nameAndTypeIndex) + " " + 235 clazz.getType(interfaceMethodrefConstant.u2nameAndTypeIndex) + "]"); 236 } 237 238 239 public void visitMethodrefConstant(Clazz clazz, MethodrefConstant methodrefConstant) 240 { 241 println(visitorInfo(methodrefConstant) + " Methodref [" + 242 clazz.getClassName(methodrefConstant.u2classIndex) + "." + 243 clazz.getName(methodrefConstant.u2nameAndTypeIndex) + " " + 244 clazz.getType(methodrefConstant.u2nameAndTypeIndex) + "]"); 245 } 246 247 248 public void visitClassConstant(Clazz clazz, ClassConstant classConstant) 249 { 250 println(visitorInfo(classConstant) + " Class [" + 251 clazz.getString(classConstant.u2nameIndex) + "]"); 252 } 253 254 255 public void visitNameAndTypeConstant(Clazz clazz, NameAndTypeConstant nameAndTypeConstant) 256 { 257 println(visitorInfo(nameAndTypeConstant) + " NameAndType [" + 258 clazz.getString(nameAndTypeConstant.u2nameIndex) + " " + 259 clazz.getString(nameAndTypeConstant.u2descriptorIndex) + "]"); 260 } 261 262 263 265 public void visitProgramField(ProgramClass programClass, ProgramField programField) 266 { 267 println(visitorInfo(programField) + " " + 268 "Field: " + 269 programField.getName(programClass) + " " + 270 programField.getDescriptor(programClass)); 271 272 indent(); 273 println("Access flags: 0x" + Integer.toHexString(programField.u2accessFlags)); 274 println(" = " + 275 ClassUtil.externalFullFieldDescription(programField.u2accessFlags, 276 programField.getName(programClass), 277 programField.getDescriptor(programClass))); 278 279 visitMember(programClass, programField); 280 outdent(); 281 } 282 283 284 public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod) 285 { 286 println(visitorInfo(programMethod) + " " + 287 "Method: " + 288 programMethod.getName(programClass) + 289 programMethod.getDescriptor(programClass)); 290 291 indent(); 292 println("Access flags: 0x" + Integer.toHexString(programMethod.u2accessFlags)); 293 println(" = " + 294 ClassUtil.externalFullMethodDescription(programClass.getName(), 295 programMethod.u2accessFlags, 296 programMethod.getName(programClass), 297 programMethod.getDescriptor(programClass))); 298 299 visitMember(programClass, programMethod); 300 outdent(); 301 } 302 303 304 private void visitMember(ProgramClass programClass, ProgramMember programMember) 305 { 306 if (programMember.u2attributesCount > 0) 307 { 308 println("Class member attributes (count = " + programMember.u2attributesCount + "):"); 309 programMember.attributesAccept(programClass, this); 310 } 311 } 312 313 314 public void visitLibraryField(LibraryClass libraryClass, LibraryField libraryField) 315 { 316 println(visitorInfo(libraryField) + " " + 317 "Field: " + 318 libraryField.getName(libraryClass) + " " + 319 libraryField.getDescriptor(libraryClass)); 320 321 indent(); 322 println("Access flags: 0x" + Integer.toHexString(libraryField.u2accessFlags)); 323 println(" = " + 324 ClassUtil.externalFullFieldDescription(libraryField.u2accessFlags, 325 libraryField.getName(libraryClass), 326 libraryField.getDescriptor(libraryClass))); 327 outdent(); 328 } 329 330 331 public void visitLibraryMethod(LibraryClass libraryClass, LibraryMethod libraryMethod) 332 { 333 println(visitorInfo(libraryMethod) + " " + 334 "Method: " + 335 libraryMethod.getName(libraryClass) + " " + 336 libraryMethod.getDescriptor(libraryClass)); 337 338 indent(); 339 println("Access flags: 0x" + Integer.toHexString(libraryMethod.u2accessFlags)); 340 println(" = " + 341 ClassUtil.externalFullMethodDescription(libraryClass.getName(), 342 libraryMethod.u2accessFlags, 343 libraryMethod.getName(libraryClass), 344 libraryMethod.getDescriptor(libraryClass))); 345 outdent(); 346 } 347 348 349 353 public void visitUnknownAttribute(Clazz clazz, UnknownAttribute unknownAttribute) 354 { 355 println(visitorInfo(unknownAttribute) + 356 " Unknown attribute (" + clazz.getString(unknownAttribute.u2attributeNameIndex) + ")"); 357 } 358 359 360 public void visitSourceFileAttribute(Clazz clazz, SourceFileAttribute sourceFileAttribute) 361 { 362 println(visitorInfo(sourceFileAttribute) + 363 " Source file attribute:"); 364 365 indent(); 366 clazz.constantPoolEntryAccept(sourceFileAttribute.u2sourceFileIndex, this); 367 outdent(); 368 } 369 370 371 public void visitSourceDirAttribute(Clazz clazz, SourceDirAttribute sourceDirAttribute) 372 { 373 println(visitorInfo(sourceDirAttribute) + 374 " Source dir attribute:"); 375 376 indent(); 377 clazz.constantPoolEntryAccept(sourceDirAttribute.u2sourceDirIndex, this); 378 outdent(); 379 } 380 381 382 public void visitInnerClassesAttribute(Clazz clazz, InnerClassesAttribute innerClassesAttribute) 383 { 384 println(visitorInfo(innerClassesAttribute) + 385 " Inner classes attribute (count = " + innerClassesAttribute.u2classesCount + ")"); 386 387 indent(); 388 innerClassesAttribute.innerClassEntriesAccept(clazz, this); 389 outdent(); 390 } 391 392 393 public void visitEnclosingMethodAttribute(Clazz clazz, EnclosingMethodAttribute enclosingMethodAttribute) 394 { 395 println(visitorInfo(enclosingMethodAttribute) + 396 " Enclosing method attribute [" + 397 clazz.getClassName(enclosingMethodAttribute.u2classIndex) + 398 (enclosingMethodAttribute.u2nameAndTypeIndex == 0 ? "" : "." + 399 clazz.getName(enclosingMethodAttribute.u2nameAndTypeIndex) + " " + 400 clazz.getType(enclosingMethodAttribute.u2nameAndTypeIndex)) + "]"); 401 } 402 403 404 public void visitDeprecatedAttribute(Clazz clazz, DeprecatedAttribute deprecatedAttribute) 405 { 406 println(visitorInfo(deprecatedAttribute) + 407 " Deprecated attribute"); 408 } 409 410 411 public void visitSyntheticAttribute(Clazz clazz, SyntheticAttribute syntheticAttribute) 412 { 413 println(visitorInfo(syntheticAttribute) + 414 " Synthetic attribute"); 415 } 416 417 418 public void visitSignatureAttribute(Clazz clazz, SignatureAttribute signatureAttribute) 419 { 420 println(visitorInfo(signatureAttribute) + 421 " Signature attribute:"); 422 423 indent(); 424 clazz.constantPoolEntryAccept(signatureAttribute.u2signatureIndex, this); 425 outdent(); 426 } 427 428 429 public void visitConstantValueAttribute(Clazz clazz, Field field, ConstantValueAttribute constantValueAttribute) 430 { 431 println(visitorInfo(constantValueAttribute) + 432 " Constant value attribute:"); 433 434 clazz.constantPoolEntryAccept(constantValueAttribute.u2constantValueIndex, this); 435 } 436 437 438 public void visitExceptionsAttribute(Clazz clazz, Method method, ExceptionsAttribute exceptionsAttribute) 439 { 440 println(visitorInfo(exceptionsAttribute) + 441 " Exceptions attribute (count = " + exceptionsAttribute.u2exceptionIndexTableLength + ")"); 442 443 indent(); 444 exceptionsAttribute.exceptionEntriesAccept((ProgramClass)clazz, this); 445 outdent(); 446 } 447 448 449 public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute) 450 { 451 println(visitorInfo(codeAttribute) + 452 " Code attribute instructions (code length = "+ codeAttribute.u4codeLength + 453 ", locals = "+ codeAttribute.u2maxLocals + 454 ", stack = "+ codeAttribute.u2maxStack + "):"); 455 456 indent(); 457 458 codeAttribute.instructionsAccept(clazz, method, this); 459 460 println("Code attribute exceptions (count = " + 461 codeAttribute.u2exceptionTableLength + "):"); 462 463 codeAttribute.exceptionsAccept(clazz, method, this); 464 465 println("Code attribute attributes (attribute count = " + 466 codeAttribute.u2attributesCount + "):"); 467 468 codeAttribute.attributesAccept(clazz, method, this); 469 470 outdent(); 471 } 472 473 474 public void visitStackMapAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, StackMapAttribute stackMapAttribute) 475 { 476 println(visitorInfo(codeAttribute) + 477 " Stack map attribute (count = "+ 478 stackMapAttribute.u2stackMapFramesCount + "):"); 479 480 indent(); 481 stackMapAttribute.stackMapFramesAccept(clazz, method, codeAttribute, this); 482 outdent(); 483 } 484 485 486 public void visitStackMapTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, StackMapTableAttribute stackMapTableAttribute) 487 { 488 println(visitorInfo(codeAttribute) + 489 " Stack map table attribute (count = "+ 490 stackMapTableAttribute.u2stackMapFramesCount + "):"); 491 492 indent(); 493 stackMapTableAttribute.stackMapFramesAccept(clazz, method, codeAttribute, this); 494 outdent(); 495 } 496 497 498 public void visitLineNumberTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LineNumberTableAttribute lineNumberTableAttribute) 499 { 500 println(visitorInfo(lineNumberTableAttribute) + 501 " Line number table attribute (count = " + 502 lineNumberTableAttribute.u2lineNumberTableLength + ")"); 503 504 indent(); 505 lineNumberTableAttribute.lineNumbersAccept(clazz, method, codeAttribute, this); 506 outdent(); 507 } 508 509 510 public void visitLocalVariableTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTableAttribute localVariableTableAttribute) 511 { 512 println(visitorInfo(localVariableTableAttribute) + 513 " Local variable table attribute (count = " + 514 localVariableTableAttribute.u2localVariableTableLength + ")"); 515 516 indent(); 517 localVariableTableAttribute.localVariablesAccept(clazz, method, codeAttribute, this); 518 outdent(); 519 } 520 521 522 public void visitLocalVariableTypeTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTypeTableAttribute localVariableTypeTableAttribute) 523 { 524 println(visitorInfo(localVariableTypeTableAttribute) + 525 " Local variable type table attribute (count = "+ 526 localVariableTypeTableAttribute.u2localVariableTypeTableLength + ")"); 527 528 indent(); 529 localVariableTypeTableAttribute.localVariablesAccept(clazz, method, codeAttribute, this); 530 outdent(); 531 } 532 533 534 public void visitRuntimeVisibleAnnotationsAttribute(Clazz clazz, RuntimeVisibleAnnotationsAttribute runtimeVisibleAnnotationsAttribute) 535 { 536 println(visitorInfo(runtimeVisibleAnnotationsAttribute) + 537 " Runtime visible annotations attribute:"); 538 539 indent(); 540 runtimeVisibleAnnotationsAttribute.annotationsAccept(clazz, this); 541 outdent(); 542 } 543 544 545 public void visitRuntimeInvisibleAnnotationsAttribute(Clazz clazz, RuntimeInvisibleAnnotationsAttribute runtimeInvisibleAnnotationsAttribute) 546 { 547 println(visitorInfo(runtimeInvisibleAnnotationsAttribute) + 548 " Runtime invisible annotations attribute:"); 549 550 indent(); 551 runtimeInvisibleAnnotationsAttribute.annotationsAccept(clazz, this); 552 outdent(); 553 } 554 555 556 public void visitRuntimeVisibleParameterAnnotationsAttribute(Clazz clazz, Method method, RuntimeVisibleParameterAnnotationsAttribute runtimeVisibleParameterAnnotationsAttribute) 557 { 558 println(visitorInfo(runtimeVisibleParameterAnnotationsAttribute) + 559 " Runtime visible parameter annotations attribute:"); 560 561 indent(); 562 runtimeVisibleParameterAnnotationsAttribute.annotationsAccept(clazz, method, this); 563 outdent(); 564 } 565 566 567 public void visitRuntimeInvisibleParameterAnnotationsAttribute(Clazz clazz, Method method, RuntimeInvisibleParameterAnnotationsAttribute runtimeInvisibleParameterAnnotationsAttribute) 568 { 569 println(visitorInfo(runtimeInvisibleParameterAnnotationsAttribute) + 570 " Runtime invisible parameter annotations attribute:"); 571 572 indent(); 573 runtimeInvisibleParameterAnnotationsAttribute.annotationsAccept(clazz, method, this); 574 outdent(); 575 } 576 577 578 public void visitAnnotationDefaultAttribute(Clazz clazz, Method method, AnnotationDefaultAttribute annotationDefaultAttribute) 579 { 580 println(visitorInfo(annotationDefaultAttribute) + 581 " Annotation default attribute:"); 582 583 indent(); 584 annotationDefaultAttribute.defaultValueAccept(clazz, this); 585 outdent(); 586 } 587 588 589 591 public void visitInnerClassesInfo(Clazz clazz, InnerClassesInfo innerClassesInfo) 592 { 593 println(visitorInfo(innerClassesInfo) + 594 " InnerClassesInfo:"); 595 596 indent(); 597 if (innerClassesInfo.u2innerClassIndex != 0) 598 { 599 clazz.constantPoolEntryAccept(innerClassesInfo.u2innerClassIndex, this); 600 } 601 602 if (innerClassesInfo.u2outerClassIndex != 0) 603 { 604 clazz.constantPoolEntryAccept(innerClassesInfo.u2outerClassIndex, this); 605 } 606 607 if (innerClassesInfo.u2innerNameIndex != 0) 608 { 609 clazz.constantPoolEntryAccept(innerClassesInfo.u2innerNameIndex, this); 610 } 611 outdent(); 612 } 613 614 615 617 public void visitAnyInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, Instruction instruction) 618 { 619 println(instruction.toString(offset)); 620 } 621 622 623 public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction) 624 { 625 println(constantInstruction.toString(offset)); 626 627 indent(); 628 clazz.constantPoolEntryAccept(constantInstruction.constantIndex, this); 629 outdent(); 630 } 631 632 633 public void visitTableSwitchInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, TableSwitchInstruction tableSwitchInstruction) 634 { 635 println(tableSwitchInstruction.toString(offset)); 636 637 indent(); 638 639 int[] jumpOffsets = tableSwitchInstruction.jumpOffsets; 640 641 for (int index = 0; index < jumpOffsets.length; index++) 642 { 643 int jumpOffset = jumpOffsets[index]; 644 println(Integer.toString(tableSwitchInstruction.lowCase + index) + ": offset = " + jumpOffset + ", target = " + (offset + jumpOffset)); 645 } 646 647 int defaultOffset = tableSwitchInstruction.defaultOffset; 648 println("default: offset = " + defaultOffset + ", target = "+ (offset + defaultOffset)); 649 650 outdent(); 651 } 652 653 654 public void visitLookUpSwitchInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, LookUpSwitchInstruction lookUpSwitchInstruction) 655 { 656 println(lookUpSwitchInstruction.toString(offset)); 657 658 indent(); 659 660 int[] cases = lookUpSwitchInstruction.cases; 661 int[] jumpOffsets = lookUpSwitchInstruction.jumpOffsets; 662 663 for (int index = 0; index < jumpOffsets.length; index++) 664 { 665 int jumpOffset = jumpOffsets[index]; 666 println(Integer.toString(cases[index]) + ": offset = " + jumpOffset + ", target = " + (offset + jumpOffset)); 667 } 668 669 int defaultOffset = lookUpSwitchInstruction.defaultOffset; 670 println("default: offset = " + defaultOffset + ", target = "+ (offset + defaultOffset)); 671 672 outdent(); 673 } 674 675 676 678 public void visitExceptionInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, ExceptionInfo exceptionInfo) 679 { 680 println(visitorInfo(exceptionInfo) + 681 " ExceptionInfo (" + 682 exceptionInfo.u2startPC + " -> " + 683 exceptionInfo.u2endPC + ": " + 684 exceptionInfo.u2handlerPC + "):"); 685 686 if (exceptionInfo.u2catchType != 0) 687 { 688 clazz.constantPoolEntryAccept(exceptionInfo.u2catchType, this); 689 } 690 } 691 692 693 695 public void visitSameZeroFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, SameZeroFrame sameZeroFrame) 696 { 697 println(visitorInfo(sameZeroFrame) + 698 " [" + offset + "]" + 699 " Var: ..., Stack: (empty)"); 700 } 701 702 703 public void visitSameOneFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, SameOneFrame sameOneFrame) 704 { 705 print(visitorInfo(sameOneFrame) + 706 " [" + offset + "]" + 707 " Var: ..., Stack: "); 708 709 sameOneFrame.stackItemAccept(clazz, method, codeAttribute, offset, this); 710 711 println(); 712 } 713 714 715 public void visitLessZeroFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, LessZeroFrame lessZeroFrame) 716 { 717 println(visitorInfo(lessZeroFrame) + 718 " [" + offset + "]" + 719 " Var: -" + lessZeroFrame.choppedVariablesCount + 720 ", Stack: (empty)"); 721 } 722 723 724 public void visitMoreZeroFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, MoreZeroFrame moreZeroFrame) 725 { 726 print(visitorInfo(moreZeroFrame) + 727 " [" + offset + "]" + 728 " Var: ..."); 729 730 moreZeroFrame.additionalVariablesAccept(clazz, method, codeAttribute, offset, this); 731 732 ps.println(", Stack: (empty)"); 733 } 734 735 736 public void visitFullFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, FullFrame fullFrame) 737 { 738 print(visitorInfo(fullFrame) + 739 " [" + offset + "]" + 740 " Var: "); 741 742 fullFrame.variablesAccept(clazz, method, codeAttribute, offset, this); 743 744 ps.print(", Stack: "); 745 746 fullFrame.stackAccept(clazz, method, codeAttribute, offset, this); 747 748 println(); 749 } 750 751 752 754 public void visitIntegerType(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, IntegerType integerType) 755 { 756 ps.print("[i]"); 757 } 758 759 760 public void visitFloatType(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, FloatType floatType) 761 { 762 ps.print("[f]"); 763 } 764 765 766 public void visitLongType(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, LongType longType) 767 { 768 ps.print("[l]"); 769 } 770 771 772 public void visitDoubleType(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, DoubleType doubleType) 773 { 774 ps.print("[d]"); 775 } 776 777 778 public void visitTopType(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, TopType topType) 779 { 780 ps.print("[T]"); 781 } 782 783 784 public void visitObjectType(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ObjectType objectType) 785 { 786 ps.print("[a:" + clazz.getClassName(objectType.u2classIndex) + "]"); 787 } 788 789 790 public void visitNullType(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, NullType nullType) 791 { 792 ps.print("[n]"); 793 } 794 795 796 public void visitUninitializedType(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, UninitializedType uninitializedType) 797 { 798 ps.print("[u:" + uninitializedType.u2newInstructionOffset + "]"); 799 } 800 801 802 public void visitUninitializedThisType(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, UninitializedThisType uninitializedThisType) 803 { 804 ps.print("[u:this]"); 805 } 806 807 808 810 public void visitLineNumberInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, LineNumberInfo lineNumberInfo) 811 { 812 println("[" + lineNumberInfo.u2startPC + "] -> line " + 813 lineNumberInfo.u2lineNumber); 814 } 815 816 817 819 public void visitLocalVariableInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableInfo localVariableInfo) 820 { 821 println("#" + localVariableInfo.u2index + ": " + 822 localVariableInfo.u2startPC + " -> " + 823 (localVariableInfo.u2startPC + localVariableInfo.u2length) + " [" + 824 clazz.getString(localVariableInfo.u2descriptorIndex) + " " + 825 clazz.getString(localVariableInfo.u2nameIndex) + "]"); 826 } 827 828 829 831 public void visitLocalVariableTypeInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTypeInfo localVariableTypeInfo) 832 { 833 println("#" + localVariableTypeInfo.u2index + ": " + 834 localVariableTypeInfo.u2startPC + " -> " + 835 (localVariableTypeInfo.u2startPC + localVariableTypeInfo.u2length) + " [" + 836 clazz.getString(localVariableTypeInfo.u2signatureIndex) + " " + 837 clazz.getString(localVariableTypeInfo.u2nameIndex) + "]"); 838 } 839 840 841 843 public void visitAnnotation(Clazz clazz, Annotation annotation) 844 { 845 println(visitorInfo(annotation) + 846 " Annotation [" + clazz.getString(annotation.u2typeIndex) + "]:"); 847 848 indent(); 849 annotation.elementValuesAccept(clazz, this); 850 outdent(); 851 } 852 853 854 856 public void visitConstantElementValue(Clazz clazz, Annotation annotation, ConstantElementValue constantElementValue) 857 { 858 println(visitorInfo(constantElementValue) + 859 " Constant element value [" + 860 (constantElementValue.u2elementNameIndex == 0 ? "(default)" : 861 clazz.getString(constantElementValue.u2elementNameIndex)) + " '" + 862 constantElementValue.u1tag + "']"); 863 864 indent(); 865 clazz.constantPoolEntryAccept(constantElementValue.u2constantValueIndex, this); 866 outdent(); 867 } 868 869 870 public void visitEnumConstantElementValue(Clazz clazz, Annotation annotation, EnumConstantElementValue enumConstantElementValue) 871 { 872 println(visitorInfo(enumConstantElementValue) + 873 " Enum constant element value [" + 874 (enumConstantElementValue.u2elementNameIndex == 0 ? "(default)" : 875 clazz.getString(enumConstantElementValue.u2elementNameIndex)) + ", " + 876 clazz.getString(enumConstantElementValue.u2typeNameIndex) + ", " + 877 clazz.getString(enumConstantElementValue.u2constantNameIndex) + "]"); 878 } 879 880 881 public void visitClassElementValue(Clazz clazz, Annotation annotation, ClassElementValue classElementValue) 882 { 883 println(visitorInfo(classElementValue) + 884 " Class element value [" + 885 (classElementValue.u2elementNameIndex == 0 ? "(default)" : 886 clazz.getString(classElementValue.u2elementNameIndex)) + ", " + 887 clazz.getString(classElementValue.u2classInfoIndex) + "]"); 888 } 889 890 891 public void visitAnnotationElementValue(Clazz clazz, Annotation annotation, AnnotationElementValue annotationElementValue) 892 { 893 println(visitorInfo(annotationElementValue) + 894 " Annotation element value [" + 895 (annotationElementValue.u2elementNameIndex == 0 ? "(default)" : 896 clazz.getString(annotationElementValue.u2elementNameIndex)) + "]:"); 897 898 indent(); 899 annotationElementValue.annotationAccept(clazz, this); 900 outdent(); 901 } 902 903 904 public void visitArrayElementValue(Clazz clazz, Annotation annotation, ArrayElementValue arrayElementValue) 905 { 906 println(visitorInfo(arrayElementValue) + 907 " Array element value [" + 908 (arrayElementValue.u2elementNameIndex == 0 ? "(default)" : 909 clazz.getString(arrayElementValue.u2elementNameIndex)) + "]:"); 910 911 indent(); 912 arrayElementValue.elementValuesAccept(clazz, annotation, this); 913 outdent(); 914 } 915 916 917 919 private void indent() 920 { 921 indentation++; 922 } 923 924 private void outdent() 925 { 926 indentation--; 927 } 928 929 private void println(String string) 930 { 931 print(string); 932 println(); 933 934 } 935 936 private void print(String string) 937 { 938 for (int index = 0; index < indentation; index++) 939 { 940 ps.print(INDENTATION); 941 } 942 943 ps.print(string); 944 } 945 946 private void println() 947 { 948 ps.println(); 949 } 950 951 952 private String visitorInfo(VisitorAccepter visitorAccepter) 953 { 954 return visitorAccepter.getVisitorInfo() == null ? "-" : "+"; 955 } 956 } 957 | Popular Tags |