1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.apache.juneau.commons.reflect;
18
19 /**
20 * Enumeration of possible modifiers and attributes that can be present on classes, methods, fields, and constructors.
21 *
22 * <p>
23 * This enum provides a comprehensive set of flags for identifying Java language modifiers (public, private, static, etc.)
24 * and other attributes (synthetic, deprecated, etc.) that can be present on program elements. Each modifier has both
25 * a positive flag (e.g., <c>PUBLIC</c>) and a negated flag (e.g., <c>NOT_PUBLIC</c>) for convenient filtering.
26 *
27 * <h5 class='section'>Features:</h5>
28 * <ul class='spaced-list'>
29 * <li>Java modifiers - all standard Java modifiers (public, private, protected, static, final, etc.)
30 * <li>Negated flags - each modifier has a corresponding NOT_* flag for filtering
31 * <li>Non-modifier attributes - flags for synthetic, deprecated, bridge methods, etc.
32 * <li>Type attributes - flags for identifying classes, interfaces, enums, records, annotations
33 * </ul>
34 *
35 * <h5 class='section'>Use Cases:</h5>
36 * <ul class='spaced-list'>
37 * <li>Filtering classes, methods, fields by modifiers
38 * <li>Identifying special attributes (synthetic, deprecated, bridge methods)
39 * <li>Type checking (enum, record, annotation, interface)
40 * <li>Building frameworks that need to analyze program element characteristics
41 * </ul>
42 *
43 * <h5 class='section'>Usage:</h5>
44 * <p class='bjava'>
45 * <jc>// Check if a class is public</jc>
46 * ClassInfo <jv>ci</jv> = ClassInfo.<jsm>of</jsm>(MyClass.<jk>class</jk>);
47 * <jk>boolean</jk> <jv>isPublic</jv> = <jv>ci</jv>.hasFlag(ElementFlag.PUBLIC);
48 *
49 * <jc>// Filter methods by modifier</jc>
50 * List<MethodInfo> <jv>staticMethods</jv> = <jv>ci</jv>.getMethods()
51 * .stream()
52 * .filter(<jv>m</jv> -> <jv>m</jv>.hasFlag(ElementFlag.STATIC))
53 * .toList();
54 *
55 * <jc>// Check for deprecated methods</jc>
56 * <jk>boolean</jk> <jv>isDeprecated</jv> = <jv>method</jv>.hasFlag(ElementFlag.DEPRECATED);
57 * </p>
58 *
59 * <h5 class='section'>Modifier Flags:</h5>
60 * <p>
61 * Standard Java modifiers: <c>PUBLIC</c>, <c>PRIVATE</c>, <c>PROTECTED</c>, <c>STATIC</c>, <c>FINAL</c>,
62 * <c>SYNCHRONIZED</c>, <c>VOLATILE</c>, <c>TRANSIENT</c>, <c>NATIVE</c>, <c>ABSTRACT</c>.
63 * Each has a corresponding <c>NOT_*</c> flag.
64 *
65 * <h5 class='section'>Attribute Flags:</h5>
66 * <p>
67 * Non-modifier attributes: <c>ANNOTATION</c>, <c>ANONYMOUS</c>, <c>ARRAY</c>, <c>BRIDGE</c>, <c>CLASS</c>,
68 * <c>CONSTRUCTOR</c>, <c>DEFAULT</c>, <c>DEPRECATED</c>, <c>ENUM</c>, <c>ENUM_CONSTANT</c>, <c>HAS_PARAMS</c>,
69 * <c>LOCAL</c>, <c>MEMBER</c>, <c>NON_STATIC_MEMBER</c>, <c>PRIMITIVE</c>, <c>RECORD</c>, <c>SEALED</c>,
70 * <c>SYNTHETIC</c>, <c>VARARGS</c>.
71 *
72 * <h5 class='section'>See Also:</h5><ul>
73 * <li class='jc'>{@link ElementInfo} - Base class that uses these flags
74 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauCommonsReflection">Reflection Package</a>
75 * </ul>
76 */
77 public enum ElementFlag {
78
79 // Java modifiers from java.lang.reflect.Modifier
80
81 /** PUBLIC modifier */
82 PUBLIC,
83
84 /** NOT_PUBLIC (negated) */
85 NOT_PUBLIC,
86
87 /** PRIVATE modifier */
88 PRIVATE,
89
90 /** NOT_PRIVATE (negated) */
91 NOT_PRIVATE,
92
93 /** PROTECTED modifier */
94 PROTECTED,
95
96 /** NOT_PROTECTED (negated) */
97 NOT_PROTECTED,
98
99 /** STATIC modifier */
100 STATIC,
101
102 /** NOT_STATIC (negated) */
103 NOT_STATIC,
104
105 /** FINAL modifier */
106 FINAL,
107
108 /** NOT_FINAL (negated) */
109 NOT_FINAL,
110
111 /** SYNCHRONIZED modifier */
112 SYNCHRONIZED,
113
114 /** NOT_SYNCHRONIZED (negated) */
115 NOT_SYNCHRONIZED,
116
117 /** VOLATILE modifier */
118 VOLATILE,
119
120 /** NOT_VOLATILE (negated) */
121 NOT_VOLATILE,
122
123 /** TRANSIENT modifier */
124 TRANSIENT,
125
126 /** NOT_TRANSIENT (negated) */
127 NOT_TRANSIENT,
128
129 /** NATIVE modifier */
130 NATIVE,
131
132 /** NOT_NATIVE (negated) */
133 NOT_NATIVE,
134
135 /** INTERFACE modifier */
136 INTERFACE,
137
138 /** ABSTRACT modifier */
139 ABSTRACT,
140
141 /** NOT_ABSTRACT (negated) */
142 NOT_ABSTRACT,
143
144 // Non-modifier attributes
145
146 /** ANNOTATION (is an annotation type) */
147 ANNOTATION,
148
149 /** NOT_ANNOTATION (not an annotation type) */
150 NOT_ANNOTATION,
151
152 /** ANONYMOUS (is an anonymous class) */
153 ANONYMOUS,
154
155 /** NOT_ANONYMOUS (not an anonymous class) */
156 NOT_ANONYMOUS,
157
158 /** ARRAY (is an array type) */
159 ARRAY,
160
161 /** NOT_ARRAY (not an array type) */
162 NOT_ARRAY,
163
164 /** BRIDGE (is a bridge method) */
165 BRIDGE,
166
167 /** NOT_BRIDGE (not a bridge method) */
168 NOT_BRIDGE,
169
170 /** CLASS (is a class, not an interface) */
171 CLASS,
172
173 /** CONSTRUCTOR (is a constructor) */
174 CONSTRUCTOR,
175
176 /** NOT_CONSTRUCTOR (not a constructor) */
177 NOT_CONSTRUCTOR,
178
179 /** DEFAULT (is a default interface method) */
180 DEFAULT,
181
182 /** NOT_DEFAULT (not a default interface method) */
183 NOT_DEFAULT,
184
185 /** DEPRECATED (has @Deprecated annotation) */
186 DEPRECATED,
187
188 /** NOT_DEPRECATED (no @Deprecated annotation) */
189 NOT_DEPRECATED,
190
191 /** ENUM (is an enum type) */
192 ENUM,
193
194 /** NOT_ENUM (not an enum type) */
195 NOT_ENUM,
196
197 /** ENUM_CONSTANT (is an enum constant field) */
198 ENUM_CONSTANT,
199
200 /** NOT_ENUM_CONSTANT (not an enum constant field) */
201 NOT_ENUM_CONSTANT,
202
203 /** HAS_PARAMS (has parameters) */
204 HAS_PARAMS,
205
206 /** HAS_NO_PARAMS (has no parameters) */
207 HAS_NO_PARAMS,
208
209 /** LOCAL (is a local class) */
210 LOCAL,
211
212 /** NOT_LOCAL (not a local class) */
213 NOT_LOCAL,
214
215 /** MEMBER (is a member class) */
216 MEMBER,
217
218 /** NOT_MEMBER (not a member class) */
219 NOT_MEMBER,
220
221 /** NON_STATIC_MEMBER (is a non-static member class) */
222 NON_STATIC_MEMBER,
223
224 /** NOT_NON_STATIC_MEMBER (not a non-static member class) */
225 NOT_NON_STATIC_MEMBER,
226
227 /** PRIMITIVE (is a primitive type) */
228 PRIMITIVE,
229
230 /** NOT_PRIMITIVE (not a primitive type) */
231 NOT_PRIMITIVE,
232
233 /** RECORD (is a record type) */
234 RECORD,
235
236 /** NOT_RECORD (not a record type) */
237 NOT_RECORD,
238
239 /** SEALED (is a sealed class) */
240 SEALED,
241
242 /** NOT_SEALED (not a sealed class) */
243 NOT_SEALED,
244
245 /** SYNTHETIC (is compiler-generated) */
246 SYNTHETIC,
247
248 /** NOT_SYNTHETIC (not compiler-generated) */
249 NOT_SYNTHETIC,
250
251 /** VARARGS (has variable arity) */
252 VARARGS,
253
254 /** NOT_VARARGS (does not have variable arity) */
255 NOT_VARARGS
256 }