169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal/* 269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * Javassist, a Java-bytecode translator toolkit. 369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * Copyright (C) 1999-2007 Shigeru Chiba. All Rights Reserved. 469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * 569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * The contents of this file are subject to the Mozilla Public License Version 669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * 1.1 (the "License"); you may not use this file except in compliance with 769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * the License. Alternatively, the contents of this file may be used under 869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * the terms of the GNU Lesser General Public License Version 2.1 or later. 969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * 1069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * Software distributed under the License is distributed on an "AS IS" basis, 1169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 1269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * for the specific language governing rights and limitations under the 1369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * License. 1469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal */ 1569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 1669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigalpackage javassist.bytecode; 1769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 1869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigalimport java.io.DataInputStream; 1969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigalimport java.io.DataOutputStream; 2069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigalimport java.io.IOException; 2169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigalimport java.util.Map; 2269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigalimport java.util.ArrayList; 2369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigalimport java.util.ListIterator; 2469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigalimport java.util.List; 2569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigalimport java.util.Iterator; 2669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 2769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal// Note: if you define a new subclass of AttributeInfo, then 2869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal// update AttributeInfo.read(), .copy(), and (maybe) write(). 2969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 3069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal/** 3169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * <code>attribute_info</code> structure. 3269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal */ 3369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigalpublic class AttributeInfo { 3469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal protected ConstPool constPool; 3569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal int name; 3669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal byte[] info; 3769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 3869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal protected AttributeInfo(ConstPool cp, int attrname, byte[] attrinfo) { 3969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal constPool = cp; 4069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal name = attrname; 4169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal info = attrinfo; 4269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal } 4369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 4469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal protected AttributeInfo(ConstPool cp, String attrname) { 4569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal this(cp, attrname, (byte[])null); 4669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal } 4769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 4869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal /** 4969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * Constructs an <code>attribute_info</code> structure. 5069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * 5169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * @param cp constant pool table 5269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * @param attrname attribute name 5369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * @param attrinfo <code>info</code> field 5469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * of <code>attribute_info</code> structure. 5569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal */ 5669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal public AttributeInfo(ConstPool cp, String attrname, byte[] attrinfo) { 5769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal this(cp, cp.addUtf8Info(attrname), attrinfo); 5869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal } 5969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 6069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal protected AttributeInfo(ConstPool cp, int n, DataInputStream in) 6169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal throws IOException 6269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal { 6369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal constPool = cp; 6469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal name = n; 6569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal int len = in.readInt(); 6669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal info = new byte[len]; 6769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal if (len > 0) 6869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal in.readFully(info); 6969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal } 7069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 7169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal static AttributeInfo read(ConstPool cp, DataInputStream in) 7269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal throws IOException 7369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal { 7469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal int name = in.readUnsignedShort(); 7569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal String nameStr = cp.getUtf8Info(name); 7669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal if (nameStr.charAt(0) < 'L') { 7769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal if (nameStr.equals(AnnotationDefaultAttribute.tag)) 7869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal return new AnnotationDefaultAttribute(cp, name, in); 7969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal else if (nameStr.equals(CodeAttribute.tag)) 8069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal return new CodeAttribute(cp, name, in); 8169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal else if (nameStr.equals(ConstantAttribute.tag)) 8269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal return new ConstantAttribute(cp, name, in); 8369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal else if (nameStr.equals(DeprecatedAttribute.tag)) 8469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal return new DeprecatedAttribute(cp, name, in); 8569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal else if (nameStr.equals(EnclosingMethodAttribute.tag)) 8669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal return new EnclosingMethodAttribute(cp, name, in); 8769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal else if (nameStr.equals(ExceptionsAttribute.tag)) 8869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal return new ExceptionsAttribute(cp, name, in); 8969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal else if (nameStr.equals(InnerClassesAttribute.tag)) 9069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal return new InnerClassesAttribute(cp, name, in); 9169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal } 9269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal else { 9369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal /* Note that the names of Annotations attributes begin with 'R'. 9469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal */ 9569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal if (nameStr.equals(LineNumberAttribute.tag)) 9669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal return new LineNumberAttribute(cp, name, in); 9769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal else if (nameStr.equals(LocalVariableAttribute.tag)) 9869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal return new LocalVariableAttribute(cp, name, in); 9969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal else if (nameStr.equals(LocalVariableTypeAttribute.tag)) 10069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal return new LocalVariableTypeAttribute(cp, name, in); 10169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal else if (nameStr.equals(AnnotationsAttribute.visibleTag) 10269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal || nameStr.equals(AnnotationsAttribute.invisibleTag)) { 10369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal // RuntimeVisibleAnnotations or RuntimeInvisibleAnnotations 10469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal return new AnnotationsAttribute(cp, name, in); 10569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal } 10669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal else if (nameStr.equals(ParameterAnnotationsAttribute.visibleTag) 10769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal || nameStr.equals(ParameterAnnotationsAttribute.invisibleTag)) 10869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal return new ParameterAnnotationsAttribute(cp, name, in); 10969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal else if (nameStr.equals(SignatureAttribute.tag)) 11069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal return new SignatureAttribute(cp, name, in); 11169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal else if (nameStr.equals(SourceFileAttribute.tag)) 11269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal return new SourceFileAttribute(cp, name, in); 11369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal else if (nameStr.equals(SyntheticAttribute.tag)) 11469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal return new SyntheticAttribute(cp, name, in); 11569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal else if (nameStr.equals(StackMap.tag)) 11669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal return new StackMap(cp, name, in); 11769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal else if (nameStr.equals(StackMapTable.tag)) 11869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal return new StackMapTable(cp, name, in); 11969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal } 12069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 12169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal return new AttributeInfo(cp, name, in); 12269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal } 12369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 12469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal /** 12569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * Returns an attribute name. 12669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal */ 12769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal public String getName() { 12869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal return constPool.getUtf8Info(name); 12969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal } 13069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 13169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal /** 13269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * Returns a constant pool table. 13369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal */ 13469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal public ConstPool getConstPool() { return constPool; } 13569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 13669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal /** 13769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * Returns the length of this <code>attribute_info</code> 13869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * structure. 13969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * The returned value is <code>attribute_length + 6</code>. 14069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal */ 14169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal public int length() { 14269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal return info.length + 6; 14369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal } 14469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 14569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal /** 14669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * Returns the <code>info</code> field 14769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * of this <code>attribute_info</code> structure. 14869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * 14969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * <p>This method is not available if the object is an instance 15069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * of <code>CodeAttribute</code>. 15169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal */ 15269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal public byte[] get() { return info; } 15369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 15469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal /** 15569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * Sets the <code>info</code> field 15669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * of this <code>attribute_info</code> structure. 15769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * 15869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * <p>This method is not available if the object is an instance 15969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * of <code>CodeAttribute</code>. 16069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal */ 16169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal public void set(byte[] newinfo) { info = newinfo; } 16269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 16369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal /** 16469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * Makes a copy. Class names are replaced according to the 16569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * given <code>Map</code> object. 16669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * 16769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * @param newCp the constant pool table used by the new copy. 16869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * @param classnames pairs of replaced and substituted 16969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * class names. 17069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal */ 17169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal public AttributeInfo copy(ConstPool newCp, Map classnames) { 17269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal int s = info.length; 17369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal byte[] srcInfo = info; 17469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal byte[] newInfo = new byte[s]; 17569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal for (int i = 0; i < s; ++i) 17669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal newInfo[i] = srcInfo[i]; 17769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 17869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal return new AttributeInfo(newCp, getName(), newInfo); 17969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal } 18069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 18169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal void write(DataOutputStream out) throws IOException { 18269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal out.writeShort(name); 18369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal out.writeInt(info.length); 18469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal if (info.length > 0) 18569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal out.write(info); 18669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal } 18769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 18869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal static int getLength(ArrayList list) { 18969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal int size = 0; 19069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal int n = list.size(); 19169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal for (int i = 0; i < n; ++i) { 19269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal AttributeInfo attr = (AttributeInfo)list.get(i); 19369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal size += attr.length(); 19469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal } 19569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 19669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal return size; 19769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal } 19869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 19969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal static AttributeInfo lookup(ArrayList list, String name) { 20069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal if (list == null) 20169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal return null; 20269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 20369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal ListIterator iterator = list.listIterator(); 20469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal while (iterator.hasNext()) { 20569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal AttributeInfo ai = (AttributeInfo)iterator.next(); 20669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal if (ai.getName().equals(name)) 20769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal return ai; 20869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal } 20969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 21069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal return null; // no such attribute 21169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal } 21269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 21369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal static synchronized void remove(ArrayList list, String name) { 21469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal if (list == null) 21569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal return; 21669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 21769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal ListIterator iterator = list.listIterator(); 21869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal while (iterator.hasNext()) { 21969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal AttributeInfo ai = (AttributeInfo)iterator.next(); 22069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal if (ai.getName().equals(name)) 22169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal iterator.remove(); 22269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal } 22369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal } 22469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 22569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal static void writeAll(ArrayList list, DataOutputStream out) 22669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal throws IOException 22769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal { 22869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal if (list == null) 22969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal return; 23069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 23169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal int n = list.size(); 23269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal for (int i = 0; i < n; ++i) { 23369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal AttributeInfo attr = (AttributeInfo)list.get(i); 23469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal attr.write(out); 23569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal } 23669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal } 23769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 23869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal static ArrayList copyAll(ArrayList list, ConstPool cp) { 23969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal if (list == null) 24069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal return null; 24169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 24269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal ArrayList newList = new ArrayList(); 24369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal int n = list.size(); 24469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal for (int i = 0; i < n; ++i) { 24569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal AttributeInfo attr = (AttributeInfo)list.get(i); 24669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal newList.add(attr.copy(cp, null)); 24769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal } 24869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 24969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal return newList; 25069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal } 25169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 25269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal /* The following two methods are used to implement 25369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * ClassFile.renameClass(). 25469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * Only CodeAttribute, LocalVariableAttribute, 25569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * AnnotationsAttribute, and SignatureAttribute 25669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * override these methods. 25769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal */ 25869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal void renameClass(String oldname, String newname) {} 25969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal void renameClass(Map classnames) {} 26069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 26169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal static void renameClass(List attributes, String oldname, String newname) { 26269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal Iterator iterator = attributes.iterator(); 26369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal while (iterator.hasNext()) { 26469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal AttributeInfo ai = (AttributeInfo)iterator.next(); 26569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal ai.renameClass(oldname, newname); 26669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal } 26769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal } 26869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 26969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal static void renameClass(List attributes, Map classnames) { 27069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal Iterator iterator = attributes.iterator(); 27169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal while (iterator.hasNext()) { 27269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal AttributeInfo ai = (AttributeInfo)iterator.next(); 27369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal ai.renameClass(classnames); 27469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal } 27569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal } 27669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 27769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal void getRefClasses(Map classnames) {} 27869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal 27969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal static void getRefClasses(List attributes, Map classnames) { 28069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal Iterator iterator = attributes.iterator(); 28169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal while (iterator.hasNext()) { 28269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal AttributeInfo ai = (AttributeInfo)iterator.next(); 28369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal ai.getRefClasses(classnames); 28469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal } 28569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal } 28669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal} 287