gh-pages / com.nextfaze.devfun.function / FunctionTransformer

FunctionTransformer

interface FunctionTransformer (source)

Function transformers filter and/or convert a FunctionDefinition to FunctionItem.

Item lifecycle:

They can be used to:

If a transformer chooses to accept an item, it still has the choice of ignoring it by returning null from apply. Anything but null will remove the item from further processing. Thus returning an empty list will effectively filter the item (as done in RequiresApiTransformer).

Standard Transformers

Currently there are four transformers, which are checked in order of declaration (from Transformers.kt);

internal val TRANSFORMERS = listOf(
        RequiresApiTransformer::class,
        ContextTransformer::class,
        CustomProviderTransformer::class,
        SingleFunctionTransformer::class
)

RequiresApiTransformer

Filters items that require an API greater than that available - as declared by FunctionDefinition.requiresApi.

ContextTransformer

Filters (must be active) and tweaks (overrides the category) items that are relevant to the current screen.

If an item is defined in an Activity or Fragment, and that Activity is active or the Fragment is added (to the current Activity), then the result from the item’s original FunctionDefinition.transformer is wrapped with a ContextFunctionItem that overrides the category with a ContextCategory. This sets the category to “Context”, and its group to the class where the function is defined - e.g. “Main Activity” or “Navigation Fragment”, etc.

Items that aren’t on the current screen are filtered out (by returning an empty list - stopping further processing).

CustomProviderTransformer

Delegates to a user declared transformer - as declared by FunctionDefinition.transformer.

SingleFunctionTransformer

Final/default transformer that effectively just wraps a FunctionDefinition in a FunctionItem using SimpleFunctionItem.

Functions

Name Summary
accept open fun accept(functionDefinition: FunctionDefinition): Boolean
Should this transformer accept this item for transforming.
apply abstract fun apply(functionDefinition: FunctionDefinition, categoryDefinition: CategoryDefinition): Collection<FunctionItem>?
Transforms a FunctionDefinition to one or more FunctionItem.

Inheritors

Name Summary
ArgumentsTransformer interface ArgumentsTransformer : FunctionTransformer
A function transformer that tells DevFun how to generate functions for annotation-defined arguments.
PropertyTransformer interface PropertyTransformer : FunctionTransformer
A function transformer that tells DevFun how to render Kotlin properties.
SingleFunctionTransformer object SingleFunctionTransformer : FunctionTransformer
The default transformer. Effectively just wraps the FunctionDefinition to a FunctionItem (1:1).