scoop:scoop.core:0.1.0
src/type_info_annotations.scoop
Selected production source · src/type_info_annotations.scoop
1
/**2
* The identity of an annotation declaration, distinct from its display spelling.3
*/4
public struct AnnotationKey(5
val identity: String,6
val displayName: String,7
val describeBody: () -> AnnotationDeclarationInfo8
) : Equals<AnnotationKey> {9
/**10
* Compares annotation declaration identities.11
*/12
public override operator fun equals(other: AnnotationKey): Boolean = identity == other.identity14
/**15
* Returns the annotation declaration's parameter and annotation metadata.16
*/17
public fun describe(): AnnotationDeclarationInfo = describeBody()18
}20
/**21
* Describes an annotation declaration, its visibility, constructor parameters, and own22
* annotations.23
*/24
public struct AnnotationDeclarationInfo(25
val key: AnnotationKey,26
val visibility: DeclarationVisibility,27
val parameters: Array<AnnotationParameterInfo>,28
val annotations: Array<AnnotationInfo>29
)31
/**32
* A declared annotation parameter with its accepted constant type and optional default.33
*/34
public struct AnnotationParameterInfo(35
val id: ParameterRef,36
val name: String,37
val type: AnnotationParameterType,38
val defaultValue: Option<AnnotationValue>39
)41
/**42
* One applied annotation with resolved argument values bound to the declaring parameters.43
*/44
public struct AnnotationInfo(val key: AnnotationKey, val arguments: Array<AnnotationArgument>)46
/**47
* An evaluated annotation argument retaining both its parameter identity and declared constant48
* type.49
*/50
public struct AnnotationArgument(51
val parameter: ParameterRef,52
val name: String,53
val type: AnnotationParameterType,54
val value: AnnotationValue55
)57
/**58
* The supported scalar, integer-enum, nested-annotation, or homogeneous-array parameter59
* categories.60
*/61
public enum AnnotationParameterType {62
/**63
* A supported scalar constant with its concrete type.64
*/65
Scalar(TypeRef),66
/**67
* A constant from the identified integer-backed enum.68
*/69
IntegerEnum(TypeRef),70
/**71
* A nested instance of the identified annotation declaration.72
*/73
Annotation(AnnotationKey),74
/**75
* A homogeneous array of constants in the specified atom category.76
*/77
Array(AnnotationAtomType)78
}80
/**81
* The non-array categories allowed as elements of an annotation array.82
*/83
public enum AnnotationAtomType {84
/**85
* A supported scalar constant with its concrete type.86
*/87
Scalar(TypeRef),88
/**89
* A constant from the identified integer-backed enum.90
*/91
IntegerEnum(TypeRef),92
/**93
* A nested instance of the identified annotation declaration.94
*/95
Annotation(AnnotationKey)96
}98
/**99
* An integer annotation value retaining its declared width and signedness.100
*/101
public enum IntegerValue {102
/**103
* An integer constant with the width and signedness of Int8.104
*/105
Int8(Int8),106
/**107
* An integer constant with the width and signedness of Int16.108
*/109
Int16(Int16),110
/**111
* An integer constant with the width and signedness of Int.112
*/113
Int(Int),114
/**115
* An integer constant with the width and signedness of Long.116
*/117
Long(Long),118
/**119
* An integer constant with the width and signedness of UInt8.120
*/121
UInt8(UInt8),122
/**123
* An integer constant with the width and signedness of UInt16.124
*/125
UInt16(UInt16),126
/**127
* An integer constant with the width and signedness of UInt.128
*/129
UInt(UInt),130
/**131
* An integer constant with the width and signedness of ULong.132
*/133
ULong(ULong)134
}136
/**137
* An evaluated annotation constant. Floating-point payloads retain their raw bits, and enum values138
* retain variant identity.139
*/140
public enum AnnotationValue {141
/**142
* A Boolean constant.143
*/144
Boolean(Boolean),145
/**146
* An immutable text constant.147
*/148
String(String),149
/**150
* A Unicode scalar constant.151
*/152
Char(Char),153
/**154
* An integer retaining its width and signedness.155
*/156
Integer(IntegerValue),157
/**158
* Raw binary32 bits, preserving NaN payload and signed zero.159
*/160
FloatBits(UInt),161
/**162
* Raw binary64 bits, preserving NaN payload and signed zero.163
*/164
DoubleBits(ULong),165
/**166
* An integer-enum type, declared variant identity, and underlying integer value.167
*/168
IntegerEnum(TypeRef, VariantRef, IntegerValue),169
/**170
* A nested annotation instance.171
*/172
Annotation(AnnotationInfo),173
/**174
* A homogeneous array retaining its declared element category.175
*/176
Array(AnnotationAtomType, Array<AnnotationValue>)177
}179
/**180
* Returns every application with the requested annotation identity, preserving repeated181
* annotations and input order.182
*/183
public fun findAnnotations(items: Array<AnnotationInfo>, key: AnnotationKey): Array<AnnotationInfo> {184
val result = ArrayList<AnnotationInfo>()185
for (item in items) {186
if (item.key == key) {187
result.add(item)188
}189
}190
return result.toArray()191
}193
/**194
* Obtains the compiler-provided identity and description of annotation type A.195
*/196
@Intrinsic("annotation_key")197
public fun <A> annotationKey(): AnnotationKey