KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > proguard > classfile > editor > AttributeAdder


1 /*
2  * ProGuard -- shrinking, optimization, obfuscation, and preverification
3  * of Java bytecode.
4  *
5  * Copyright (c) 2002-2007 Eric Lafortune (eric@graphics.cornell.edu)
6  *
7  * This program is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by the Free
9  * Software Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15  * more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */

21 package proguard.classfile.editor;
22
23 import proguard.classfile.*;
24 import proguard.classfile.util.SimplifiedVisitor;
25 import proguard.classfile.attribute.visitor.AttributeVisitor;
26 import proguard.classfile.attribute.*;
27 import proguard.classfile.attribute.annotation.*;
28 import proguard.classfile.attribute.preverification.*;
29
30 /**
31  * This AttributeVisitor adds all attributes that it visits to the given
32  * target class, class member, or attribute.
33  *
34  * @author Eric Lafortune
35  */

36 public class AttributeAdder
37 implements AttributeVisitor
38 {
39     private ProgramClass targetClass;
40     private ProgramMember targetMember;
41     private Attribute targetAttribute;
42
43     private ConstantAdder constantAdder = new ConstantAdder();
44     private AttributesEditor attributesEditor = new AttributesEditor();
45
46
47     /**
48      * Creates a new AttributeAdder that will copy attributes into the given
49      * target class.
50      */

51     public AttributeAdder(ProgramClass targetClass)
52     {
53         this(targetClass, null, null);
54     }
55
56
57     /**
58      * Creates a new AttributeAdder that will copy attributes into the given
59      * target class member.
60      */

61     public AttributeAdder(ProgramClass targetClass,
62                           ProgramMember targetMember)
63     {
64         this(targetClass, targetMember, null);
65     }
66
67
68     /**
69      * Creates a new AttributeAdder that will copy attributes into the given
70      * target attribute.
71      */

72     public AttributeAdder(ProgramClass targetClass,
73                           ProgramMember targetMember,
74                           Attribute targetAttribute)
75     {
76         this.targetClass = targetClass;
77         this.targetMember = targetMember;
78         this.targetAttribute = targetAttribute;
79
80         constantAdder.setTargetClass(targetClass);
81     }
82
83
84     // Implementations for AttibuteVisitor.
85

86     public void visitUnknownAttribute(Clazz clazz, UnknownAttribute unknownAttribute)
87     {
88         //To change body of implemented methods use File | Settings | File Templates.
89
}
90
91
92     public void visitSourceFileAttribute(Clazz clazz, SourceFileAttribute sourceFileAttribute)
93     {
94         //To change body of implemented methods use File | Settings | File Templates.
95
}
96
97
98     public void visitSourceDirAttribute(Clazz clazz, SourceDirAttribute sourceDirAttribute)
99     {
100         //To change body of implemented methods use File | Settings | File Templates.
101
}
102
103
104     public void visitInnerClassesAttribute(Clazz clazz, InnerClassesAttribute innerClassesAttribute)
105     {
106         //To change body of implemented methods use File | Settings | File Templates.
107
}
108
109
110     public void visitEnclosingMethodAttribute(Clazz clazz, EnclosingMethodAttribute enclosingMethodAttribute)
111     {
112         //To change body of implemented methods use File | Settings | File Templates.
113
}
114
115
116     public void visitDeprecatedAttribute(Clazz clazz, DeprecatedAttribute deprecatedAttribute)
117     {
118         //To change body of implemented methods use File | Settings | File Templates.
119
}
120
121
122     public void visitDeprecatedAttribute(Clazz clazz, Field field, DeprecatedAttribute deprecatedAttribute)
123     {
124         //To change body of implemented methods use File | Settings | File Templates.
125
}
126
127
128     public void visitDeprecatedAttribute(Clazz clazz, Method method, DeprecatedAttribute deprecatedAttribute)
129     {
130         //To change body of implemented methods use File | Settings | File Templates.
131
}
132
133
134     public void visitSyntheticAttribute(Clazz clazz, SyntheticAttribute syntheticAttribute)
135     {
136         //To change body of implemented methods use File | Settings | File Templates.
137
}
138
139
140     public void visitSyntheticAttribute(Clazz clazz, Field field, SyntheticAttribute syntheticAttribute)
141     {
142         //To change body of implemented methods use File | Settings | File Templates.
143
}
144
145
146     public void visitSyntheticAttribute(Clazz clazz, Method method, SyntheticAttribute syntheticAttribute)
147     {
148         //To change body of implemented methods use File | Settings | File Templates.
149
}
150
151
152     public void visitSignatureAttribute(Clazz clazz, SignatureAttribute signatureAttribute)
153     {
154         //To change body of implemented methods use File | Settings | File Templates.
155
}
156
157
158     public void visitSignatureAttribute(Clazz clazz, Field field, SignatureAttribute signatureAttribute)
159     {
160         //To change body of implemented methods use File | Settings | File Templates.
161
}
162
163
164     public void visitSignatureAttribute(Clazz clazz, Method method, SignatureAttribute signatureAttribute)
165     {
166         //To change body of implemented methods use File | Settings | File Templates.
167
}
168
169
170     public void visitConstantValueAttribute(Clazz clazz, Field field, ConstantValueAttribute constantValueAttribute)
171     {
172         //To change body of implemented methods use File | Settings | File Templates.
173
}
174
175
176     public void visitExceptionsAttribute(Clazz clazz, Method method, ExceptionsAttribute exceptionsAttribute)
177     {
178         // Create a new exceptions attribute.
179
ExceptionsAttribute newExceptionsAttribute = new ExceptionsAttribute();
180
181         // Make sure the name is set in the constant pool.
182
clazz.constantPoolEntryAccept(exceptionsAttribute.u2attributeNameIndex,
183                                       constantAdder);
184
185         newExceptionsAttribute.u2attributeNameIndex = constantAdder.getConstantIndex();
186
187         // Start with an empty exception index table.
188
newExceptionsAttribute.u2exceptionIndexTableLength = 0;
189         newExceptionsAttribute.u2exceptionIndexTable = new int[0];
190
191         // Add the exceptions.
192
exceptionsAttribute.exceptionEntriesAccept((ProgramClass)clazz,
193                                                    new ExceptionAdder(targetClass,
194                                                                       newExceptionsAttribute));
195
196         // Add the completed exceptions attribute.
197
attributesEditor.addAttribute(targetClass,
198                                       (ProgramMethod)targetMember,
199                                       newExceptionsAttribute);
200     }
201
202
203     public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute)
204     {
205         //To change body of implemented methods use File | Settings | File Templates.
206
}
207
208
209     public void visitStackMapAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, StackMapAttribute stackMapAttribute)
210     {
211         //To change body of implemented methods use File | Settings | File Templates.
212
}
213
214
215     public void visitStackMapTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, StackMapTableAttribute stackMapTableAttribute)
216     {
217         //To change body of implemented methods use File | Settings | File Templates.
218
}
219
220
221     public void visitLineNumberTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LineNumberTableAttribute lineNumberTableAttribute)
222     {
223         //To change body of implemented methods use File | Settings | File Templates.
224
}
225
226
227     public void visitLocalVariableTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTableAttribute localVariableTableAttribute)
228     {
229         //To change body of implemented methods use File | Settings | File Templates.
230
}
231
232
233     public void visitLocalVariableTypeTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTypeTableAttribute localVariableTypeTableAttribute)
234     {
235         //To change body of implemented methods use File | Settings | File Templates.
236
}
237
238
239     public void visitRuntimeVisibleAnnotationsAttribute(Clazz clazz, RuntimeVisibleAnnotationsAttribute runtimeVisibleAnnotationsAttribute)
240     {
241         //To change body of implemented methods use File | Settings | File Templates.
242
}
243
244
245     public void visitRuntimeVisibleAnnotationsAttribute(Clazz clazz, Field field, RuntimeVisibleAnnotationsAttribute runtimeVisibleAnnotationsAttribute)
246     {
247         //To change body of implemented methods use File | Settings | File Templates.
248
}
249
250
251     public void visitRuntimeVisibleAnnotationsAttribute(Clazz clazz, Method method, RuntimeVisibleAnnotationsAttribute runtimeVisibleAnnotationsAttribute)
252     {
253         //To change body of implemented methods use File | Settings | File Templates.
254
}
255
256
257     public void visitRuntimeInvisibleAnnotationsAttribute(Clazz clazz, RuntimeInvisibleAnnotationsAttribute runtimeInvisibleAnnotationsAttribute)
258     {
259         //To change body of implemented methods use File | Settings | File Templates.
260
}
261
262
263     public void visitRuntimeInvisibleAnnotationsAttribute(Clazz clazz, Field field, RuntimeInvisibleAnnotationsAttribute runtimeInvisibleAnnotationsAttribute)
264     {
265         //To change body of implemented methods use File | Settings | File Templates.
266
}
267
268
269     public void visitRuntimeInvisibleAnnotationsAttribute(Clazz clazz, Method method, RuntimeInvisibleAnnotationsAttribute runtimeInvisibleAnnotationsAttribute)
270     {
271         //To change body of implemented methods use File | Settings | File Templates.
272
}
273
274
275     public void visitRuntimeVisibleParameterAnnotationsAttribute(Clazz clazz, Method method, RuntimeVisibleParameterAnnotationsAttribute runtimeVisibleParameterAnnotationsAttribute)
276     {
277         //To change body of implemented methods use File | Settings | File Templates.
278
}
279
280
281     public void visitRuntimeInvisibleParameterAnnotationsAttribute(Clazz clazz, Method method, RuntimeInvisibleParameterAnnotationsAttribute runtimeInvisibleParameterAnnotationsAttribute)
282     {
283         //To change body of implemented methods use File | Settings | File Templates.
284
}
285
286
287     public void visitAnnotationDefaultAttribute(Clazz clazz, Method method, AnnotationDefaultAttribute annotationDefaultAttribute)
288     {
289         //To change body of implemented methods use File | Settings | File Templates.
290
}
291 }
292
Popular Tags