forked from Konloch/bytecode-viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMod.java
More file actions
270 lines (222 loc) · 12 KB
/
Copy pathMod.java
File metadata and controls
270 lines (222 loc) · 12 KB
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
/*
* Janino - An embedded Java[TM] compiler
*
* Copyright (c) 2001-2010, Arno Unkrig
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package org.codehaus.janino;
/**
* This class defines constants and convenience methods for the handling of modifiers as defined by the JVM.
* <p>
* Notice: This class should be named <code>IClass.IModifier</code>, but changing the name would break existing client
* code. Thus it won't be renamed until there's a really good reason to do it (maybe with a major design change).
*/
public final
class Mod {
private Mod() {} // Don't instantiate me!
/** An alias for '0' -- <i>no</i> modifiers. */
public static final short NONE = 0x0000;
/**
* The flag indicating 'public accessibility' of the modified element. Methods of interfaces are always {@link
* #PUBLIC}.
*
* @see #PPP
* @see #isPublicAccess(short)
*/
public static final short PUBLIC = 0x0001;
/** @return Whether the given modifier symbolizes {@link #PUBLIC} accessibility */
public static boolean isPublicAccess(short sh) { return (sh & Mod.PPP) == Mod.PUBLIC; }
/**
* The flag indicating 'private accessibility' of the modified element.
*
* @see #PPP
* @see #isPrivateAccess(short)
*/
public static final short PRIVATE = 0x0002;
/** @return Whether the given modifier symbolizes {@link #PRIVATE} accessibility */
public static boolean isPrivateAccess(short sh) { return (sh & Mod.PPP) == Mod.PRIVATE; }
/**
* The flag indicating 'protected accessibility' of the modified element.
*
* @see #PPP
* @see #isProtectedAccess(short)
*/
public static final short PROTECTED = 0x0004;
/** @return Whether the given modifier symbolizes {@link #PROTECTED} accessibility */
public static boolean isProtectedAccess(short sh) { return (sh & Mod.PPP) == Mod.PROTECTED; }
/**
* The flag indicating 'default accessibility' a.k.a. 'package accessibility' of the modified element.
*
* @see #PPP
* @see #isPackageAccess(short)
*/
public static final short PACKAGE = 0x0000;
/** @return Whether the given modifier symbolizes {@link #PACKAGE} (a.k.a. 'default') accessibility */
public static boolean isPackageAccess(short sh) { return (sh & Mod.PPP) == Mod.PACKAGE; }
/** The mask to select the accessibility flags from modifiers. */
public static final short PPP = 0x0007;
/** @return The given {@code modifiers}, but with the accessibility part changed to {@code newAccess} */
public static short
changeAccess(short modifiers, short newAccess) { return (short) ((modifiers & ~Mod.PPP) | newAccess); }
/**
* This flag is set on class or interface initialization methods, STATIC class fields, all interface fields, STATIC
* methods, and STATIC nested classes.
*/
public static final short STATIC = 0x0008;
/** @return Whether the given modifier includes {@link #STATIC} */
public static boolean isStatic(short sh) { return (sh & Mod.STATIC) != 0; }
/**
* This flag is set on FINAL classes, FINAL fields and FINAL methods, and is mutually exclusive with {@link
* #VOLATILE} and {@link #ABSTRACT}.
*/
public static final short FINAL = 0x0010;
/** @return Whether the given modifier includes {@link #INTERFACE} */
public static boolean isFinal(short sh) { return (sh & Mod.FINAL) != 0; }
/**
* This flag is always set on classes, and never set on any other element. Notice that it has the same value as
* {@link #SYNCHRONIZED}, which is OK because {@link #SYNCHRONIZED} is for methods and {@link #SUPER} for classes.
*/
public static final short SUPER = 0x0020;
/** @return Whether the given modifier includes {@link #SUPER} */
public static boolean isSuper(short sh) { return (sh & Mod.SUPER) != 0; }
/**
* This flag is set on SYNCHRONIZED methods. Notice that it has the same value as {@link #SUPER}, which is OK
* because {@link #SYNCHRONIZED} is for methods and {@link #SUPER} for classes.
*/
public static final short SYNCHRONIZED = 0x0020;
/** @return Whether the given modifier includes {@link #SYNCHRONIZED} */
public static boolean isSynchronized(short sh) { return (sh & Mod.SYNCHRONIZED) != 0; }
/**
* This flag is set on VOLATILE fields and is mutually exclusive with {@link #FINAL}. Notice that it has the same
* value as {@link #BRIDGE}, which is OK because {@link #BRIDGE} is for methods and {@link #VOLATILE} for fields.
*/
public static final short VOLATILE = 0x0040;
/** @return Whether the given modifier includes {@link #VOLATILE} */
public static boolean isVolatile(short sh) { return (sh & Mod.VOLATILE) != 0; }
/**
* This flag is set on 'bridge methods' generated by the compiler. Notice that it has the same value as {@link
* #VOLATILE}, which is OK because {@link #BRIDGE} is for methods and {@link #VOLATILE} for fields.
*/
public static final short BRIDGE = 0x0040;
/** @return Whether the given modifier includes {@link #BRIDGE} */
public static boolean isBridge(short sh) { return (sh & Mod.BRIDGE) != 0; }
/**
* This flag is set on TRANSIENT fields. Notice that it has the same value as {@link #VARARGS}, which is OK because
* {@link #VARARGS} is for methods and {@link #TRANSIENT} for fields.
*/
public static final short TRANSIENT = 0x0080;
/** @return Whether the given modifier includes {@link #TRANSIENT} */
public static boolean isTransient(short sh) { return (sh & Mod.TRANSIENT) != 0; }
/**
* This flag is set on 'variable arity' (a.k.a. 'varargs') methods and constructors. Notice that it has the same
* value as {@link #TRANSIENT}, which is OK because {@link #VARARGS} is for methods and {@link #TRANSIENT} for
* fields.
*/
public static final short VARARGS = 0x0080;
/** @return Whether the given modifier includes {@link #VARARGS} */
public static boolean isVarargs(short sh) { return (sh & Mod.VARARGS) != 0; }
/** This flag is set on NATIVE methods, and is mutually exclusive with {@link #ABSTRACT}. */
public static final short NATIVE = 0x0100;
/** @return Whether the given modifier includes {@link #NATIVE} */
public static boolean isNative(short sh) { return (sh & Mod.NATIVE) != 0; }
/**
* This flag is set on interfaces (including nested interfaces), and requires that {@link #ABSTRACT} must also be
* set. {@link #INTERFACE} is mutually exclusive with {@link #FINAL}, {@link #SUPER} and {@link #ENUM}.
*/
public static final short INTERFACE = 0x0200;
/** @return Whether the given modifier includes {@link #INTERFACE} */
public static boolean isInterface(short sh) { return (sh & Mod.INTERFACE) != 0; }
/**
* This flag is set on all interfaces, ABSTRACT classes and ABSTRACT methods, and is mutually exclusive with
* {@link #FINAL}, {@link #NATIVE}, {@link #PRIVATE}, {@link #STATIC} and {@link #SYNCHRONIZED}.
*/
public static final short ABSTRACT = 0x0400;
/** @return Whether the given modifier includes {@link #ABSTRACT} */
public static boolean isAbstract(short sh) { return (sh & Mod.ABSTRACT) != 0; }
/** This flag is set on STRICTFP methods, and is mutually exclusive with {@link #ABSTRACT}. */
public static final short STRICTFP = 0x0800;
/** @return Whether the given modifier includes {@link #STRICTFP} */
public static boolean isStrictfp(short sh) { return (sh & Mod.STRICTFP) != 0; }
// Poorly documented JDK 1.5 modifiers:
/**
* This flag is set on classes, methods and fields that were generated by the compiler and do not appear in the
* source code.
*/
public static final short SYNTHETIC = 0x1000;
/** @return Whether the given modifier includes {@link #SYNTHETIC} */
public static boolean isSynthetic(short sh) { return (sh & Mod.SYNTHETIC) != 0; }
/**
* This flag is set on annotation types (including nested annotation types), and requires that {@link #INTERFACE}
* is also set.
*/
public static final short ANNOTATION = 0x2000;
/** @return Whether the given modifier includes {@link #ANNOTATION} */
public static boolean isAnnotation(short sh) { return (sh & Mod.ANNOTATION) != 0; }
/**
* This flag is set on enumerated types (including nested enumerated types) and enumerated types' elements, and is
* mutually exclusive with {@link #INTERFACE}.
*/
public static final short ENUM = 0x4000;
/** @return Whether the given modifier includes {@link #ENUM} */
public static boolean isEnum(short sh) { return (sh & Mod.ENUM) != 0; }
/**
* Composes and returns a string that maps the given modifier as follows:
* <ul>
* <li>Value zero is mapped to "".
* <li>Non-zero values are mapped to a sequence of words, separated with blanks.
* <li>{@link #VARARGS} is mapped to "transient", because the two flags have the same value
* <li>{@link #SUPER} is mapped to "synchronized", because the two flags have the same value
* <li>{@link #BRIDGE} is mapped to "volatile", because the two flags have the same value
* </ul>
*/
public static String
shortToString(short sh) {
if (sh == 0) return "";
StringBuilder res = new StringBuilder();
for (int i = 0; i < Mod.MAPPINGS.length; i += 2) {
if ((sh & ((Short) Mod.MAPPINGS[i + 1]).shortValue()) == 0) continue;
if (res.length() > 0) res.append(' ');
res.append((String) Mod.MAPPINGS[i]);
}
return res.toString();
}
private static final Object[] MAPPINGS = {
"public", new Short(Mod.PUBLIC),
"private", new Short(Mod.PRIVATE),
"protected", new Short(Mod.PROTECTED),
// "???", new Short(Mod.PACKAGE),
"static", new Short(Mod.STATIC),
"final", new Short(Mod.FINAL),
"synchronized", new Short(Mod.SYNCHRONIZED), // Has the same value as SUPER
// "super", new Short(Mod.SUPER), // Has the same value as SYNCHRONIZED
"volatile", new Short(Mod.VOLATILE), // Has the same value as BRIDGE
// "bridge", new Short(Mod.BRIDGE), // Has the same value as VOLATILE
"transient", new Short(Mod.TRANSIENT), // Has the same value as VARARGS
// "varargs", new Short(Mod.VARARGS), // Has the same value as TRANSIENT
"native", new Short(Mod.NATIVE),
"interface", new Short(Mod.INTERFACE),
"abstract", new Short(Mod.ABSTRACT),
"strictfp", new Short(Mod.STRICTFP),
"enum", new Short(Mod.ENUM),
"synthetic", new Short(Mod.SYNTHETIC),
"@", new Short(Mod.ANNOTATION),
};
}