📄 constantpooleditor.java
字号:
* given class and method, in the given class. * @return the constant pool index of the InterfaceMethodrefConstant. */ public int addInterfaceMethodrefConstant(ProgramClass programClass, Clazz referencedClass, Member referencedMember) { return addInterfaceMethodrefConstant(programClass, referencedClass.getName(), referencedMember.getName(referencedClass), referencedMember.getDescriptor(referencedClass), referencedClass, referencedMember); } /** * Finds or creates a InterfaceMethodrefConstant constant pool entry with the * given class constant pool entry index, method name, and descriptor, in * the given class. * @return the constant pool index of the InterfaceMethodrefConstant. */ public int addInterfaceMethodrefConstant(ProgramClass programClass, int classIndex, String name, String descriptor, Clazz referencedClass, Member referencedMember) { return addInterfaceMethodrefConstant(programClass, classIndex, addNameAndTypeConstant(programClass, name, descriptor), referencedClass, referencedMember); } /** * Finds or creates a InterfaceMethodrefConstant constant pool entry with the * given class constant pool entry index and name and type constant pool * entry index the given class. * @return the constant pool index of the InterfaceMethodrefConstant. */ public int addInterfaceMethodrefConstant(ProgramClass programClass, int classIndex, int nameAndTypeIndex, Clazz referencedClass, Member referencedMember) { int constantPoolCount = programClass.u2constantPoolCount; Constant[] constantPool = programClass.constantPool; // Check if the entry already exists. for (int index = 1; index < constantPoolCount; index++) { Constant constant = constantPool[index]; if (constant != null && constant.getTag() == ClassConstants.CONSTANT_InterfaceMethodref) { InterfaceMethodrefConstant methodrefConstant = (InterfaceMethodrefConstant)constant; if (methodrefConstant.u2classIndex == classIndex && methodrefConstant.u2nameAndTypeIndex == nameAndTypeIndex) { return index; } } } return addConstant(programClass, new InterfaceMethodrefConstant(classIndex, nameAndTypeIndex, referencedClass, referencedMember)); } /** * Finds or creates a MethodrefConstant constant pool entry for the given * class and method, in the given class. * @return the constant pool index of the MethodrefConstant. */ public int addMethodrefConstant(ProgramClass programClass, Clazz referencedClass, Member referencedMember) { return addMethodrefConstant(programClass, referencedClass.getName(), referencedMember.getName(referencedClass), referencedMember.getDescriptor(referencedClass), referencedClass, referencedMember); } /** * Finds or creates a MethodrefConstant constant pool entry with the given * class name, method name, and descriptor, in the given class. * @return the constant pool index of the MethodrefConstant. */ public int addMethodrefConstant(ProgramClass programClass, String className, String name, String descriptor, Clazz referencedClass, Member referencedMember) { return addMethodrefConstant(programClass, className, addNameAndTypeConstant(programClass, name, descriptor), referencedClass, referencedMember); } /** * Finds or creates a MethodrefConstant constant pool entry with the given * class name, method name, and descriptor, in the given class. * @return the constant pool index of the MethodrefConstant. */ public int addMethodrefConstant(ProgramClass programClass, String className, int nameAndTypeIndex, Clazz referencedClass, Member referencedMember) { return addMethodrefConstant(programClass, addClassConstant(programClass, className, referencedClass), nameAndTypeIndex, referencedClass, referencedMember); } /** * Finds or creates a MethodrefConstant constant pool entry with the given * class constant pool entry index, method name, and descriptor, in the * given class. * @return the constant pool index of the MethodrefConstant. */ public int addMethodrefConstant(ProgramClass programClass, int classIndex, String name, String descriptor, Clazz referencedClass, Member referencedMember) { return addMethodrefConstant(programClass, classIndex, addNameAndTypeConstant(programClass, name, descriptor), referencedClass, referencedMember); } /** * Finds or creates a MethodrefConstant constant pool entry with the given * class constant pool entry index and name and type constant pool entry index * the given class. * @return the constant pool index of the MethodrefConstant. */ public int addMethodrefConstant(ProgramClass programClass, int classIndex, int nameAndTypeIndex, Clazz referencedClass, Member referencedMember) { int constantPoolCount = programClass.u2constantPoolCount; Constant[] constantPool = programClass.constantPool; // Check if the entry already exists. for (int index = 1; index < constantPoolCount; index++) { Constant constant = constantPool[index]; if (constant != null && constant.getTag() == ClassConstants.CONSTANT_Methodref) { MethodrefConstant methodrefConstant = (MethodrefConstant)constant; if (methodrefConstant.u2classIndex == classIndex && methodrefConstant.u2nameAndTypeIndex == nameAndTypeIndex) { return index; } } } return addConstant(programClass, new MethodrefConstant(classIndex, nameAndTypeIndex, referencedClass, referencedMember)); } /** * Finds or creates a ClassConstant constant pool entry for the given class, * in the given class. * @return the constant pool index of the ClassConstant. */ public int addClassConstant(ProgramClass programClass, Clazz referencedClass) { return addClassConstant(programClass, referencedClass.getName(), referencedClass); } /** * Finds or creates a ClassConstant constant pool entry with the given name, * in the given class. * @return the constant pool index of the ClassConstant. */ public int addClassConstant(ProgramClass programClass, String name, Clazz referencedClass) { int constantPoolCount = programClass.u2constantPoolCount; Constant[] constantPool = programClass.constantPool; // Check if the entry already exists. for (int index = 1; index < constantPoolCount; index++) { Constant constant = constantPool[index]; if (constant != null && constant.getTag() == ClassConstants.CONSTANT_Class) { ClassConstant classConstant = (ClassConstant)constant; if (classConstant.getName(programClass).equals(name)) { return index; } } } int nameIndex = addUtf8Constant(programClass, name); return addConstant(programClass, new ClassConstant(nameIndex, referencedClass)); } /** * Finds or creates a NameAndTypeConstant constant pool entry with the given * name and type, in the given class. * @return the constant pool index of the NameAndTypeConstant. */ public int addNameAndTypeConstant(ProgramClass programClass, String name, String type) { int constantPoolCount = programClass.u2constantPoolCount; Constant[] constantPool = programClass.constantPool; // Check if the entry already exists. for (int index = 1; index < constantPoolCount; index++) { Constant constant = constantPool[index]; if (constant != null && constant.getTag() == ClassConstants.CONSTANT_NameAndType) { NameAndTypeConstant nameAndTypeConstant = (NameAndTypeConstant)constant; if (nameAndTypeConstant.getName(programClass).equals(name) && nameAndTypeConstant.getType(programClass).equals(type)) { return index; } } } int nameIndex = addUtf8Constant(programClass, name); int descriptorIndex = addUtf8Constant(programClass, type); return addConstant(programClass, new NameAndTypeConstant(nameIndex, descriptorIndex)); } /** * Finds or creates a Utf8Constant constant pool entry for the given string, * in the given class. * @return the constant pool index of the Utf8Constant. */ public int addUtf8Constant(ProgramClass programClass, String string) { int constantPoolCount = programClass.u2constantPoolCount; Constant[] constantPool = programClass.constantPool; // Check if the entry already exists. for (int index = 1; index < constantPoolCount; index++) { Constant constant = constantPool[index]; if (constant != null && constant.getTag() == ClassConstants.CONSTANT_Utf8) { Utf8Constant utf8Constant = (Utf8Constant)constant; if (utf8Constant.getString().equals(string)) { return index; } } } return addConstant(programClass, new Utf8Constant(string)); } /** * Adds a given constant pool entry to the end of the constant pool * in the given class. * @return the constant pool index for the added entry. */ public int addConstant(ProgramClass programClass, Constant constant) { int constantPoolCount = programClass.u2constantPoolCount; Constant[] constantPool = programClass.constantPool; // Make sure there is enough space for another constant pool entry. if (constantPool.length < constantPoolCount+2) { programClass.constantPool = new Constant[constantPoolCount+2]; System.arraycopy(constantPool, 0, programClass.constantPool, 0, constantPoolCount); constantPool = programClass.constantPool; } if (DEBUG) { System.out.println(programClass.getName()+": adding ["+constant.getClass().getName()+"] at index "+programClass.u2constantPoolCount); } // Create a new Utf8Constant for the given string. constantPool[programClass.u2constantPoolCount++] = constant; // Long constants and double constants take up two entries in the // constant pool. int tag = constant.getTag(); if (tag == ClassConstants.CONSTANT_Long || tag == ClassConstants.CONSTANT_Double) { constantPool[programClass.u2constantPoolCount++] = null; } return constantPoolCount; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -