| 1 |
package jakarta.enterprise.lang.model.declarations; |
| 2 |
|
| 3 |
import jakarta.enterprise.lang.model.types.Type; |
| 4 |
import jakarta.enterprise.lang.model.types.TypeVariable; |
| 5 |
|
| 6 |
import java.util.Collection; |
| 7 |
import java.util.List; |
| 8 |
|
| 9 |
/** |
| 10 |
* A class. Five kinds of classes are distinguished: |
| 11 |
* <ul> |
| 12 |
* <li>plain classes</li> |
| 13 |
* <li>interfaces</li> |
| 14 |
* <li>enums (restricted kind of classes)</li> |
| 15 |
* <li>annotations (specialized kind of interfaces)</li> |
| 16 |
* <li>records (restricted kind of classes)</li> |
| 17 |
* </ul> |
| 18 |
* |
| 19 |
* Classes are represented as isolated units. That is, if this class is nested, it is not possible |
| 20 |
* to obtain the enclosing class. Similarly, it is not possible to obtain the set of classes |
| 21 |
* nested in this class. |
| 22 |
* <p> |
| 23 |
* At the same time, it is possible to obtain the set of {@linkplain #constructors() constructors}, |
| 24 |
* {@linkplain #methods() methods} and {@linkplain #fields() fields} declared in this class, as well |
| 25 |
* as the set of {@linkplain #recordComponents() record components} if this class is a record. |
| 26 |
* It is also possible to obtain the {@linkplain #packageInfo() package} this class is declared in. |
| 27 |
* |
| 28 |
* @since 4.0 |
| 29 |
*/ |
| 30 |
public interface ClassInfo extends DeclarationInfo { |
| 31 |
/** |
| 32 |
* Returns the binary name of this class, as defined by <cite>The Java™ Language Specification</cite>; |
| 33 |
* in other words, the class name as returned by {@link Class#getName()}. |
| 34 |
* |
| 35 |
* @return binary name of this class, never {@code null} |
| 36 |
*/ |
| 37 |
String name(); |
| 38 |
|
| 39 |
/** |
| 40 |
* Returns the simple name of this class, as defined by <cite>The Java™ Language Specification</cite>; |
| 41 |
* in other words, the class name as returned by {@link Class#getSimpleName()}. |
| 42 |
* |
| 43 |
* @return simple name of this class, never {@code null} |
| 44 |
*/ |
| 45 |
String simpleName(); |
| 46 |
|
| 47 |
/** |
| 48 |
* Returns the {@linkplain PackageInfo package} this class is part of. |
| 49 |
* Returns {@code null} if this class is part of an unnamed package. |
| 50 |
* |
| 51 |
* @return this class's package, or {@code null} if this class is in an unnamed package |
| 52 |
*/ |
| 53 |
PackageInfo packageInfo(); |
| 54 |
|
| 55 |
/** |
| 56 |
* Returns a list of {@linkplain TypeVariable type parameters} declared on this class. |
| 57 |
* Returns an empty list if this class is not generic and so does not declare type parameters. |
| 58 |
* |
| 59 |
* @return immutable list of this class's type parameters, never {@code null} |
| 60 |
*/ |
| 61 |
List<TypeVariable> typeParameters(); |
| 62 |
|
| 63 |
/** |
| 64 |
* Returns the {@linkplain Type type} of this class's superclass. Returns {@code null} if this class |
| 65 |
* does not have a superclass; that is, if this class is {@code java.lang.Object} or an interface. |
| 66 |
* |
| 67 |
* @return the type of this class's superclass, or {@code null} if there's no superclass |
| 68 |
*/ |
| 69 |
Type superClass(); |
| 70 |
|
| 71 |
/** |
| 72 |
* Returns the {@linkplain ClassInfo declaration} of this class's superclass. Returns {@code null} if this class |
| 73 |
* does not have a superclass; that is, if this class is {@code java.lang.Object} or an interface. |
| 74 |
* |
| 75 |
* @return the declaration of this class's superclass, or {@code null} if there's no superclass |
| 76 |
*/ |
| 77 |
ClassInfo superClassDeclaration(); |
| 78 |
|
| 79 |
/** |
| 80 |
* Returns a list of {@linkplain Type types} of this class's direct superinterfaces. |
| 81 |
* Returns an empty list if this class has no direct superinterface. |
| 82 |
* |
| 83 |
* @return immutable list of types of this class's direct superinterfaces, never {@code null} |
| 84 |
*/ |
| 85 |
List<Type> superInterfaces(); |
| 86 |
|
| 87 |
/** |
| 88 |
* Returns a list of {@linkplain ClassInfo declarations} of this class's direct superinterfaces. |
| 89 |
* Returns an empty list if this class has no direct superinterface. |
| 90 |
* |
| 91 |
* @return immutable list of declarations of this class's direct superinterfaces, never {@code null} |
| 92 |
*/ |
| 93 |
List<ClassInfo> superInterfacesDeclarations(); |
| 94 |
|
| 95 |
/** |
| 96 |
* Returns whether this class is a plain class. That is, not an interface, |
| 97 |
* not an enum, not an annotation, and not a record. |
| 98 |
* |
| 99 |
* @return whether this class is a plain class |
| 100 |
*/ |
| 101 |
boolean isPlainClass(); |
| 102 |
|
| 103 |
/** |
| 104 |
* Returns whether this class is an interface. |
| 105 |
* If this class is an annotation, returns {@code false}. |
| 106 |
* |
| 107 |
* @return whether this class is an interface |
| 108 |
*/ |
| 109 |
boolean isInterface(); |
| 110 |
|
| 111 |
/** |
| 112 |
* Returns whether this class is an enum. |
| 113 |
* |
| 114 |
* @return whether this class is an enum |
| 115 |
*/ |
| 116 |
boolean isEnum(); |
| 117 |
|
| 118 |
/** |
| 119 |
* Returns whether this class is an annotation. |
| 120 |
* |
| 121 |
* @return whether this class is an annotation |
| 122 |
*/ |
| 123 |
boolean isAnnotation(); |
| 124 |
|
| 125 |
/** |
| 126 |
* Returns whether this class is a record. |
| 127 |
* |
| 128 |
* @return whether this class is a record |
| 129 |
*/ |
| 130 |
boolean isRecord(); |
| 131 |
|
| 132 |
/** |
| 133 |
* Returns whether this class is abstract. |
| 134 |
* <p> |
| 135 |
* A plain class is abstract if declared {@code abstract}. |
| 136 |
* An enum is abstract if it declares {@code abstract} methods. |
| 137 |
* An interface or an annotation is always abstract. |
| 138 |
* A record is never abstract. |
| 139 |
* |
| 140 |
* @return whether this class is {@code abstract} |
| 141 |
*/ |
| 142 |
boolean isAbstract(); |
| 143 |
|
| 144 |
/** |
| 145 |
* Returns whether this class is {@code final}. |
| 146 |
* |
| 147 |
* @return whether this class is {@code final} |
| 148 |
*/ |
| 149 |
boolean isFinal(); |
| 150 |
|
| 151 |
/** |
| 152 |
* Returns the modifiers of this class as an {@code int}. |
| 153 |
* Use {@link java.lang.reflect.Modifier Modifier} to inspect the value. |
| 154 |
* |
| 155 |
* @return the modifiers of this class |
| 156 |
*/ |
| 157 |
int modifiers(); |
| 158 |
|
| 159 |
/** |
| 160 |
* Returns a collection of {@linkplain MethodInfo constructors} declared or implicitly declared |
| 161 |
* in this class. Constructors declared in direct or indirect superclasses are not included. |
| 162 |
* <p> |
| 163 |
* If this class is an interface or an annotation, returns an empty collection. |
| 164 |
* |
| 165 |
* @return immutable collection of constructors, never {@code null} |
| 166 |
*/ |
| 167 |
Collection<MethodInfo> constructors(); |
| 168 |
|
| 169 |
/** |
| 170 |
* Returns a collection of {@linkplain MethodInfo methods} declared or implicitly declared |
| 171 |
* in this class and all its superclasses up to and excluding {@code java.lang.Object}, |
| 172 |
* as well as all direct and indirect superinterfaces. If this class is an interface, |
| 173 |
* only superinterfaces are considered. Methods implicitly declared in interfaces are omitted. |
| 174 |
* <p> |
| 175 |
* If the collection of methods described above contains multiple methods with the same signature, |
| 176 |
* all such methods are returned. {@link MethodInfo#declaringClass() MethodInfo.declaringClass} |
| 177 |
* should be used to distinguish such methods. |
| 178 |
* <p> |
| 179 |
* Iteration order of the resulting collection is not defined and does not have to correspond |
| 180 |
* to the inheritance hierarchy of this class. |
| 181 |
* |
| 182 |
* @return immutable collection of methods, never {@code null} |
| 183 |
*/ |
| 184 |
Collection<MethodInfo> methods(); |
| 185 |
|
| 186 |
/** |
| 187 |
* Returns a collection of {@linkplain FieldInfo fields} declared or implicitly declared |
| 188 |
* in this class and all its superclasses up to and excluding {@code java.lang.Object}, |
| 189 |
* as well as all direct and indirect superinterfaces. If this class is an interface, |
| 190 |
* only superinterfaces are considered. |
| 191 |
* <p> |
| 192 |
* If the collection of fields described above contains multiple fields with the same name, |
| 193 |
* all such fields are returned. {@link FieldInfo#declaringClass() FieldInfo.declaringClass} |
| 194 |
* should be used to distinguish such fields |
| 195 |
* <p> |
| 196 |
* Iteration order of the resulting collection is not defined and does not have to correspond |
| 197 |
* to the inheritance hierarchy of this class. |
| 198 |
* |
| 199 |
* @return immutable collection of fields, never {@code null} |
| 200 |
*/ |
| 201 |
Collection<FieldInfo> fields(); |
| 202 |
|
| 203 |
/** |
| 204 |
* Returns a collection of {@linkplain RecordComponentInfo record components} declared in this class. |
| 205 |
* If this class is not a record, returns an empty collection. |
| 206 |
* |
| 207 |
* @return immutable collection of record components, never {@code nul} |
| 208 |
*/ |
| 209 |
Collection<RecordComponentInfo> recordComponents(); |
| 210 |
|
| 211 |
// --- |
| 212 |
|
| 213 |
@Override |
| 214 |
default Kind kind() { |
| 215 |
return Kind.CLASS; |
| 216 |
} |
| 217 |
|
| 218 |
@Override |
| 219 |
default ClassInfo asClass() { |
| 220 |
return this; |
| 221 |
} |
| 222 |
} |