Variable
The bridge between ParameterSpec and PropertySpec.
The goal of Variable
ParameterSpec and PropertySpec are very similar:
ParameterSpec
PropertySpec
name
name
modifiers
modifiers
type
type
defaultValue
initializer
null
mutable: Boolean
Although they have more fields, these are the ones KotlinPoetDSL supports before V0.2.
Because they are this similar it would make sense to pass around a type that has the commonalities of both the classes. In KotlinPoetDSL, this class is called Variable.
Constructions
There are 3 function-names: of
, valOf
, varOf
. These can all be invoked the same way. Therefor I show below only using valOf
.
for the vararg:
Interoperability
Slightly interoperable, but will be improved in V0.2
Creating Variables
Using Variable
In V0.1 the variables can't be used. In V0.2, the variables can be used interchangeable with ParamSpec and PropertySpec.
Getting KotlinPoetTypes
The spec passed to the constructor will be returned, so with it's unsuported fields.
On the other hand, annotations are not yet support by KotlinPoetDSL, so when you go from one type to another (paramSpec.toVariable().toPropertySpec()
), the annotations are not preserved.
Last updated