📄 programclassreader.java
字号:
public void visitMoreZeroFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, MoreZeroFrame moreZeroFrame) { moreZeroFrame.u2offsetDelta = dataInput.readUnsignedShort(); // Read the verification types of the additional local variables. moreZeroFrame.additionalVariables = new VerificationType[moreZeroFrame.additionalVariablesCount]; for (int index = 0; index < moreZeroFrame.additionalVariablesCount; index++) { VerificationType verificationType = createVerificationType(); verificationType.accept(clazz, method, codeAttribute, offset, this); moreZeroFrame.additionalVariables[index] = verificationType; } } public void visitFullFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, FullFrame fullFrame) { fullFrame.u2offsetDelta = dataInput.readUnsignedShort(); // Read the verification types of the local variables. fullFrame.variablesCount = dataInput.readUnsignedShort(); fullFrame.variables = new VerificationType[fullFrame.variablesCount]; for (int index = 0; index < fullFrame.variablesCount; index++) { VerificationType verificationType = createVerificationType(); verificationType.variablesAccept(clazz, method, codeAttribute, offset, index, this); fullFrame.variables[index] = verificationType; } // Read the verification types of the stack entries. fullFrame.stackCount = dataInput.readUnsignedShort(); fullFrame.stack = new VerificationType[fullFrame.stackCount]; for (int index = 0; index < fullFrame.stackCount; index++) { VerificationType verificationType = createVerificationType(); verificationType.stackAccept(clazz, method, codeAttribute, offset, index, this); fullFrame.stack[index] = verificationType; } } // 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) { objectType.u2classIndex = dataInput.readUnsignedShort(); } public void visitUninitializedType(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, UninitializedType uninitializedType) { uninitializedType.u2newInstructionOffset = dataInput.readUnsignedShort(); } // Implementations for LineNumberInfoVisitor. public void visitLineNumberInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, LineNumberInfo lineNumberInfo) { lineNumberInfo.u2startPC = dataInput.readUnsignedShort(); lineNumberInfo.u2lineNumber = dataInput.readUnsignedShort(); } // Implementations for LocalVariableInfoVisitor. public void visitLocalVariableInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableInfo localVariableInfo) { localVariableInfo.u2startPC = dataInput.readUnsignedShort(); localVariableInfo.u2length = dataInput.readUnsignedShort(); localVariableInfo.u2nameIndex = dataInput.readUnsignedShort(); localVariableInfo.u2descriptorIndex = dataInput.readUnsignedShort(); localVariableInfo.u2index = dataInput.readUnsignedShort(); } // Implementations for LocalVariableTypeInfoVisitor. public void visitLocalVariableTypeInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTypeInfo localVariableTypeInfo) { localVariableTypeInfo.u2startPC = dataInput.readUnsignedShort(); localVariableTypeInfo.u2length = dataInput.readUnsignedShort(); localVariableTypeInfo.u2nameIndex = dataInput.readUnsignedShort(); localVariableTypeInfo.u2signatureIndex = dataInput.readUnsignedShort(); localVariableTypeInfo.u2index = dataInput.readUnsignedShort(); } // Implementations for AnnotationVisitor. public void visitAnnotation(Clazz clazz, Annotation annotation) { // Read the annotation type. annotation.u2typeIndex = dataInput.readUnsignedShort(); // Read the element value pairs. annotation.u2elementValuesCount = dataInput.readUnsignedShort(); annotation.elementValues = new ElementValue[annotation.u2elementValuesCount]; for (int index = 0; index < annotation.u2elementValuesCount; index++) { int u2elementNameIndex = dataInput.readUnsignedShort(); ElementValue elementValue = createElementValue(); elementValue.u2elementNameIndex = u2elementNameIndex; elementValue.accept(clazz, annotation, this); annotation.elementValues[index] = elementValue; } } // Implementations for ElementValueVisitor. public void visitConstantElementValue(Clazz clazz, Annotation annotation, ConstantElementValue constantElementValue) { constantElementValue.u2constantValueIndex = dataInput.readUnsignedShort(); } public void visitEnumConstantElementValue(Clazz clazz, Annotation annotation, EnumConstantElementValue enumConstantElementValue) { enumConstantElementValue.u2typeNameIndex = dataInput.readUnsignedShort(); enumConstantElementValue.u2constantNameIndex = dataInput.readUnsignedShort(); } public void visitClassElementValue(Clazz clazz, Annotation annotation, ClassElementValue classElementValue) { classElementValue.u2classInfoIndex = dataInput.readUnsignedShort(); } public void visitAnnotationElementValue(Clazz clazz, Annotation annotation, AnnotationElementValue annotationElementValue) { // Read the annotation. Annotation annotationValue = new Annotation(); this.visitAnnotation(clazz, annotationValue); annotationElementValue.annotationValue = annotationValue; } public void visitArrayElementValue(Clazz clazz, Annotation annotation, ArrayElementValue arrayElementValue) { // Read the element values. arrayElementValue.u2elementValuesCount = dataInput.readUnsignedShort(); arrayElementValue.elementValues = new ElementValue[arrayElementValue.u2elementValuesCount]; for (int index = 0; index < arrayElementValue.u2elementValuesCount; index++) { ElementValue elementValue = createElementValue(); elementValue.accept(clazz, annotation, this); arrayElementValue.elementValues[index] = elementValue; } } // Small utility methods. private Constant createConstant() { int u1tag = dataInput.readUnsignedByte(); switch (u1tag) { case ClassConstants.CONSTANT_Utf8: return new Utf8Constant(); case ClassConstants.CONSTANT_Integer: return new IntegerConstant(); case ClassConstants.CONSTANT_Float: return new FloatConstant(); case ClassConstants.CONSTANT_Long: return new LongConstant(); case ClassConstants.CONSTANT_Double: return new DoubleConstant(); case ClassConstants.CONSTANT_String: return new StringConstant(); case ClassConstants.CONSTANT_Fieldref: return new FieldrefConstant(); case ClassConstants.CONSTANT_Methodref: return new MethodrefConstant(); case ClassConstants.CONSTANT_InterfaceMethodref: return new InterfaceMethodrefConstant(); case ClassConstants.CONSTANT_Class: return new ClassConstant(); case ClassConstants.CONSTANT_NameAndType: return new NameAndTypeConstant(); default: throw new RuntimeException("Unknown constant type ["+u1tag+"] in constant pool"); } } private Attribute createAttribute(Clazz clazz) { int u2attributeNameIndex = dataInput.readUnsignedShort(); int u4attributeLength = dataInput.readInt(); String attributeName = clazz.getString(u2attributeNameIndex); Attribute attribute = attributeName.equals(ClassConstants.ATTR_SourceFile) ? (Attribute)new SourceFileAttribute(): attributeName.equals(ClassConstants.ATTR_SourceDir) ? (Attribute)new SourceDirAttribute(): attributeName.equals(ClassConstants.ATTR_InnerClasses) ? (Attribute)new InnerClassesAttribute(): attributeName.equals(ClassConstants.ATTR_EnclosingMethod) ? (Attribute)new EnclosingMethodAttribute(): attributeName.equals(ClassConstants.ATTR_Deprecated) ? (Attribute)new DeprecatedAttribute(): attributeName.equals(ClassConstants.ATTR_Synthetic) ? (Attribute)new SyntheticAttribute(): attributeName.equals(ClassConstants.ATTR_Signature) ? (Attribute)new SignatureAttribute(): attributeName.equals(ClassConstants.ATTR_ConstantValue) ? (Attribute)new ConstantValueAttribute(): attributeName.equals(ClassConstants.ATTR_Exceptions) ? (Attribute)new ExceptionsAttribute(): attributeName.equals(ClassConstants.ATTR_Code) ? (Attribute)new CodeAttribute(): attributeName.equals(ClassConstants.ATTR_StackMap) ? (Attribute)new StackMapAttribute(): attributeName.equals(ClassConstants.ATTR_StackMapTable) ? (Attribute)new StackMapTableAttribute(): attributeName.equals(ClassConstants.ATTR_LineNumberTable) ? (Attribute)new LineNumberTableAttribute(): attributeName.equals(ClassConstants.ATTR_LocalVariableTable) ? (Attribute)new LocalVariableTableAttribute(): attributeName.equals(ClassConstants.ATTR_LocalVariableTypeTable) ? (Attribute)new LocalVariableTypeTableAttribute(): attributeName.equals(ClassConstants.ATTR_RuntimeVisibleAnnotations) ? (Attribute)new RuntimeVisibleAnnotationsAttribute(): attributeName.equals(ClassConstants.ATTR_RuntimeInvisibleAnnotations) ? (Attribute)new RuntimeInvisibleAnnotationsAttribute(): attributeName.equals(ClassConstants.ATTR_RuntimeVisibleParameterAnnotations) ? (Attribute)new RuntimeVisibleParameterAnnotationsAttribute(): attributeName.equals(ClassConstants.ATTR_RuntimeInvisibleParameterAnnotations) ? (Attribute)new RuntimeInvisibleParameterAnnotationsAttribute(): attributeName.equals(ClassConstants.ATTR_AnnotationDefault) ? (Attribute)new AnnotationDefaultAttribute(): (Attribute)new UnknownAttribute(u4attributeLength); attribute.u2attributeNameIndex = u2attributeNameIndex; return attribute; } private StackMapFrame createStackMapFrame() { int u1tag = dataInput.readUnsignedByte(); return u1tag < StackMapFrame.SAME_ONE_FRAME ? (StackMapFrame)new SameZeroFrame(u1tag) : u1tag < StackMapFrame.SAME_ONE_FRAME_EXTENDED ? (StackMapFrame)new SameOneFrame(u1tag) : u1tag < StackMapFrame.LESS_ZERO_FRAME ? (StackMapFrame)new SameOneFrame(u1tag) : u1tag < StackMapFrame.SAME_ZERO_FRAME_EXTENDED ? (StackMapFrame)new LessZeroFrame(u1tag) : u1tag < StackMapFrame.MORE_ZERO_FRAME ? (StackMapFrame)new SameZeroFrame(u1tag) : u1tag < StackMapFrame.FULL_FRAME ? (StackMapFrame)new MoreZeroFrame(u1tag) : (StackMapFrame)new FullFrame(); } private VerificationType createVerificationType() { int u1tag = dataInput.readUnsignedByte(); switch (u1tag) { case VerificationType.INTEGER_TYPE: return new IntegerType(); case VerificationType.FLOAT_TYPE: return new FloatType(); case VerificationType.LONG_TYPE: return new LongType(); case VerificationType.DOUBLE_TYPE: return new DoubleType(); case VerificationType.TOP_TYPE: return new TopType(); case VerificationType.OBJECT_TYPE: return new ObjectType(); case VerificationType.NULL_TYPE: return new NullType(); case VerificationType.UNINITIALIZED_TYPE: return new UninitializedType(); case VerificationType.UNINITIALIZED_THIS_TYPE: return new UninitializedThisType(); default: throw new RuntimeException("Unknown verification type ["+u1tag+"] in stack map frame"); } } private ElementValue createElementValue() { int u1tag = dataInput.readUnsignedByte(); switch (u1tag) { case ClassConstants.INTERNAL_TYPE_BOOLEAN: case ClassConstants.INTERNAL_TYPE_BYTE: case ClassConstants.INTERNAL_TYPE_CHAR: case ClassConstants.INTERNAL_TYPE_SHORT: case ClassConstants.INTERNAL_TYPE_INT: case ClassConstants.INTERNAL_TYPE_FLOAT: case ClassConstants.INTERNAL_TYPE_LONG: case ClassConstants.INTERNAL_TYPE_DOUBLE: case ClassConstants.ELEMENT_VALUE_STRING_CONSTANT: return new ConstantElementValue(u1tag); case ClassConstants.ELEMENT_VALUE_ENUM_CONSTANT: return new EnumConstantElementValue(); case ClassConstants.ELEMENT_VALUE_CLASS: return new ClassElementValue(); case ClassConstants.ELEMENT_VALUE_ANNOTATION: return new AnnotationElementValue(); case ClassConstants.ELEMENT_VALUE_ARRAY: return new ArrayElementValue(); default: throw new IllegalArgumentException("Unknown element value tag ["+u1tag+"]"); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -