DSL_MODE enum

Inheritance

Constructors

DSL_MODE()
const

Values

WRAPPER_CLASS → const DSL_MODE

The default mode. In DSL_MODE.WRAPPER_CLASS the generated $switchXXYY(instances...) functions will return a callable class wrapping the provided instances. This class can then be directly called providing case functions to perform a switch over the instances like so:

// WRAPPER_CLASS is the default mode so you don't need to provide
// any options to @ClassSwitch.
@ClassSwitch(options:ClassSwitchOptions(dslMode:WRAPPER_CLASS))
abstract class Base {}
class A extends Base {}
class B extends Base {}

// The above will generate a function you can use like so:
$switchBase(A())(
  (a) => 1, //
  (b) => 2);

// Explicitly typing .call will autocomplete all of the case functions for
// you in intellij! After which you can delete .call .
$switchBase(A()).call(
  (a) => 1, //
  (b) => 2);

// A cases method is also provided which is exactly the same as .call
// but provides a more readable api and also works nicely with
// autocomplete.
$switchBase(A()).cases(
  (a) => 1, //
  (b) => 2)
SINGLE_METHOD_WITH_INSTANCES_AND_CASES → const DSL_MODE

In DSL_MODE.SINGLE_METHOD_WITH_INSTANCES_AND_CASES the generated $switchXXYY functions take both the instances and the cases in one method call and immediately performs the switch and returns the result.

This provides the best autocomplete experience as intellij can generate all of the instance parameters and case parameters in one go. However the API looks less like a traditional switch statement and so might be seen as less readable or obvious what is happening.

@ClassSwitch(options:ClassSwitchOptions(dslMode:SINGLE_METHOD_WITH_INSTANCES_AND_CASES))
abstract class Base {}
class A extends Base {}
class B extends Base {}

// The above will generate a function you can use like so:
$switchBase(
  A(),
  (a) => 1,
  (b) => 2);
OUTER_METHOD_TAKES_INSTANCES_AND_RETURNS_CASE_FUNCTION → const DSL_MODE

In DSL_MODE.OUTER_METHOD_TAKES_INSTANCES_AND_RETURNS_CASE_FUNCTION the generated $switchXXYY functions take the instances and return an anonymous function which then takes the case functions and performs the switch.

Intellij provides no help with autocompleting switch functions generated in this mode. However it does generate the simplest API out of the modes and perhaps in the future or in other IDE's autocomplete will help out more.

@ClassSwitch(options:ClassSwitchOptions(dslMode:OUTER_METHOD_TAKES_INSTANCES_AND_RETURNS_CASE_FUNCTION))
abstract class Base {}
class A extends Base {}
class B extends Base {}

// The above will generate a function you can use like so:
$switchBase(A())(
  (a) => 1, //
  (b) => 2);

Properties

hashCode int
The hash code for this object.
no setterinherited
index int
A numeric identifier for the enumerated value.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Constants

values → const List<DSL_MODE>
A constant List of the values in this enum, in order of their declaration.