1b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato/*
2b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * ProGuard -- shrinking, optimization, obfuscation, and preverification
3b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato *             of Java bytecode.
4b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato *
5b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang * Copyright (c) 2002-2013 Eric Lafortune (eric@graphics.cornell.edu)
6b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato *
7b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * This program is free software; you can redistribute it and/or modify it
8b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * under the terms of the GNU General Public License as published by the Free
9b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * Software Foundation; either version 2 of the License, or (at your option)
10b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * any later version.
11b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato *
12b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * This program is distributed in the hope that it will be useful, but WITHOUT
13b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * more details.
16b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato *
17b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * You should have received a copy of the GNU General Public License along
18b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * with this program; if not, write to the Free Software Foundation, Inc.,
19b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato */
21b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratopackage proguard.classfile.editor;
22b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
23b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoimport proguard.classfile.*;
24b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoimport proguard.classfile.attribute.*;
25b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoimport proguard.classfile.attribute.annotation.*;
26b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoimport proguard.classfile.attribute.preverification.*;
27b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoimport proguard.classfile.attribute.visitor.AttributeVisitor;
28b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoimport proguard.classfile.util.SimplifiedVisitor;
29b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
30b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato/**
31b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * This AttributeVisitor adds all attributes that it visits to the given
32b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * target class, class member, or attribute.
33b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato *
34b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * @author Eric Lafortune
35b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato */
36b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratopublic class AttributeAdder
37b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoextends      SimplifiedVisitor
38b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoimplements   AttributeVisitor
39b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato{
40b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    private static final byte[]          EMPTY_BYTES       = new byte[0];
41b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    private static final int[]           EMPTY_INTS        = new int[0];
42b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    private static final Attribute[]     EMPTY_ATTRIBUTES  = new Attribute[0];
43b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    private static final ExceptionInfo[] EMPTY_EXCEPTIONS  = new ExceptionInfo[0];
44b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
45b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
46b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    private final ProgramClass  targetClass;
47b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    private final ProgramMember targetMember;
48b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    private final CodeAttribute targetCodeAttribute;
49b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    private final boolean       replaceAttributes;
50b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
51b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    private final ConstantAdder    constantAdder;
52b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    private final AttributesEditor attributesEditor;
53b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
54b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
55b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    /**
56b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato     * Creates a new AttributeAdder that will copy attributes into the given
57b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato     * target class.
58b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato     */
59b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    public AttributeAdder(ProgramClass targetClass,
60b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                          boolean      replaceAttributes)
61b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    {
62b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        this(targetClass, null, null, replaceAttributes);
63b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    }
64b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
65b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
66b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    /**
67b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato     * Creates a new AttributeAdder that will copy attributes into the given
68b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato     * target class member.
69b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato     */
70b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    public AttributeAdder(ProgramClass  targetClass,
71b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                          ProgramMember targetMember,
72b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                          boolean       replaceAttributes)
73b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    {
74b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        this(targetClass, targetMember, null, replaceAttributes);
75b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    }
76b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
77b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
78b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    /**
79b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato     * Creates a new AttributeAdder that will copy attributes into the given
80b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato     * target attribute.
81b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato     */
82b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    public AttributeAdder(ProgramClass  targetClass,
83b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                          ProgramMember targetMember,
84b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                          CodeAttribute targetCodeAttribute,
85b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                          boolean       replaceAttributes)
86b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    {
87b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        this.targetClass         = targetClass;
88b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        this.targetMember        = targetMember;
89b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        this.targetCodeAttribute = targetCodeAttribute;
90b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        this.replaceAttributes   = replaceAttributes;
91b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
92b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        constantAdder    = new ConstantAdder(targetClass);
93b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        attributesEditor = new AttributesEditor(targetClass,
94b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                                targetMember,
95b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                                targetCodeAttribute,
96b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                                replaceAttributes);
97b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    }
98b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
99b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
100b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    // Implementations for AttributeVisitor.
101b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
102b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    public void visitUnknownAttribute(Clazz clazz, UnknownAttribute unknownAttribute)
103b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    {
104b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Create a copy of the attribute.
105b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        UnknownAttribute newUnknownAttribute =
106b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato            new UnknownAttribute(constantAdder.addConstant(clazz, unknownAttribute.u2attributeNameIndex),
107b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                 unknownAttribute.u4attributeLength,
108b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                 unknownAttribute.info);
109b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
110b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Add it to the target class.
111b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        attributesEditor.addAttribute(newUnknownAttribute);
112b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    }
113b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
114b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
115b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    public void visitSourceFileAttribute(Clazz clazz, SourceFileAttribute sourceFileAttribute)
116b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    {
117b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Create a copy of the attribute.
118b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        SourceFileAttribute newSourceFileAttribute =
119b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato            new SourceFileAttribute(constantAdder.addConstant(clazz, sourceFileAttribute.u2attributeNameIndex),
120b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                    constantAdder.addConstant(clazz, sourceFileAttribute.u2sourceFileIndex));
121b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
122b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Add it to the target class.
123b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        attributesEditor.addAttribute(newSourceFileAttribute);
124b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    }
125b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
126b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
127b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    public void visitSourceDirAttribute(Clazz clazz, SourceDirAttribute sourceDirAttribute)
128b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    {
129b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Create a copy of the attribute.
130b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        SourceDirAttribute newSourceDirAttribute =
131b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato            new SourceDirAttribute(constantAdder.addConstant(clazz, sourceDirAttribute.u2attributeNameIndex),
132b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                   constantAdder.addConstant(clazz, sourceDirAttribute.u2sourceDirIndex));
133b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
134b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Add it to the target class.
135b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        attributesEditor.addAttribute(newSourceDirAttribute);
136b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    }
137b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
138b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
139b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    public void visitInnerClassesAttribute(Clazz clazz, InnerClassesAttribute innerClassesAttribute)
140b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    {
141b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang        // Create a copy of the attribute.
142b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang        InnerClassesAttribute newInnerClassesAttribute =
143b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang            new InnerClassesAttribute(constantAdder.addConstant(clazz, innerClassesAttribute.u2attributeNameIndex),
144b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang                                      0,
145b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang                                      null);
146b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang
147b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang        // Add it to the target class.
148b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang        attributesEditor.addAttribute(newInnerClassesAttribute);
149b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    }
150b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
151b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
152b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    public void visitEnclosingMethodAttribute(Clazz clazz, EnclosingMethodAttribute enclosingMethodAttribute)
153b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    {
154b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Create a copy of the attribute.
155b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        EnclosingMethodAttribute newEnclosingMethodAttribute =
156b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato            new EnclosingMethodAttribute(constantAdder.addConstant(clazz, enclosingMethodAttribute.u2attributeNameIndex),
157b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                         constantAdder.addConstant(clazz, enclosingMethodAttribute.u2classIndex),
158b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                         enclosingMethodAttribute.u2nameAndTypeIndex == 0 ? 0 :
159b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                         constantAdder.addConstant(clazz, enclosingMethodAttribute.u2nameAndTypeIndex));
160b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
161b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        newEnclosingMethodAttribute.referencedClass  = enclosingMethodAttribute.referencedClass;
162b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        newEnclosingMethodAttribute.referencedMethod = enclosingMethodAttribute.referencedMethod;
163b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
164b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Add it to the target class.
165b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        attributesEditor.addAttribute(newEnclosingMethodAttribute);
166b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    }
167b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
168b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
169b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    public void visitDeprecatedAttribute(Clazz clazz, DeprecatedAttribute deprecatedAttribute)
170b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    {
171b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Create a copy of the attribute.
172b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        DeprecatedAttribute newDeprecatedAttribute =
173b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato            new DeprecatedAttribute(constantAdder.addConstant(clazz, deprecatedAttribute.u2attributeNameIndex));
174b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
175b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Add it to the target.
176b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        attributesEditor.addAttribute(newDeprecatedAttribute);
177b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    }
178b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
179b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
180b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    public void visitSyntheticAttribute(Clazz clazz, SyntheticAttribute syntheticAttribute)
181b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    {
182b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Create a copy of the attribute.
183b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        SyntheticAttribute newSyntheticAttribute =
184b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato            new SyntheticAttribute(constantAdder.addConstant(clazz, syntheticAttribute.u2attributeNameIndex));
185b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
186b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Add it to the target.
187b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        attributesEditor.addAttribute(newSyntheticAttribute);
188b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    }
189b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
190b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
191b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    public void visitSignatureAttribute(Clazz clazz, SignatureAttribute signatureAttribute)
192b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    {
193b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Create a copy of the attribute.
194b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        SignatureAttribute newSignatureAttribute =
195b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato            new SignatureAttribute(constantAdder.addConstant(clazz, signatureAttribute.u2attributeNameIndex),
196b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                   constantAdder.addConstant(clazz, signatureAttribute.u2signatureIndex));
197b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
198b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        newSignatureAttribute.referencedClasses = signatureAttribute.referencedClasses;
199b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
200b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Add it to the target.
201b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        attributesEditor.addAttribute(newSignatureAttribute);
202b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    }
203b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
204b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
205b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    public void visitConstantValueAttribute(Clazz clazz, Field field, ConstantValueAttribute constantValueAttribute)
206b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    {
207b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Create a copy of the attribute.
208b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        ConstantValueAttribute newConstantValueAttribute =
209b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato            new ConstantValueAttribute(constantAdder.addConstant(clazz, constantValueAttribute.u2attributeNameIndex),
210b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                       constantAdder.addConstant(clazz, constantValueAttribute.u2constantValueIndex));
211b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
212b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Add it to the target field.
213b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        attributesEditor.addAttribute(newConstantValueAttribute);
214b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    }
215b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
216b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
217b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    public void visitExceptionsAttribute(Clazz clazz, Method method, ExceptionsAttribute exceptionsAttribute)
218b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    {
219b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Create a new exceptions attribute.
220b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        ExceptionsAttribute newExceptionsAttribute =
221b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato            new ExceptionsAttribute(constantAdder.addConstant(clazz, exceptionsAttribute.u2attributeNameIndex),
222b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                    0,
223b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                    exceptionsAttribute.u2exceptionIndexTableLength > 0 ?
224b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                        new int[exceptionsAttribute.u2exceptionIndexTableLength] :
225b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                        EMPTY_INTS);
226b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
227b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Add the exceptions.
228b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        exceptionsAttribute.exceptionEntriesAccept((ProgramClass)clazz,
229b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                                   new ExceptionAdder(targetClass,
230b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                                                      newExceptionsAttribute));
231b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
232b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Add it to the target method.
233b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        attributesEditor.addAttribute(newExceptionsAttribute);
234b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    }
235b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
236b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
237b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute)
238b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    {
239b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Create a new code attribute.
240b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        CodeAttribute newCodeAttribute =
241b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato            new CodeAttribute(constantAdder.addConstant(clazz, codeAttribute.u2attributeNameIndex),
242b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                              codeAttribute.u2maxStack,
243b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                              codeAttribute.u2maxLocals,
244b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                              0,
245b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                              EMPTY_BYTES,
246b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                              0,
247b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                              codeAttribute.u2exceptionTableLength > 0 ?
248b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                  new ExceptionInfo[codeAttribute.u2exceptionTableLength] :
249b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                  EMPTY_EXCEPTIONS,
250b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                              0,
251b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                              codeAttribute.u2attributesCount > 0 ?
252b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                  new Attribute[codeAttribute.u2attributesCount] :
253b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                  EMPTY_ATTRIBUTES);
254b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
255b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        CodeAttributeComposer codeAttributeComposer = new CodeAttributeComposer();
256b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
257b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang        codeAttributeComposer.beginCodeFragment(codeAttribute.u4codeLength + 32);
258b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
259b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Add the instructions.
260b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        codeAttribute.instructionsAccept(clazz,
261b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                         method,
262b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                         new InstructionAdder(targetClass,
263b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                                              codeAttributeComposer));
264b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
265b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Append a label just after the code.
266b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        codeAttributeComposer.appendLabel(codeAttribute.u4codeLength);
267b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
268b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Add the exceptions.
269b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        codeAttribute.exceptionsAccept(clazz,
270b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                       method,
271b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                       new ExceptionInfoAdder(targetClass,
272b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                                              codeAttributeComposer));
273b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
274b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        codeAttributeComposer.endCodeFragment();
275b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
276b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Add the attributes.
277b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        codeAttribute.attributesAccept(clazz,
278b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                       method,
279b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                       new AttributeAdder(targetClass,
280b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                                          targetMember,
281b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                                          newCodeAttribute,
282b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                                          replaceAttributes));
283b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
284b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Apply these changes to the new code attribute.
285b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        codeAttributeComposer.visitCodeAttribute(targetClass,
286b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                                 (Method)targetMember,
287b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                                 newCodeAttribute);
288b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
289b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Add the completed code attribute to the target method.
290b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        attributesEditor.addAttribute(newCodeAttribute);
291b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    }
292b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
293b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
294b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    public void visitStackMapAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, StackMapAttribute stackMapAttribute)
295b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    {
296b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // TODO: Implement method.
297b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    }
298b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
299b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
300b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    public void visitStackMapTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, StackMapTableAttribute stackMapTableAttribute)
301b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    {
302b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // TODO: Implement method.
303b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    }
304b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
305b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
306b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    public void visitLineNumberTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LineNumberTableAttribute lineNumberTableAttribute)
307b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    {
308b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Create a new line number table attribute.
309b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        LineNumberTableAttribute newLineNumberTableAttribute =
310b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato            new LineNumberTableAttribute(constantAdder.addConstant(clazz, lineNumberTableAttribute.u2attributeNameIndex),
311b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                         0,
312b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                         new LineNumberInfo[lineNumberTableAttribute.u2lineNumberTableLength]);
313b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
314b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Add the line numbers.
315b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        lineNumberTableAttribute.lineNumbersAccept(clazz,
316b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                                   method,
317b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                                   codeAttribute,
318b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                                   new LineNumberInfoAdder(newLineNumberTableAttribute));
319b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
320b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Add it to the target.
321b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        attributesEditor.addAttribute(newLineNumberTableAttribute);
322b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    }
323b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
324b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
325b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    public void visitLocalVariableTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTableAttribute localVariableTableAttribute)
326b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    {
327b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Create a new local variable table attribute.
328b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        LocalVariableTableAttribute newLocalVariableTableAttribute =
329b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato            new LocalVariableTableAttribute(constantAdder.addConstant(clazz, localVariableTableAttribute.u2attributeNameIndex),
330b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                            0,
331b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                            new LocalVariableInfo[localVariableTableAttribute.u2localVariableTableLength]);
332b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
333b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Add the local variables.
334b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        localVariableTableAttribute.localVariablesAccept(clazz,
335b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                                         method,
336b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                                         codeAttribute,
337b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                                         new LocalVariableInfoAdder(targetClass, newLocalVariableTableAttribute));
338b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
339b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Add it to the target.
340b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        attributesEditor.addAttribute(newLocalVariableTableAttribute);
341b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    }
342b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
343b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
344b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    public void visitLocalVariableTypeTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTypeTableAttribute localVariableTypeTableAttribute)
345b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    {
346b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Create a new local variable type table attribute.
347b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        LocalVariableTypeTableAttribute newLocalVariableTypeTableAttribute =
348b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato            new LocalVariableTypeTableAttribute(constantAdder.addConstant(clazz, localVariableTypeTableAttribute.u2attributeNameIndex),
349b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                            0,
350b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                            new LocalVariableTypeInfo[localVariableTypeTableAttribute.u2localVariableTypeTableLength]);
351b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
352b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Add the local variable types.
353b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        localVariableTypeTableAttribute.localVariablesAccept(clazz,
354b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                                             method,
355b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                                             codeAttribute,
356b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                                             new LocalVariableTypeInfoAdder(targetClass, newLocalVariableTypeTableAttribute));
357b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
358b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Add it to the target.
359b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        attributesEditor.addAttribute(newLocalVariableTypeTableAttribute);
360b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    }
361b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
362b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
363b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    public void visitRuntimeVisibleAnnotationsAttribute(Clazz clazz, RuntimeVisibleAnnotationsAttribute runtimeVisibleAnnotationsAttribute)
364b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    {
365b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Create a new annotations attribute.
366b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        RuntimeVisibleAnnotationsAttribute newAnnotationsAttribute =
367b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato            new RuntimeVisibleAnnotationsAttribute(constantAdder.addConstant(clazz, runtimeVisibleAnnotationsAttribute.u2attributeNameIndex),
368b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                                   0,
369b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                                   new Annotation[runtimeVisibleAnnotationsAttribute.u2annotationsCount]);
370b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
371b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Add the annotations.
372b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        runtimeVisibleAnnotationsAttribute.annotationsAccept(clazz,
373b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                                             new AnnotationAdder(targetClass,
374b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                                                                 newAnnotationsAttribute));
375b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
376b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Add it to the target.
377b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        attributesEditor.addAttribute(newAnnotationsAttribute);
378b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    }
379b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
380b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
381b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    public void visitRuntimeInvisibleAnnotationsAttribute(Clazz clazz, RuntimeInvisibleAnnotationsAttribute runtimeInvisibleAnnotationsAttribute)
382b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    {
383b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Create a new annotations attribute.
384b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        RuntimeInvisibleAnnotationsAttribute newAnnotationsAttribute =
385b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato            new RuntimeInvisibleAnnotationsAttribute(constantAdder.addConstant(clazz, runtimeInvisibleAnnotationsAttribute.u2attributeNameIndex),
386b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                                     0,
387b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                                     new Annotation[runtimeInvisibleAnnotationsAttribute.u2annotationsCount]);
388b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
389b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Add the annotations.
390b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        runtimeInvisibleAnnotationsAttribute.annotationsAccept(clazz,
391b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                                               new AnnotationAdder(targetClass,
392b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                                                                   newAnnotationsAttribute));
393b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
394b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Add it to the target.
395b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        attributesEditor.addAttribute(newAnnotationsAttribute);
396b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    }
397b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
398b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
399b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    public void visitRuntimeVisibleParameterAnnotationsAttribute(Clazz clazz, Method method, RuntimeVisibleParameterAnnotationsAttribute runtimeVisibleParameterAnnotationsAttribute)
400b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    {
401b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Create a new annotations attribute.
402b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        RuntimeVisibleParameterAnnotationsAttribute newParameterAnnotationsAttribute =
403b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato            new RuntimeVisibleParameterAnnotationsAttribute(constantAdder.addConstant(clazz, runtimeVisibleParameterAnnotationsAttribute.u2attributeNameIndex),
404b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                                            0,
405b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                                            new int[runtimeVisibleParameterAnnotationsAttribute.u2parametersCount],
406b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                                            new Annotation[runtimeVisibleParameterAnnotationsAttribute.u2parametersCount][]);
407b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
408b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Add the annotations.
409b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        runtimeVisibleParameterAnnotationsAttribute.annotationsAccept(clazz,
410b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                                                      method,
411b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                                                      new AnnotationAdder(targetClass,
412b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                                                                          newParameterAnnotationsAttribute));
413b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
414b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Add it to the target.
415b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        attributesEditor.addAttribute(newParameterAnnotationsAttribute);
416b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    }
417b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
418b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
419b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    public void visitRuntimeInvisibleParameterAnnotationsAttribute(Clazz clazz, Method method, RuntimeInvisibleParameterAnnotationsAttribute runtimeInvisibleParameterAnnotationsAttribute)
420b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    {
421b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Create a new annotations attribute.
422b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        RuntimeInvisibleParameterAnnotationsAttribute newParameterAnnotationsAttribute =
423b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato            new RuntimeInvisibleParameterAnnotationsAttribute(constantAdder.addConstant(clazz, runtimeInvisibleParameterAnnotationsAttribute.u2attributeNameIndex),
424b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                                              0,
425b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                                              new int[runtimeInvisibleParameterAnnotationsAttribute.u2parametersCount],
426b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                                              new Annotation[runtimeInvisibleParameterAnnotationsAttribute.u2parametersCount][]);
427b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
428b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Add the annotations.
429b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        runtimeInvisibleParameterAnnotationsAttribute.annotationsAccept(clazz,
430b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                                                        method,
431b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                                                        new AnnotationAdder(targetClass,
432b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                                                                            newParameterAnnotationsAttribute));
433b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
434b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Add it to the target.
435b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        attributesEditor.addAttribute(newParameterAnnotationsAttribute);
436b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    }
437b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
438b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
439b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    public void visitAnnotationDefaultAttribute(Clazz clazz, Method method, AnnotationDefaultAttribute annotationDefaultAttribute)
440b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    {
441b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Create a new annotation default attribute.
442b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        AnnotationDefaultAttribute newAnnotationDefaultAttribute =
443b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato            new AnnotationDefaultAttribute(constantAdder.addConstant(clazz, annotationDefaultAttribute.u2attributeNameIndex),
444b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                           null);
445b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
446b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Add the annotations.
447b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        annotationDefaultAttribute.defaultValueAccept(clazz,
448b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                                      new ElementValueAdder(targetClass,
449b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                                                            newAnnotationDefaultAttribute,
450b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato                                                                            false));
451b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato
452b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        // Add it to the target.
453b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato        attributesEditor.addAttribute(newAnnotationDefaultAttribute);
454b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato    }
455b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato}
456