Skip to content

Commit b4cba18

Browse files
committed
Polish the documentation
1 parent 3898cab commit b4cba18

File tree

93 files changed

+2195
-1878
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+2195
-1878
lines changed

Writerside/hi.tree

Lines changed: 61 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,57 +5,82 @@
55
<toc-element topic="Index.md"/>
66
<toc-element topic="Fundamentals.md"/>
77
<toc-element topic="Symbols.md">
8-
<toc-element topic="KtFileSymbol.md"/>
9-
<toc-element topic="KtClassOrObjectSymbol.md"/>
10-
<toc-element topic="KtTypeParameterSymbol.md"/>
11-
<toc-element topic="KtCallableSymbol.md">
12-
<toc-element topic="KtVariableLikeSymbol.md">
13-
<toc-element topic="KtPropertySymbol.md"/>
14-
<toc-element topic="KtValueParameterSymbol.md"/>
8+
<toc-element topic="KaSymbol.md">
9+
</toc-element>
10+
<toc-element topic="KaDeclarationSymbol.md">
11+
</toc-element>
12+
<toc-element topic="KaClassifierSymbol.md">
13+
<toc-element topic="KaClassLikeSymbol.md">
14+
<toc-element topic="KaClassSymbol.md">
15+
<toc-element topic="KaNamedClassSymbol.md"/>
16+
<toc-element topic="KaAnonymousObjectSymbol.md"/>
17+
</toc-element>
18+
<toc-element topic="KaTypeAliasSymbol.md"/>
1519
</toc-element>
16-
<toc-element topic="KtFunctionLikeSymbol.md">
17-
<toc-element topic="KtConstructorSymbol.md"/>
18-
<toc-element topic="KtFunctionSymbol.md"/>
20+
<toc-element topic="KaTypeParameterSymbol.md"/>
21+
</toc-element>
22+
<toc-element topic="KaCallableSymbol.md">
23+
<toc-element topic="KaFunctionSymbol.md">
24+
<toc-element topic="KaNamedFunctionSymbol.md"/>
25+
<toc-element topic="KaAnonymousFunctionSymbol.md"/>
26+
<toc-element topic="KaConstructorSymbol.md"/>
27+
<toc-element topic="KaPropertyAccessorSymbol.md"/>
28+
</toc-element>
29+
<toc-element topic="KaVariableSymbol.md">
30+
<toc-element topic="KaPropertySymbol.md"/>
31+
<toc-element topic="KaValueParameterSymbol.md"/>
32+
<toc-element topic="KaLocalVariableSymbol.md"/>
33+
<toc-element topic="KaBackingFieldSymbol.md"/>
34+
<toc-element topic="KaEnumEntrySymbol.md"/>
1935
</toc-element>
2036
</toc-element>
2137
</toc-element>
38+
<toc-element topic="Scopes.md"/>
2239
<toc-element topic="Types.md">
23-
<toc-element topic="Type-Projections.md"/>
24-
<toc-element topic="Expression-Types.md"/>
25-
<toc-element topic="Java-Kotlin-Type-Bridging.md"/>
26-
<toc-element topic="KtType.md">
27-
<toc-element topic="KtClassType.md"/>
28-
<toc-element topic="KtFunctionalType.md"/>
29-
<toc-element topic="KtTypeParameterType.md"/>
30-
<toc-element topic="KtDefinitelyNotNullType.md"/>
31-
<toc-element topic="KtIntersectionType.md"/>
32-
<toc-element topic="KtCapturedType.md"/>
33-
<toc-element topic="KtFlexibleType.md"/>
34-
<toc-element topic="KtDynamicType.md">
40+
<toc-element topic="KaType.md">
41+
<toc-element topic="KaClassType.md">
42+
<toc-element topic="KaUsualClassType.md"/>
43+
<toc-element topic="KaFunctionType.md"/>
44+
</toc-element>
45+
<toc-element topic="KaTypeParameterType.md"/>
46+
<toc-element topic="KaDefinitelyNotNullType.md"/>
47+
<toc-element topic="KaIntersectionType.md"/>
48+
<toc-element topic="KaCapturedType.md"/>
49+
<toc-element topic="KaFlexibleType.md"/>
50+
<toc-element topic="KaDynamicType.md"/>
51+
<toc-element topic="KaErrorType.md">
52+
<toc-element topic="KaClassErrorType.md"/>
3553
</toc-element>
3654
</toc-element>
55+
<toc-element topic="KaTypeProjection.md"/>
3756
</toc-element>
3857
<toc-element topic="Annotations.md">
39-
<toc-element topic="Annotation-Values.md"/>
58+
<toc-element topic="KaAnnotation.md"/>
59+
<toc-element topic="KaAnnotationValue.md"/>
4060
</toc-element>
41-
<toc-element topic="Scopes.md"/>
42-
<toc-element topic="Calls-And-References.md">
43-
<toc-element topic="KtCall.md">
44-
<toc-element topic="KtFunctionCall.md">
45-
<toc-element topic="KtSimpleFunctionCall.md"/>
46-
<toc-element topic="KtDelegatedConstructorCall.md"/>
47-
</toc-element>
48-
<toc-element topic="KtVariableCall.md">
49-
<toc-element topic="KtCompoundVariableAccessCall.md"/>
61+
<toc-element topic="References-And-Calls.md">
62+
<toc-element topic="KaCall.md">
63+
<toc-element topic="KaCallableMemberCall.md">
64+
<toc-element topic="KaFunctionCall.md">
65+
<toc-element topic="KaSimpleFunctionCall.md"/>
66+
<toc-element topic="KaDelegatedConstructorCall.md"/>
67+
<toc-element topic="KaAnnotationCall.md"/>
68+
</toc-element>
69+
<toc-element topic="KaVariableAccessCall.md">
70+
</toc-element>
71+
<toc-element topic="KaCompoundVariableAccessCall.md"/>
72+
<toc-element topic="KaCompoundArrayAccessCall.md"/>
5073
</toc-element>
51-
<toc-element topic="KtQualifierCall.md"/>
52-
<toc-element topic="KtCheckNotNullCall.md"/>
53-
<toc-element topic="KtGenericTypeQualifier.md"/>
5474
</toc-element>
5575
<toc-element topic="Receivers.md"/>
5676
</toc-element>
5777
<toc-element topic="Other.md">
58-
<toc-element topic="Diagnostics.md"/>
78+
<toc-element topic="Java-Kotlin-Bridging.md"/>
79+
<toc-element topic="Diagnostics.md">
80+
<toc-element topic="KaDiagnostic.md">
81+
</toc-element>
82+
<toc-element topic="KaDiagnosticWithPsi.md"/>
83+
</toc-element>
5984
<toc-element topic="File-Compilation.md"/>
6085
</toc-element>
6186
<toc-element topic="Guides.md">

