If
Last updated
Last updated
If exists out of multiple parts that can indefinately be chained: if
, else if
and else
.
Because KotlinPoetDSL adds completed components to code and not uncompleted code, KotlinPoetDSL needs to know if an if-statement needs to be finished.
This can be done with an additional wrapper around the if-statement, or requiring to call an closing function: endIf
or else
. KotlinPoetDSL choose for the second option.
When the if is not finished, there are two things we can do: either don't add it, or throw an exception. Because the code is generated inside the DSL, just ignoring the if can lead to confusion. Therefor, KotlinPoetDSL throws exceptions.
KotlinPoetDSL has three kinds of if:
Okidoki, here we go!
will evaluate to:
name
evaluates true if
code generated
if
The content is true, null throws exception
if (...) {
ifp
The content is positive, null is false
if ((...) == true) {
ifn
The content is negative, null is false
if ((...) == false) {
name
evaluates true if
code generated
orElseIf
The content is true, null throws exception
} else if(...) {
orElseIfP
The content is positive, null is false
} else if((...) == true) {
orElseIfN
The content is negative, null is false
} else if((...) == false) {=