📄 classprinter.java
字号:
outdent(); } // Implementations for InstructionVisitor. public void visitAnyInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, Instruction instruction) { println(instruction.toString(offset)); } public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction) { println(constantInstruction.toString(offset)); indent(); clazz.constantPoolEntryAccept(constantInstruction.constantIndex, this); outdent(); } // Implementations for ExceptionInfoVisitor. public void visitExceptionInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, ExceptionInfo exceptionInfo) { println(visitorInfo(exceptionInfo) + " ExceptionInfo (" + exceptionInfo.u2startPC + " -> " + exceptionInfo.u2endPC + ": " + exceptionInfo.u2handlerPC + "):"); if (exceptionInfo.u2catchType != 0) { clazz.constantPoolEntryAccept(exceptionInfo.u2catchType, this); } } // Implementations for StackMapFrameVisitor. public void visitSameZeroFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, SameZeroFrame sameZeroFrame) { println(visitorInfo(sameZeroFrame) + " [" + offset + "]" + " Var: ..., Stack: (empty)"); } public void visitSameOneFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, SameOneFrame sameOneFrame) { print(visitorInfo(sameOneFrame) + " [" + offset + "]" + " Var: ..., Stack: "); sameOneFrame.stackItemAccept(clazz, method, codeAttribute, offset, this); println(); } public void visitLessZeroFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, LessZeroFrame lessZeroFrame) { println(visitorInfo(lessZeroFrame) + " [" + offset + "]" + " Var: -" + lessZeroFrame.choppedVariablesCount + ", Stack: (empty)"); } public void visitMoreZeroFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, MoreZeroFrame moreZeroFrame) { print(visitorInfo(moreZeroFrame) + " [" + offset + "]" + " Var: ..."); moreZeroFrame.additionalVariablesAccept(clazz, method, codeAttribute, offset, this); ps.println(", Stack: (empty)"); } public void visitFullFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, FullFrame fullFrame) { print(visitorInfo(fullFrame) + " [" + offset + "]" + " Var: "); fullFrame.variablesAccept(clazz, method, codeAttribute, offset, this); ps.print(", Stack: "); fullFrame.stackAccept(clazz, method, codeAttribute, offset, this); println(); } // Implementations for VerificationTypeVisitor. public void visitIntegerType(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, IntegerType integerType) { ps.print("[i]"); } public void visitFloatType(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, FloatType floatType) { ps.print("[f]"); } public void visitLongType(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, LongType longType) { ps.print("[l]"); } public void visitDoubleType(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, DoubleType doubleType) { ps.print("[d]"); } public void visitTopType(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, TopType topType) { ps.print("[T]"); } public void visitObjectType(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ObjectType objectType) { ps.print("[a:" + clazz.getClassName(objectType.u2classIndex) + "]"); } public void visitNullType(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, NullType nullType) { ps.print("[n]"); } public void visitUninitializedType(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, UninitializedType uninitializedType) { ps.print("[u:" + uninitializedType.u2newInstructionOffset + "]"); } public void visitUninitializedThisType(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, UninitializedThisType uninitializedThisType) { ps.print("[u:this]"); } // Implementations for LineNumberInfoVisitor. public void visitLineNumberInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, LineNumberInfo lineNumberInfo) { println("[" + lineNumberInfo.u2startPC + "] -> line " + lineNumberInfo.u2lineNumber); } // Implementations for LocalVariableInfoVisitor. public void visitLocalVariableInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableInfo localVariableInfo) { println("#" + localVariableInfo.u2index + ": " + localVariableInfo.u2startPC + " -> " + (localVariableInfo.u2startPC + localVariableInfo.u2length) + " [" + clazz.getString(localVariableInfo.u2descriptorIndex) + " " + clazz.getString(localVariableInfo.u2nameIndex) + "]"); } // Implementations for LocalVariableTypeInfoVisitor. public void visitLocalVariableTypeInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTypeInfo localVariableTypeInfo) { println("#" + localVariableTypeInfo.u2index + ": " + localVariableTypeInfo.u2startPC + " -> " + (localVariableTypeInfo.u2startPC + localVariableTypeInfo.u2length) + " [" + clazz.getString(localVariableTypeInfo.u2signatureIndex) + " " + clazz.getString(localVariableTypeInfo.u2nameIndex) + "]"); } // Implementations for AnnotationVisitor. public void visitAnnotation(Clazz clazz, Annotation annotation) { println(visitorInfo(annotation) + " Annotation [" + clazz.getString(annotation.u2typeIndex) + "]:"); indent(); annotation.elementValuesAccept(clazz, this); outdent(); } // Implementations for ElementValueVisitor. public void visitConstantElementValue(Clazz clazz, Annotation annotation, ConstantElementValue constantElementValue) { println(visitorInfo(constantElementValue) + " Constant element value [" + (constantElementValue.u2elementNameIndex == 0 ? "(default)" : clazz.getString(constantElementValue.u2elementNameIndex)) + " '" + constantElementValue.u1tag + "']"); indent(); clazz.constantPoolEntryAccept(constantElementValue.u2constantValueIndex, this); outdent(); } public void visitEnumConstantElementValue(Clazz clazz, Annotation annotation, EnumConstantElementValue enumConstantElementValue) { println(visitorInfo(enumConstantElementValue) + " Enum constant element value [" + (enumConstantElementValue.u2elementNameIndex == 0 ? "(default)" : clazz.getString(enumConstantElementValue.u2elementNameIndex)) + ", " + clazz.getString(enumConstantElementValue.u2typeNameIndex) + ", " + clazz.getString(enumConstantElementValue.u2constantNameIndex) + "]"); } public void visitClassElementValue(Clazz clazz, Annotation annotation, ClassElementValue classElementValue) { println(visitorInfo(classElementValue) + " Class element value [" + (classElementValue.u2elementNameIndex == 0 ? "(default)" : clazz.getString(classElementValue.u2elementNameIndex)) + ", " + clazz.getString(classElementValue.u2classInfoIndex) + "]"); } public void visitAnnotationElementValue(Clazz clazz, Annotation annotation, AnnotationElementValue annotationElementValue) { println(visitorInfo(annotationElementValue) + " Annotation element value [" + (annotationElementValue.u2elementNameIndex == 0 ? "(default)" : clazz.getString(annotationElementValue.u2elementNameIndex)) + "]:"); indent(); annotationElementValue.annotationAccept(clazz, this); outdent(); } public void visitArrayElementValue(Clazz clazz, Annotation annotation, ArrayElementValue arrayElementValue) { println(visitorInfo(arrayElementValue) + " Array element value [" + (arrayElementValue.u2elementNameIndex == 0 ? "(default)" : clazz.getString(arrayElementValue.u2elementNameIndex)) + "]:"); indent(); arrayElementValue.elementValuesAccept(clazz, annotation, this); outdent(); } // Small utility methods. private void indent() { indentation++; } private void outdent() { indentation--; } private void println(String string) { print(string); println(); } private void print(String string) { for (int index = 0; index < indentation; index++) { ps.print(INDENTATION); } ps.print(string); } private void println() { ps.println(); } private String visitorInfo(VisitorAccepter visitorAccepter) { return visitorAccepter.getVisitorInfo() == null ? "-" : "+"; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -