Exemplo n.º 1
0
class ConstantClassInfo(ConstantInfo):
    def __init__(self, constant_pool):
        from ch07.classfile.ConstantPool import ConstantPool
        self.cp = ConstantPool(constant_pool)
        self.name_index = 0

    def read_info(self, class_reader):
        self.name_index = int.from_bytes(class_reader.read_unit16(),
                                         byteorder="big")

    @property
    def name(self):
        return self.cp.get_utf8(self.name_index)
Exemplo n.º 2
0
class ConstantStringInfo(ConstantInfo):
    def __init__(self, constant_pool):
        from ch07.classfile.ConstantPool import ConstantPool
        self.cp = ConstantPool(constant_pool)
        self.string_index = ""

    # 读取常量池索引
    def read_info(self, class_reader):
        self.string_index = int.from_bytes(class_reader.read_unit16(), byteorder="big")

    # 按索引从常量池中查找字符串
    def __str__(self):
        return self.cp.get_utf8(self.string_index)