Skip to content

Commit 0d82cc8

Browse files
committed
Updated KDOC guide with typealias recommendation
1 parent 6adaa75 commit 0d82cc8

File tree

1 file changed

+49
-23
lines changed

1 file changed

+49
-23
lines changed

KDOC_PREPROCESSING.md

Lines changed: 49 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ This document explains how to use KoDEx in the DataFrame project.
2929
* [`\`: Escape Character](#-escape-character)
3030
* [
3131
`@ExcludeFromSources` Annotation: Excluding code content from sources](#excludefromsources-annotation-excluding-code-content-from-sources)
32+
* [Using Typealiases to save Byte Size](#using-nested-typealiases-instead-of-interfaces)
3233
* [KoDEx Conventions in DataFrame](#kodex-conventions-in-dataframe)
3334
* [Common Concepts and Definitions](#common-concepts-and-definitions)
3435
* [Link Interfaces](#link-interfaces)
@@ -356,6 +357,31 @@ Since [v0.3.9](https://github.com/Jolanrensen/KoDEx/releases/tag/v0.3.9) it's al
356357
exclude a whole file from the `sources.jar` by adding the annotation to the top of the file,
357358
like `@file:ExcludeFromSources`.
358359

360+
### Using (nested) Type Aliases Instead of Interfaces
361+
362+
([Nested](https://kotlinlang.org/docs/type-aliases.html#nested-type-aliases))
363+
[Type aliases](https://kotlinlang.org/docs/type-aliases.html)
364+
can be used to save byte size in the published library.jar file.
365+
This is useful when you have a lot of documentation interfaces without a body that are only used to host KDoc.
366+
367+
For example:
368+
369+
```kt
370+
/** [Common doc][CommonDoc] */
371+
typealias CommonDocLink = Nothing
372+
373+
/**
374+
* ## {@include [CommonDocLink]}
375+
* Hello from $[NAME]!
376+
*/
377+
interface CommonDoc {
378+
379+
// name argument
380+
typealias NAME = Nothing
381+
}
382+
```
383+
384+
359385
## KoDEx Conventions in DataFrame
360386

361387
### Common Concepts and Definitions
@@ -385,24 +411,24 @@ and include things like:
385411
- [`NA`](./core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/documentation/NA.kt) / [`NaN`](./core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/documentation/NaN.kt)
386412
- To be linked to for more information on the concepts
387413
- [DslGrammar](./core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/documentation/DslGrammar.kt)
388-
- To be linked to from each DSL grammar by the link interface
414+
- To be linked to from each DSL grammar by the link KDoc
389415
- Check the folder to see if there are more and feel free to add them if needed :)
390416

391-
### Link Interfaces
417+
### Link KDocs
392418

393-
As can be seen, interfaces that can be "linked" to, like [`AccessApi`](./core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/documentation/AccessApi.kt), are often
394-
accompanied by a `-Link` interface, like
419+
As can be seen, KDocs that can be "linked" to, like [`AccessApi`](./core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/documentation/AccessApi.kt), are often
420+
accompanied by a `-Link` doc, like
395421

396422
```kt
397423
/** [Access API][AccessApi] */
398-
internal interface AccessApiLink
424+
internal typealias AccessApiLink = Nothing
399425
```
400426

401427
This allows other docs to simply `{@include [AccessApiLink]}` if they want to refer to
402428
Access APIs, and it provides a single place of truth for if we ever want to rename this concept.
403429

404-
In general, docs accompanied by a `-Link` interface are meant to be linked to, while docs without
405-
a `-Link` interface are meant to be included in other docs
430+
In general, docs accompanied by a `-Link` KDoc are meant to be linked to, while docs without
431+
a `-Link` doc are meant to be included in other docs
406432
(and are often accompanied by [`@ExcludeFromSources`](#excludefromsources-annotation-excluding-code-content-from-sources)).
407433
We can deviate from this convention if it makes sense, of course.
408434

@@ -416,10 +442,10 @@ We can deviate from this convention if it makes sense, of course.
416442
interface CommonDoc {
417443

418444
// The name to be greeted from
419-
interface NameArg
445+
typealias NameArg = Nothing
420446

421447
// alternative recommended notation
422-
interface NAME
448+
typealias NAME = Nothing
423449
}
424450
```
425451

@@ -432,15 +458,15 @@ A good example of this concept can be found in the
432458
This interface provides a template for all overloads of `allBefore`,
433459
`allAfter`, `allFrom`, and `allUpTo` in a single place.
434460

435-
Nested in the documentation interface, there are several other interfaces that define the expected arguments
461+
Nested in the documentation interface, there are several type aliases that define the expected arguments
436462
of the template.
437-
These interfaces are named `TitleArg`/`TITLE`, `FunctionArg`/`FUNCTION`, etc. and commonly have no KDocs itself,
463+
These are named `TitleArg`/`TITLE`, `FunctionArg`/`FUNCTION`, etc. and commonly have no KDocs itself,
438464
just a simple comment explaining what the argument is for.
439465

440-
Other documentation interfaces like `AllAfterDocs` or functions then include `CommonAllSubsetDocs` and set
466+
Other documentation holders like `AllAfterDocs` or functions then include `CommonAllSubsetDocs` and set
441467
all the arguments accordingly.
442468

443-
It's recommended to name argument interfaces `-Arg`, or to write their name in `ALL_CAPS` (if the linter is shushed)
469+
It's recommended to name arguments `-Arg`, or to write their name in `ALL_CAPS` (if the linter is shushed)
444470
and have them nested in the documentation interface, though,
445471
this has not always been done in the past.
446472

@@ -455,9 +481,9 @@ it easier to update the documentation whenever (part of) a URL changes.
455481

456482
### Utils
457483

458-
The [`utils.kt` file](./core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/documentation/utils.kt) contains all sorts of helper interfaces for the documentation.
459-
For instance `{@include [LineBreak]}` can insert a line break in the KDoc and the family of `Indent`
460-
documentation interfaces can provide you with different non-breaking-space-based indents.
484+
The [`utils.kt` file](./core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/documentation/utils.kt) contains all sorts of helpers for the documentation.
485+
For instance `{@include [LineBreak]}` can insert a line break in the KDoc, and the family of `Indent`
486+
documentation type aliases can provide you with different non-breaking-space-based indents.
461487

462488
If you need a new utility, feel free to add it to this file.
463489

@@ -499,7 +525,7 @@ some [helpful templates](core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/do
499525
![selectingColumns.png](docs/imgs/selectingColumns.png)
500526

501527
This is a bit large, so it's best if we just link to it. Also, you'll see the examples have
502-
the generic `operation` name. So let's create our own interface `SelectSelectingOptions` we can let users link to and
528+
the generic `operation` name. So let's create our own type `SelectSelectingOptions` we can let users link to and
503529
`{@set [SelectingColumns.OPERATION] [select][select]}`.
504530
Actually, we can even put this setting the operation arg in a central place, since we reuse it a lot.
505531

@@ -559,7 +585,7 @@ But keep these things in mind:
559585
![dslgrammar.png](docs/imgs/dslgrammar.png)
560586

561587
Any family of functions or operations can show off their notation in a DSL grammar.
562-
This is done by creating a documentation interface like
588+
This is done by creating a documentation type like
563589
[`Update.Grammar`](./core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/update.kt) and linking to it
564590
from each function.
565591

@@ -650,21 +676,21 @@ All other parts are filled in like:
650676
interface Grammar {
651677

652678
/** [**`first`**][ColumnsSelectionDsl.first] */
653-
interface PlainDslName
679+
typealias PlainDslName = Nothing
654680

655681
/** __`.`__[**`first`**][ColumnsSelectionDsl.first] */
656-
interface ColumnSetName
682+
typealias ColumnSetName = Nothing
657683

658684
/** __`.`__[**`firstCol`**][ColumnsSelectionDsl.firstCol] */
659-
interface ColumnGroupName
685+
typealias ColumnGroupName = Nothing
660686
}
661687
```
662688

663689
When a reference to a certain definition is used, we take `DslGrammarTemplate.XRef`.
664690
Clicking on them takes users to the respective
665691
`XDef` and thus provides them with the formal name and type of the definition.
666692

667-
You may also notice that the `PlainDslName`, `ColumnSetName`, and `ColumnGroupName` interfaces are defined separately.
693+
You may also notice that the `PlainDslName`, `ColumnSetName`, and `ColumnGroupName` types are defined separately.
668694
This is to make sure they can be reused in the large Columns Selection DSL grammar and on the website.
669695

670696
You don't always need all three parts in the grammar; not all functions can be used in each context.
@@ -691,7 +717,7 @@ A fully interactive, single-source-of-truth grammar for the Columns Selection DS
691717
## KDoc -> WriterSide
692718

693719
There's a special annotation, `@ExportAsHtml`, that allows you to export the content of the KDoc of the annotated
694-
function, interface, or class as HTML.
720+
function, interface, type alias, or class as HTML.
695721
The Markdown of the KDoc is rendered to HTML using [JetBrains/markdown](https://github.com/JetBrains/markdown) and, in
696722
the case of DataFrame, put in [./docs/StardustDocs/resources/snippets/kdocs](docs/StardustDocs/resources/snippets/kdocs).
697723
From there, the HTML can be included in any WriterSide page as an iFrame.

0 commit comments

Comments
 (0)