Interface KotlinCodeGenerationStrategy
-
- All Implemented Interfaces:
-
io.toolisticon.kotlin.generation.spi.KotlinCodeGenerationSpi
,java.util.function.BiPredicate
,kotlin.Comparable
public interface KotlinCodeGenerationStrategy<CONTEXT extends KotlinCodeGenerationContext<CONTEXT>, INPUT extends Object, SPEC extends Object> implements KotlinCodeGenerationSpi<CONTEXT, INPUT>
Root marker interface for all strategies.
Strategies are building plans for a spec. They return a kotlin poet spec that is generated by the logic defined in the strategy using an input (the concrete data the spec is generated for) and a context (the overall generator state containing additional data and also the registry to trigger other strategies and processors).
Hint: for implementing a concrete strategy, use the io.toolisticon.kotlin.generation.spi.strategy.KotlinCodeGenerationStrategyBase.
-
-
Method Summary
Modifier and Type Method Description abstract SPEC
invoke(CONTEXT context, INPUT input)
Implements the actual strategy logic to generate a spec from a given input, using context information. Boolean
test(CONTEXT context, Object input)
If true
, the spi instance is executed, else ignored.SPEC
execute(CONTEXT context, INPUT input)
Checks if this strategy should be applied (using test) and then runs invoke. abstract KClass<CONTEXT>
getContextType()
The type of the generic CONTEXT, used to filter relevant instances. abstract KClass<INPUT>
getInputType()
The type of the generic INPUT, used to filter relevant instances. abstract String
getName()
The name that is used when the implementing class is listed in a META-INF/services/
file.abstract Integer
getOrder()
Order is used to sort spi instances. abstract KClass<SPEC>
getSpecType()
The type of the created SPEC, used to filter relevant instances for execution. -
Methods inherited from class io.toolisticon.kotlin.generation.spi.KotlinCodeGenerationSpi
compareTo
-
Methods inherited from class java.util.function.BiPredicate
and, negate, or
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Method Detail
-
invoke
abstract SPEC invoke(CONTEXT context, INPUT input)
Implements the actual strategy logic to generate a spec from a given input, using context information.
- Parameters:
context
- the context we are operating ininput
- the concrete work item- Returns:
the generated spec
-
test
Boolean test(CONTEXT context, Object input)
If
true
, the spi instance is executed, else ignored.- Parameters:
context
- the context we are operating ininput
- the concrete work item, for the check this is unbound and nullable, so we can check against calling with unsupported types.- Returns:
true
when the spi shoud be applied.
-
execute
SPEC execute(CONTEXT context, INPUT input)
- Parameters:
context
- the context we are operating ininput
- the concrete work item- Returns:
generated spec (or
null
if test wasfalse
).
-
getContextType
abstract KClass<CONTEXT> getContextType()
The type of the generic CONTEXT, used to filter relevant instances.
-
getInputType
abstract KClass<INPUT> getInputType()
The type of the generic INPUT, used to filter relevant instances.
-
getName
abstract String getName()
The name that is used when the implementing class is listed in a
META-INF/services/
file. Attention: SPI uses java naming, so inner classes have to be separated by$
.
-
getSpecType
abstract KClass<SPEC> getSpecType()
The type of the created SPEC, used to filter relevant instances for execution.
-
-
-
-