📄 programclasswriter.java
字号:
} public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute) { // Write the stack size and local variable frame size. dataOutput.writeShort(codeAttribute.u2maxStack); dataOutput.writeShort(codeAttribute.u2maxLocals); // Write the byte code. dataOutput.writeInt(codeAttribute.u4codeLength); dataOutput.write(codeAttribute.code, 0, codeAttribute.u4codeLength); // Write the exceptions. dataOutput.writeShort(codeAttribute.u2exceptionTableLength); codeAttribute.exceptionsAccept(clazz, method, this); // Write the code attributes. dataOutput.writeShort(codeAttribute.u2attributesCount); codeAttribute.attributesAccept(clazz, method, ProgramClassWriter.this); } public void visitStackMapAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, StackMapAttribute stackMapAttribute) { // Write the stack map frames (only full frames, without tag). dataOutput.writeShort(stackMapAttribute.u2stackMapFramesCount); stackMapAttribute.stackMapFramesAccept(clazz, method, codeAttribute, stackMapFrameBodyWriter); } public void visitStackMapTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, StackMapTableAttribute stackMapTableAttribute) { // Write the stack map frames. dataOutput.writeShort(stackMapTableAttribute.u2stackMapFramesCount); stackMapTableAttribute.stackMapFramesAccept(clazz, method, codeAttribute, this); } public void visitLineNumberTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LineNumberTableAttribute lineNumberTableAttribute) { // Write the line numbers. dataOutput.writeShort(lineNumberTableAttribute.u2lineNumberTableLength); lineNumberTableAttribute.lineNumbersAccept(clazz, method, codeAttribute, this); } public void visitLocalVariableTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTableAttribute localVariableTableAttribute) { // Write the local variables. dataOutput.writeShort(localVariableTableAttribute.u2localVariableTableLength); localVariableTableAttribute.localVariablesAccept(clazz, method, codeAttribute, this); } public void visitLocalVariableTypeTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTypeTableAttribute localVariableTypeTableAttribute) { // Write the local variable types. dataOutput.writeShort(localVariableTypeTableAttribute.u2localVariableTypeTableLength); localVariableTypeTableAttribute.localVariablesAccept(clazz, method, codeAttribute, this); } public void visitAnyAnnotationsAttribute(Clazz clazz, AnnotationsAttribute annotationsAttribute) { // Write the annotations. dataOutput.writeShort(annotationsAttribute.u2annotationsCount); annotationsAttribute.annotationsAccept(clazz, this); } public void visitAnyParameterAnnotationsAttribute(Clazz clazz, Method method, ParameterAnnotationsAttribute parameterAnnotationsAttribute) { // Write the parameter annotations. dataOutput.writeByte(parameterAnnotationsAttribute.u2parametersCount); for (int parameterIndex = 0; parameterIndex < parameterAnnotationsAttribute.u2parametersCount; parameterIndex++) { // Write the parameter annotations of the given parameter. Annotation[] annotations = parameterAnnotationsAttribute.parameterAnnotations[parameterIndex]; int u2annotationsCount = annotations.length; dataOutput.writeShort(u2annotationsCount); for (int index = 0; index < u2annotationsCount; index++) { Annotation annotation = annotations[index]; this.visitAnnotation(clazz, annotation); } } } public void visitAnnotationDefaultAttribute(Clazz clazz, Method method, AnnotationDefaultAttribute annotationDefaultAttribute) { // Write the default element value. annotationDefaultAttribute.defaultValue.accept(clazz, null, this); } // Implementations for InnerClassesInfoVisitor. public void visitInnerClassesInfo(Clazz clazz, InnerClassesInfo innerClassesInfo) { dataOutput.writeShort(innerClassesInfo.u2innerClassIndex); dataOutput.writeShort(innerClassesInfo.u2outerClassIndex); dataOutput.writeShort(innerClassesInfo.u2innerNameIndex); dataOutput.writeShort(innerClassesInfo.u2innerClassAccessFlags); } // Implementations for ExceptionInfoVisitor. public void visitExceptionInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, ExceptionInfo exceptionInfo) { dataOutput.writeShort(exceptionInfo.u2startPC); dataOutput.writeShort(exceptionInfo.u2endPC); dataOutput.writeShort(exceptionInfo.u2handlerPC); dataOutput.writeShort(exceptionInfo.u2catchType); } // Implementations for StackMapFrameVisitor. public void visitAnyStackMapFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, StackMapFrame stackMapFrame) { // Write the stack map frame tag. dataOutput.writeByte(stackMapFrame.getTag()); // Write the actual body. stackMapFrame.accept(clazz, method, codeAttribute, offset, stackMapFrameBodyWriter); } // Implementations for LineNumberInfoVisitor. public void visitLineNumberInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, LineNumberInfo lineNumberInfo) { dataOutput.writeShort(lineNumberInfo.u2startPC); dataOutput.writeShort(lineNumberInfo.u2lineNumber); } // Implementations for LocalVariableInfoVisitor. public void visitLocalVariableInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableInfo localVariableInfo) { dataOutput.writeShort(localVariableInfo.u2startPC); dataOutput.writeShort(localVariableInfo.u2length); dataOutput.writeShort(localVariableInfo.u2nameIndex); dataOutput.writeShort(localVariableInfo.u2descriptorIndex); dataOutput.writeShort(localVariableInfo.u2index); } // Implementations for LocalVariableTypeInfoVisitor. public void visitLocalVariableTypeInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTypeInfo localVariableTypeInfo) { dataOutput.writeShort(localVariableTypeInfo.u2startPC); dataOutput.writeShort(localVariableTypeInfo.u2length); dataOutput.writeShort(localVariableTypeInfo.u2nameIndex); dataOutput.writeShort(localVariableTypeInfo.u2signatureIndex); dataOutput.writeShort(localVariableTypeInfo.u2index); } // Implementations for AnnotationVisitor. public void visitAnnotation(Clazz clazz, Annotation annotation) { // Write the annotation type. dataOutput.writeShort(annotation.u2typeIndex); // Write the element value pairs. dataOutput.writeShort(annotation.u2elementValuesCount); annotation.elementValuesAccept(clazz, this); } // Implementations for ElementValueVisitor. public void visitAnyElementValue(Clazz clazz, Annotation annotation, ElementValue elementValue) { // Write the element name index, if applicable. int u2elementNameIndex = elementValue.u2elementNameIndex; if (u2elementNameIndex != 0) { dataOutput.writeShort(u2elementNameIndex); } // Write the tag. dataOutput.writeByte(elementValue.getTag()); // Write the actual body. elementValue.accept(clazz, annotation, elementValueBodyWriter); } } private class StackMapFrameBodyWriter extends SimplifiedVisitor implements StackMapFrameVisitor, VerificationTypeVisitor { public void visitSameZeroFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, SameZeroFrame sameZeroFrame) { if (sameZeroFrame.getTag() == StackMapFrame.SAME_ZERO_FRAME_EXTENDED) { dataOutput.writeShort(sameZeroFrame.u2offsetDelta); } } public void visitSameOneFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, SameOneFrame sameOneFrame) { if (sameOneFrame.getTag() == StackMapFrame.SAME_ONE_FRAME_EXTENDED) { dataOutput.writeShort(sameOneFrame.u2offsetDelta); } // Write the verification type of the stack entry. sameOneFrame.stackItemAccept(clazz, method, codeAttribute, offset, this); } public void visitLessZeroFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, LessZeroFrame lessZeroFrame) { dataOutput.writeShort(lessZeroFrame.u2offsetDelta); } public void visitMoreZeroFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, MoreZeroFrame moreZeroFrame) { dataOutput.writeShort(moreZeroFrame.u2offsetDelta); // Write the verification types of the additional local variables. moreZeroFrame.additionalVariablesAccept(clazz, method, codeAttribute, offset, this); } public void visitFullFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, FullFrame fullFrame) { dataOutput.writeShort(fullFrame.u2offsetDelta); // Write the verification types of the local variables. dataOutput.writeShort(fullFrame.variablesCount); fullFrame.variablesAccept(clazz, method, codeAttribute, offset, this); // Write the verification types of the stack entries. dataOutput.writeShort(fullFrame.stackCount); fullFrame.stackAccept(clazz, method, codeAttribute, offset, this); } // Implementations for VerificationTypeVisitor. public void visitAnyVerificationType(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, VerificationType verificationType) { // Write the verification type tag. dataOutput.writeByte(verificationType.getTag()); // Write the actual body. verificationType.accept(clazz, method, codeAttribute, offset, verificationTypeBodyWriter); } } private class VerificationTypeBodyWriter extends SimplifiedVisitor implements VerificationTypeVisitor { // Implementations for VerificationTypeVisitor. public void visitAnyVerificationType(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, VerificationType verificationType) { // Most verification types don't contain any additional information. } public void visitObjectType(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ObjectType objectType) { dataOutput.writeShort(objectType.u2classIndex); } public void visitUninitializedType(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, UninitializedType uninitializedType) { dataOutput.writeShort(uninitializedType.u2newInstructionOffset); } } private class ElementValueBodyWriter extends SimplifiedVisitor implements ElementValueVisitor { // Implementations for ElementValueVisitor. public void visitConstantElementValue(Clazz clazz, Annotation annotation, ConstantElementValue constantElementValue) { dataOutput.writeShort(constantElementValue.u2constantValueIndex); } public void visitEnumConstantElementValue(Clazz clazz, Annotation annotation, EnumConstantElementValue enumConstantElementValue) { dataOutput.writeShort(enumConstantElementValue.u2typeNameIndex); dataOutput.writeShort(enumConstantElementValue.u2constantNameIndex); } public void visitClassElementValue(Clazz clazz, Annotation annotation, ClassElementValue classElementValue) { dataOutput.writeShort(classElementValue.u2classInfoIndex); } public void visitAnnotationElementValue(Clazz clazz, Annotation annotation, AnnotationElementValue annotationElementValue) { // Write the annotation. attributeBodyWriter.visitAnnotation(clazz, annotationElementValue.annotationValue); } public void visitArrayElementValue(Clazz clazz, Annotation annotation, ArrayElementValue arrayElementValue) { // Write the element values. dataOutput.writeShort(arrayElementValue.u2elementValuesCount); arrayElementValue.elementValuesAccept(clazz, annotation, attributeBodyWriter); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -