gh-pages / com.nextfaze.devfun.function / DeveloperArguments / <init>

<init>

DeveloperArguments(name: String = "%0", args: Array<Args>, group: String = "%FUN_SN%", category: DeveloperCategory = DeveloperCategory(), requiresApi: Int = 0, transformer: KClass<out FunctionTransformer> = ArgumentsTransformer::class)

An alternative to DeveloperFunction that allows you to provide arguments for multiple invocations.

Note: This annotation is *SOURCE retained - its contents will not be kept in your binary!*

For an example usage, see demo AuthenticateFragment.signInAs

Args Format

Each element in the args will be converted to the appropriate type from the string provided based on the function’s parameter types. i.e. “1.0f” -> Float

@DeveloperArguments(
    args = [Args(["A string", "1.0f"])]
)
fun myFunction(str: String, float: Float) = Unit

If the second parameter was a string then it would remain a string "1.0f" etc.

Supported Types

At present only simple types and strings are supported simply because I haven’t used anything more - you’re welcome to create an issue for other types and it’ll likely be supported.

If a type is not supported (or an arg is out of bounds) then DevFun will attempt to inject it as per normal DevFun behaviour.

Arg-index name & group

You can use %d to reference your args array.

i.e. name = "%2" -> name = args[n][2]

e.g.

@DeveloperArguments(
    name = "The string arg is: '%0'"
    args = [
        Args(["Hello", "1.0f"]), // name = "The string arg is: 'Hello'"
        Args(["World", "-1.0f"]) // name = "The string arg is: 'World'"
    ]
)
fun myFunction(str: String, float: Float) = Unit

Example Usage

Taken from demo AuthenticateFragment.signInAs

@DeveloperArguments(
    args = [
        Args(["foo@example.com", "hello", "Normal"]),
        Args(["bar@example.com", "world", "Normal"]),
        Args(["mary@mailinator.com", "ContainDateNeck76", "Normal"]),
        Args(["eli@example.com", "EveningVermontNeck29", "Normal"]),
        Args(["trevor@example.com", "OftenJumpCost02", "Normal"]),
        Args(["rude.user@example.com", "TakePlayThought95", "Restricted"]),
        Args(["block.stars@mailinator.com", "DeviceSeedsSeason16", "Restricted"]),
        Args(["vulgar@user.com", "ChinaMisterGeneral11", "Banned"]),
        Args(["thirteen@years.old", "my.password", "Underage"]),
        Args(["twelve@years.old", "password", "Underage"]),
        Args(["bad.password.1@example.com", "D3;d<HF-", "Invalid Password"]),
        Args(["bad.password.2@example.com", "r2Z@fMhA", "Invalid Password"]),
        Args(["unknown@example.com", "RV[(x43@", "Unknown User"])
    ],
    group = "Authenticate as %2"
)
private fun signInAs(email: String, password: String) {
    emailEditText.setText(email)
    passwordEditText.setText(password)
    attemptLogin()
}

Context Menu:

Sensitive Information

A reminder that DeveloperArguments is SOURCE retained - it will not be present in your compiled files.

An alternative to having this annotation at the use-site could be to have the declaration in your Debug sources an invoke it from there.

object MyDebugUtils {
    @DeveloperArguments(...)
    fun signInAs(...) {
    }
}

An alternative would be to have signInAs be called from the Debug source tree or by some other means

Experimental Feature

This annotation is experimental.

Any and all input is welcome!

Parameters

name - The function’s name (equivalent to DeveloperFunction.value). Defaults to the first element in each args item %0. A null or blank value falls back FunctionItem.name.

args - A list of Args, with each item an alternative invocation. Behaviour is as FunctionItem.args.

group - A grouping for the functions - defaults to the function’s name. A null or blank value falls back to FunctionItem.group.

requiresApi - This is equivalent to DeveloperFunction.requiresApi.

transformer - This is equivalent to DeveloperFunction.transformer - do not change this unless you know what you’re doing!

See Also

ArgumentsTransformer

DeveloperFunction