1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
|
/**
* Copyright 2012-2014 Julien Eluard and contributors
* This project includes software developed by Julien Eluard: https://github.com/jeluard/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.osjava.jardiff;
import org.objectweb.asm.Opcodes;
/**
* An abstract class representing information about a class, method or field.
*
* @author <a href="mailto:antony@cyberiantiger.org">Antony Riley</a>
*/
public abstract class AbstractInfo
{
/**
* The string used to represent a class, method or field with public
* access.
*/
public final String ACCESS_PUBLIC = "public";
/**
* The string used to represent a class, method or field with protected
* access.
*/
public final String ACCESS_PROTECTED = "protected";
/**
* The string used to represent a class, method or field with package
* private access.
* Package private access is the default access level used by java when
* you do not specify one of public, protected or private.
*/
public final String ACCESS_PACKAGE = "package";
/**
* The string used to represent a class, method or field with private
* access.
*/
public final String ACCESS_PRIVATE = "private";
/**
* The access flags for this class, method or field.
*/
private final int access;
/**
* The internal name of this class, method or field.
*/
private final String name;
/**
* Construct a new AbstractInfo with the specified access and name.
*
* @param access The access flags for this class, method or field.
* @param name The internal name of this class, method or field.
*/
public AbstractInfo(int access, String name) {
this.access = access;
this.name = name;
}
/**
* Get the descriptor
*
* @return The descriptor.
*/
public abstract String getDesc();
/**
* Get the signature
*
* @return The signature.
*/
public abstract String getSignature();
/**
* Get the access flags for this class, method or field.
*
* @return the access flags.
*/
public final int getAccess() {
return access;
}
/**
* Get the internal name of this class, method or field.
*
* @return the name
*/
public final String getName() {
return name;
}
/**
* Test if this class, method or field is public.
*
* @return true if it is public.
*/
public final boolean isPublic() {
return (access & Opcodes.ACC_PUBLIC) != 0;
}
/**
* Test if this class, method or field is protected.
*
* @return true if it is protected.
*/
public final boolean isProtected() {
return (access & Opcodes.ACC_PROTECTED) != 0;
}
/**
* Test if this class, method or field is package private.
*
* @return true if it is package private.
*/
public final boolean isPackagePrivate() {
return (access & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED |
Opcodes.ACC_PRIVATE)) == 0;
}
/**
* Test if this class, method or field is private.
*
* @return true if it is private.
*/
public final boolean isPrivate() {
return (access & Opcodes.ACC_PRIVATE) != 0;
}
/**
* Test if this class, method or field is abstract.
*
* @return true if it is abstract.
*/
public final boolean isAbstract() {
return (access & Opcodes.ACC_ABSTRACT) != 0;
}
/**
* Test if this class, method or field is annotation
*
* @return true if it is annotation.
*/
public final boolean isAnnotation() {
return (access & Opcodes.ACC_ANNOTATION) != 0;
}
/**
* Test if this class, method or field is a bridge
*
* @return true if it is a bridge.
*/
public final boolean isBridge() {
return (access & Opcodes.ACC_BRIDGE) != 0;
}
/**
* Test if this class, method or field is deprecated.
*
* @return true if it is deprecated.
*/
public final boolean isDeprecated() {
return (access & Opcodes.ACC_DEPRECATED) != 0;
}
/**
* Test if this class, method or field is an enum.
*
* @return true if it is an enum.
*/
public final boolean isEnum() {
return (access & Opcodes.ACC_ENUM) != 0;
}
/**
* Test if this class, method or field is final.
*
* @return true if it is final.
*/
public final boolean isFinal() {
return (access & Opcodes.ACC_FINAL) != 0;
}
/**
* Test if this class, method or field is an interface.
*
* @return true if it is an interface.
*/
public final boolean isInterface() {
return (access & Opcodes.ACC_INTERFACE) != 0;
}
/**
* Test if this class, method or field is native.
*
* @return true if it is native.
*/
public final boolean isNative() {
return (access & Opcodes.ACC_NATIVE) != 0;
}
/**
* Test if this class, method or field is static.
*
* @return true if it is static.
*/
public final boolean isStatic() {
return (access & Opcodes.ACC_STATIC) != 0;
}
/**
* Test if this class, method or field is string.
*
* @return true if it is strict.
*/
public final boolean isStrict() {
return (access & Opcodes.ACC_STRICT) != 0;
}
/**
* Test if this class, method or field is super.
*
* @return true if it is super.
*/
public final boolean isSuper() {
return (access & Opcodes.ACC_SUPER) != 0;
}
/**
* Test if this class, method or field is synchronized.
*
* @return true if it is synchronized
*/
public final boolean isSynchronized() {
return (access & Opcodes.ACC_SYNCHRONIZED) != 0;
}
/**
* Test if this class, method or field is synthetic.
*
* @return true if it is synchronized.
*/
public final boolean isSynthetic() {
return (access & Opcodes.ACC_SYNTHETIC) != 0;
}
/**
* Test if this class or field is transient.
* If this flag is set on a method it means something different.
*
* @return true if it is transient.
*/
public final boolean isTransient() {
return !(this instanceof MethodInfo) &&
((access & Opcodes.ACC_TRANSIENT) != 0);
}
/**
* Test if this method is varargs.
* If this flag is set on a class or field it means something different.
* Well, it probably shouldn't be set on a class as it would make
* no sense, it only really makes sense on fields and methods.
*
* @return true if it is varargs.
*/
public final boolean isVarargs() {
return (this instanceof MethodInfo) &&
((access & Opcodes.ACC_VARARGS) != 0);
}
/**
* Test if this class, method or field is volatile.
*
* @return true if it is volatile.
*/
public final boolean isVolatile() {
return (access & Opcodes.ACC_VOLATILE) != 0;
}
/**
* Retrieve the access level for this class, method or field.
*
* @return the access level
*/
public final String getAccessType() {
if (isPublic())
return ACCESS_PUBLIC;
if (isProtected())
return ACCESS_PROTECTED;
if (isPrivate())
return ACCESS_PRIVATE;
return ACCESS_PACKAGE;
}
}
|