Writerside/redirection-rules.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,4 @@
66
<accepts>page.html</accepts>
77
</rule>
88
-->
9-
<rule id="638a6070">
10-
<description>Created after removal of "OLD" from Analysis API Documentation</description>
11-
<accepts>Old-Home.html</accepts>
12-
</rule>
13-
<rule id="3e5793c0">
14-
<description>Created after removal of "Call Resolution" from Analysis API Documentation</description>
15-
<accepts>Call-Resolution.html</accepts>
16-
</rule>
179
</rules>

Writerside/topics/Annotation-Values.md

Lines changed: 0 additions & 60 deletions
This file was deleted.

Writerside/topics/Annotations.md

Lines changed: 49 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,63 @@
11
# Annotations
22

3-
Annotations play a crucial role in Kotlin, providing metadata and influencing code behavior. The Analysis API allows you
4-
to access and analyze annotations applied to both symbols (declarations) and types.
5-
6-
## Annotations on Symbols
7-
8-
To access annotations on a symbol, use the `annotationsList` property of the symbol:
9-
10-
```kotlin
11-
val symbol: KtSymbol = ... // Obtain a KtSymbol
12-
val annotationsList: KtAnnotationsList = symbol.annotationsList
13-
14-
val customAnnotationName = ClassId.fromString("kotlin/Deprecated")
15-
16-
// Check if a specific annotation is present
17-
val hasDeprecatedAnnotation = annotationsList.hasAnnotation(customAnnotationName)
18-
19-
// Get all annotations with a specific class name
20-
val annotations = annotationsList.annotationsByClassId(customAnnotationName)
3+
Annotations play a crucial role in Kotlin, providing metadata and influencing code behavior. Analysis API allows you
4+
to access and analyze annotations applied to both declarations and types.
5+
6+
## KaAnnotated
7+
8+
`KaAnnotated` is an interface exposing a list of annotations. All [types](Types.md) and almost all
9+
[symbols](Symbols.md) implement it.
10+
11+
<code-block lang="mermaid">
12+
graph TD
13+
KaAnnotated
14+
KaAnnotated --> KaType
15+
KaAnnotated --> KaAnnotatedSymbol
16+
KaAnnotatedSymbol --> KaFileSymbol
17+
KaAnnotatedSymbol --> KaScriptSymbol
18+
KaAnnotatedSymbol --> KaDeclarationSymbol
19+
</code-block>
20+
21+
The only property `KaAnnotated` declares is `annotations` of the `KaAnnotationList` type. `KaAnnotationList` itself
22+
is implements a `List<KaAnnotation>`, so you can directly iterate over annotations:
23+
24+
```Kotlin
25+
fun KaSession.processAnnotations(symbol: KaDeclarationSymbol) {
26+
for (anno in symbol.annotations) {
27+
// Process the 'annotation'
28+
}
29+
}
2130
```
2231

23-
`KtAnnotationsList` provides several methods for working with annotations:
32+
`KaAnnotationsList` is not just a list. It can also efficiently check whether an annotation with some `ClassId`
33+
is there:
2434

25-
* **annotations**: A list of `KtAnnotationApplicationWithArgumentsInfo`, providing details about each annotation,
26-
including its class ID, arguments, and use-site target.
27-
* **annotationInfos**: A list of `KtAnnotationApplicationInfo`, offering a lighter-weight representation with just the
28-
class ID and use-site target.
29-
* **hasAnnotation**: Checks if an annotation with a specific class ID and optional use-site target filter is present.
30-
* **annotationsByClassId**: Retrieves a list of annotations with a specific class ID and optional use-site target
31-
filter.
35+
```Kotlin
36+
fun KaSession.hasDeprecatedAnnotation(symbol: KaDeclarationSymbol) {
37+
val classId = ClassId.fromString("kotlin/Deprecated")
38+
return classId in symbol.annotations
39+
}
40+
```
3241

33-
## Annotations on Types
42+
You can also get a list of annotations with a specific `ClassId`. Kotlin allows repeatable annotations, so a list
43+
of them is returned:
3444

35-
Annotations can also be applied to types, such as type arguments or the receiver type of an extension function. To
36-
access annotations on a type, use the `annotationsList` property:
45+
```Kotlin
46+
fun KaSession.findDeprecatedAnnotation(symbol: KaDeclarationSymbol): KaAnnotation? {
47+
val classId = ClassId.fromString("kotlin/Deprecated")
48+
return symbol.annotations[classId].firstOrNull()
49+
}
50+
```
3751

38-
```kotlin
39-
val type: KtType = ... // Obtain a KtType instance
40-
val annotationsList: KtAnnotationsList = type.annotationsList
52+
Finally, `KaAnnotationList` exposes a collection of all annotation `ClassId`s:
4153

42-
// Check if the type has the @Nullable annotation
43-
val isNullable = annotationsList.hasAnnotation(ClassId.fromString("org/jetbrains/annotations/Nullable"))
54+
```Kotlin
55+
fun KaSession.collectAnnotations(types: List<KaType>): Set<ClassId> {
56+
return types.flatMapTo(HashSet()) { it.annotations.classIds }
57+
}
4458
```
4559

4660
## Use-Site Targets
4761

4862
Annotations on declarations can have use-site targets, specifying where the annotation applies (e.g., property, field,
49-
or parameter). You can use the `useSiteTarget` property of `KtAnnotationApplication` to access this information.
63+
or parameter). You can use the `useSiteTarget` property of `KtAnnotation` to access this information.

Writerside/topics/Calls-And-References.md

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)