📄 programclassreader.java
字号:
public void visitSourceFileAttribute(Clazz clazz, SourceFileAttribute sourceFileAttribute) { sourceFileAttribute.u2sourceFileIndex = dataInput.readUnsignedShort(); } public void visitSourceDirAttribute(Clazz clazz, SourceDirAttribute sourceDirAttribute) { sourceDirAttribute.u2sourceDirIndex = dataInput.readUnsignedShort(); } public void visitInnerClassesAttribute(Clazz clazz, InnerClassesAttribute innerClassesAttribute) { // Read the inner classes. innerClassesAttribute.u2classesCount = dataInput.readUnsignedShort(); innerClassesAttribute.classes = new InnerClassesInfo[innerClassesAttribute.u2classesCount]; for (int index = 0; index < innerClassesAttribute.u2classesCount; index++) { InnerClassesInfo innerClassesInfo = new InnerClassesInfo(); this.visitInnerClassesInfo(clazz, innerClassesInfo); innerClassesAttribute.classes[index] = innerClassesInfo; } } public void visitEnclosingMethodAttribute(Clazz clazz, EnclosingMethodAttribute enclosingMethodAttribute) { enclosingMethodAttribute.u2classIndex = dataInput.readUnsignedShort(); enclosingMethodAttribute.u2nameAndTypeIndex = dataInput.readUnsignedShort(); } public void visitDeprecatedAttribute(Clazz clazz, DeprecatedAttribute deprecatedAttribute) { // This attribute does not contain any additional information. } public void visitSyntheticAttribute(Clazz clazz, SyntheticAttribute syntheticAttribute) { // This attribute does not contain any additional information. } public void visitSignatureAttribute(Clazz clazz, SignatureAttribute signatureAttribute) { signatureAttribute.u2signatureIndex = dataInput.readUnsignedShort(); } public void visitConstantValueAttribute(Clazz clazz, Field field, ConstantValueAttribute constantValueAttribute) { constantValueAttribute.u2constantValueIndex = dataInput.readUnsignedShort(); } public void visitExceptionsAttribute(Clazz clazz, Method method, ExceptionsAttribute exceptionsAttribute) { // Read the exceptions. exceptionsAttribute.u2exceptionIndexTableLength = dataInput.readUnsignedShort(); exceptionsAttribute.u2exceptionIndexTable = new int[exceptionsAttribute.u2exceptionIndexTableLength]; for (int index = 0; index < exceptionsAttribute.u2exceptionIndexTableLength; index++) { exceptionsAttribute.u2exceptionIndexTable[index] = dataInput.readUnsignedShort(); } } public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute) { // Read the stack size and local variable frame size. codeAttribute.u2maxStack = dataInput.readUnsignedShort(); codeAttribute.u2maxLocals = dataInput.readUnsignedShort(); // Read the byte code. codeAttribute.u4codeLength = dataInput.readInt(); byte[] code = new byte[codeAttribute.u4codeLength]; dataInput.readFully(code); codeAttribute.code = code; // Read the exceptions. codeAttribute.u2exceptionTableLength = dataInput.readUnsignedShort(); codeAttribute.exceptionTable = new ExceptionInfo[codeAttribute.u2exceptionTableLength]; for (int index = 0; index < codeAttribute.u2exceptionTableLength; index++) { ExceptionInfo exceptionInfo = new ExceptionInfo(); this.visitExceptionInfo(clazz, method, codeAttribute, exceptionInfo); codeAttribute.exceptionTable[index] = exceptionInfo; } // Read the code attributes. codeAttribute.u2attributesCount = dataInput.readUnsignedShort(); codeAttribute.attributes = new Attribute[codeAttribute.u2attributesCount]; for (int index = 0; index < codeAttribute.u2attributesCount; index++) { Attribute attribute = createAttribute(clazz); attribute.accept(clazz, method, codeAttribute, this); codeAttribute.attributes[index] = attribute; } } public void visitStackMapAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, StackMapAttribute stackMapAttribute) { // Read the stack map frames (only full frames, without tag). stackMapAttribute.u2stackMapFramesCount = dataInput.readUnsignedShort(); stackMapAttribute.stackMapFrames = new FullFrame[stackMapAttribute.u2stackMapFramesCount]; for (int index = 0; index < stackMapAttribute.u2stackMapFramesCount; index++) { FullFrame stackMapFrame = new FullFrame(); this.visitFullFrame(clazz, method, codeAttribute, index, stackMapFrame); stackMapAttribute.stackMapFrames[index] = stackMapFrame; } } public void visitStackMapTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, StackMapTableAttribute stackMapTableAttribute) { // Read the stack map frames. stackMapTableAttribute.u2stackMapFramesCount = dataInput.readUnsignedShort(); stackMapTableAttribute.stackMapFrames = new StackMapFrame[stackMapTableAttribute.u2stackMapFramesCount]; for (int index = 0; index < stackMapTableAttribute.u2stackMapFramesCount; index++) { StackMapFrame stackMapFrame = createStackMapFrame(); stackMapFrame.accept(clazz, method, codeAttribute, 0, this); stackMapTableAttribute.stackMapFrames[index] = stackMapFrame; } } public void visitLineNumberTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LineNumberTableAttribute lineNumberTableAttribute) { // Read the line numbers. lineNumberTableAttribute.u2lineNumberTableLength = dataInput.readUnsignedShort(); lineNumberTableAttribute.lineNumberTable = new LineNumberInfo[lineNumberTableAttribute.u2lineNumberTableLength]; for (int index = 0; index < lineNumberTableAttribute.u2lineNumberTableLength; index++) { LineNumberInfo lineNumberInfo = new LineNumberInfo(); this.visitLineNumberInfo(clazz, method, codeAttribute, lineNumberInfo); lineNumberTableAttribute.lineNumberTable[index] = lineNumberInfo; } } public void visitLocalVariableTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTableAttribute localVariableTableAttribute) { // Read the local variables. localVariableTableAttribute.u2localVariableTableLength = dataInput.readUnsignedShort(); localVariableTableAttribute.localVariableTable = new LocalVariableInfo[localVariableTableAttribute.u2localVariableTableLength]; for (int index = 0; index < localVariableTableAttribute.u2localVariableTableLength; index++) { LocalVariableInfo localVariableInfo = new LocalVariableInfo(); this.visitLocalVariableInfo(clazz, method, codeAttribute, localVariableInfo); localVariableTableAttribute.localVariableTable[index] = localVariableInfo; } } public void visitLocalVariableTypeTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTypeTableAttribute localVariableTypeTableAttribute) { // Read the local variable types. localVariableTypeTableAttribute.u2localVariableTypeTableLength = dataInput.readUnsignedShort(); localVariableTypeTableAttribute.localVariableTypeTable = new LocalVariableTypeInfo[localVariableTypeTableAttribute.u2localVariableTypeTableLength]; for (int index = 0; index < localVariableTypeTableAttribute.u2localVariableTypeTableLength; index++) { LocalVariableTypeInfo localVariableTypeInfo = new LocalVariableTypeInfo(); this.visitLocalVariableTypeInfo(clazz, method, codeAttribute, localVariableTypeInfo); localVariableTypeTableAttribute.localVariableTypeTable[index] = localVariableTypeInfo; } } public void visitAnyAnnotationsAttribute(Clazz clazz, AnnotationsAttribute annotationsAttribute) { // Read the annotations. annotationsAttribute.u2annotationsCount = dataInput.readUnsignedShort(); annotationsAttribute.annotations = new Annotation[annotationsAttribute.u2annotationsCount]; for (int index = 0; index < annotationsAttribute.u2annotationsCount; index++) { Annotation annotation = new Annotation(); this.visitAnnotation(clazz, annotation); annotationsAttribute.annotations[index] = annotation; } } public void visitAnyParameterAnnotationsAttribute(Clazz clazz, Method method, ParameterAnnotationsAttribute parameterAnnotationsAttribute) { // Read the parameter annotations. parameterAnnotationsAttribute.u2parametersCount = dataInput.readUnsignedByte(); parameterAnnotationsAttribute.parameterAnnotations = new Annotation[parameterAnnotationsAttribute.u2parametersCount][]; for (int parameterIndex = 0; parameterIndex < parameterAnnotationsAttribute.u2parametersCount; parameterIndex++) { // Read the parameter annotations of the given parameter. int u2annotationsCount = dataInput.readUnsignedShort(); Annotation[] annotations = new Annotation[u2annotationsCount]; for (int index = 0; index < u2annotationsCount; index++) { Annotation annotation = new Annotation(); this.visitAnnotation(clazz, annotation); annotations[index] = annotation; } parameterAnnotationsAttribute.parameterAnnotations[parameterIndex] = annotations; } } public void visitAnnotationDefaultAttribute(Clazz clazz, Method method, AnnotationDefaultAttribute annotationDefaultAttribute) { // Read the default element value. ElementValue elementValue = createElementValue(); elementValue.accept(clazz, null, this); annotationDefaultAttribute.defaultValue = elementValue; } // Implementations for InnerClassesInfoVisitor. public void visitInnerClassesInfo(Clazz clazz, InnerClassesInfo innerClassesInfo) { innerClassesInfo.u2innerClassIndex = dataInput.readUnsignedShort(); innerClassesInfo.u2outerClassIndex = dataInput.readUnsignedShort(); innerClassesInfo.u2innerNameIndex = dataInput.readUnsignedShort(); innerClassesInfo.u2innerClassAccessFlags = dataInput.readUnsignedShort(); } // Implementations for ExceptionInfoVisitor. public void visitExceptionInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, ExceptionInfo exceptionInfo) { exceptionInfo.u2startPC = dataInput.readUnsignedShort(); exceptionInfo.u2endPC = dataInput.readUnsignedShort(); exceptionInfo.u2handlerPC = dataInput.readUnsignedShort(); exceptionInfo.u2catchType = dataInput.readUnsignedShort(); } // Implementations for StackMapFrameVisitor. public void visitSameZeroFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, SameZeroFrame sameZeroFrame) { if (sameZeroFrame.getTag() == StackMapFrame.SAME_ZERO_FRAME_EXTENDED) { sameZeroFrame.u2offsetDelta = dataInput.readUnsignedShort(); } } public void visitSameOneFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, SameOneFrame sameOneFrame) { if (sameOneFrame.getTag() == StackMapFrame.SAME_ONE_FRAME_EXTENDED) { sameOneFrame.u2offsetDelta = dataInput.readUnsignedShort(); } // Read the verification type of the stack entry. VerificationType verificationType = createVerificationType(); verificationType.accept(clazz, method, codeAttribute, offset, this); sameOneFrame.stackItem = verificationType; } public void visitLessZeroFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, LessZeroFrame lessZeroFrame) { lessZeroFrame.u2offsetDelta = dataInput.readUnsignedShort(); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -