/** * Constructs a <code>method_info</code> structure. The initial value of <code>access_flags</code> * is zero. * * @param cp a constant pool table * @param methodname method name * @param desc method descriptor * @see Descriptor */ public MethodInfo(ConstPool cp, String methodname, String desc) { this(cp); accessFlags = 0; name = cp.addUtf8Info(methodname); cachedName = methodname; descriptor = constPool.addUtf8Info(desc); }
void prune(ConstPool cp) { LinkedList newAttributes = new LinkedList(); AttributeInfo invisibleAnnotations = getAttribute(AnnotationsAttribute.invisibleTag); if (invisibleAnnotations != null) { invisibleAnnotations = invisibleAnnotations.copy(cp, null); newAttributes.add(invisibleAnnotations); } AttributeInfo visibleAnnotations = getAttribute(AnnotationsAttribute.visibleTag); if (visibleAnnotations != null) { visibleAnnotations = visibleAnnotations.copy(cp, null); newAttributes.add(visibleAnnotations); } AttributeInfo signature = getAttribute(SignatureAttribute.tag); if (signature != null) { signature = signature.copy(cp, null); newAttributes.add(signature); } int index = getConstantValue(); if (index != 0) { index = constPool.copy(index, cp, null); newAttributes.add(new ConstantAttribute(cp, index)); } attribute = newAttributes; name = cp.addUtf8Info(getName()); descriptor = cp.addUtf8Info(getDescriptor()); constPool = cp; }
void prune(ConstPool cp) { LinkedList newAttributes = new LinkedList(); AttributeInfo invisibleAnnotations = getAttribute(AnnotationsAttribute.invisibleTag); if (invisibleAnnotations != null) { invisibleAnnotations = invisibleAnnotations.copy(cp, null); newAttributes.add(invisibleAnnotations); } AttributeInfo visibleAnnotations = getAttribute(AnnotationsAttribute.visibleTag); if (visibleAnnotations != null) { visibleAnnotations = visibleAnnotations.copy(cp, null); newAttributes.add(visibleAnnotations); } AttributeInfo parameterInvisibleAnnotations = getAttribute(ParameterAnnotationsAttribute.invisibleTag); if (parameterInvisibleAnnotations != null) { parameterInvisibleAnnotations = parameterInvisibleAnnotations.copy(cp, null); newAttributes.add(parameterInvisibleAnnotations); } AttributeInfo parameterVisibleAnnotations = getAttribute(ParameterAnnotationsAttribute.visibleTag); if (parameterVisibleAnnotations != null) { parameterVisibleAnnotations = parameterVisibleAnnotations.copy(cp, null); newAttributes.add(parameterVisibleAnnotations); } AnnotationDefaultAttribute defaultAttribute = (AnnotationDefaultAttribute) getAttribute(AnnotationDefaultAttribute.tag); if (defaultAttribute != null) newAttributes.add(defaultAttribute); ExceptionsAttribute ea = getExceptionsAttribute(); if (ea != null) newAttributes.add(ea); AttributeInfo signature = getAttribute(SignatureAttribute.tag); if (signature != null) { signature = signature.copy(cp, null); newAttributes.add(signature); } attribute = newAttributes; name = cp.addUtf8Info(getName()); descriptor = cp.addUtf8Info(getDescriptor()); constPool = cp; }
private void renameType(int pos, int index) { String name = cpool.getUtf8Info(index); String newName = Descriptor.rename(name, classnames); if (!name.equals(newName)) { int index2 = cpool.addUtf8Info(newName); ByteArray.write16bit(index2, info, pos); } }
private void read(MethodInfo src, String methodname, Map classnames) throws BadBytecode { ConstPool destCp = constPool; accessFlags = src.accessFlags; name = destCp.addUtf8Info(methodname); cachedName = methodname; ConstPool srcCp = src.constPool; String desc = srcCp.getUtf8Info(src.descriptor); String desc2 = Descriptor.rename(desc, classnames); descriptor = destCp.addUtf8Info(desc2); attribute = new LinkedList(); ExceptionsAttribute eattr = src.getExceptionsAttribute(); if (eattr != null) attribute.add(eattr.copy(destCp, classnames)); CodeAttribute cattr = src.getCodeAttribute(); if (cattr != null) attribute.add(cattr.copy(destCp, classnames)); }
/** * Constructs an <code>attribute_info</code> structure. * * @param cp constant pool table * @param attrname attribute name * @param attrinfo <code>info</code> field of <code>attribute_info</code> structure. */ public AttributeInfo(ConstPool cp, String attrname, byte[] attrinfo) { this(cp, cp.addUtf8Info(attrname), attrinfo); }
/** * Copies a constant pool entry into the destination constant pool and returns the index of the * copied entry. That entry must be a Utf8Info representing a class name in the L<class name>; * form. * * @param srcIndex the index of the copied entry into the source constant pool. * @return the index of the copied item into the destination constant pool. */ int copyType(int srcIndex) { String name = srcPool.getUtf8Info(srcIndex); String newName = Descriptor.rename(name, classnames); return destPool.addUtf8Info(newName); }
/** * Sets a method descriptor. * * @see Descriptor */ public void setDescriptor(String desc) { if (!desc.equals(getDescriptor())) descriptor = constPool.addUtf8Info(desc); }
/** Sets a method name. */ public void setName(String newName) { name = constPool.addUtf8Info(newName); cachedName = newName; }
/** * Copies all constant pool items to a given new constant pool and replaces the original items * with the new ones. This is used for garbage collecting the items of removed fields and methods. * * @param cp the destination */ void compact(ConstPool cp) { name = cp.addUtf8Info(getName()); descriptor = cp.addUtf8Info(getDescriptor()); attribute = AttributeInfo.copyAll(attribute, cp); constPool = cp; }
/** * Constructs a <code>field_info</code> structure. * * @param cp a constant pool table * @param fieldName field name * @param desc field descriptor * @see Descriptor */ public FieldInfo(ConstPool cp, String fieldName, String desc) { this(cp); name = cp.addUtf8Info(fieldName); cachedName = fieldName; descriptor = cp.addUtf8Info(desc); }