Conditional class final
An annotation that conditionally enables or disables JetLeaf-managed constructs such as Component, Pod, or configuration classes based on one or more declarative Condition evaluators.
The Conditional annotation is a reflective directive that instructs
the JetLeaf framework to include the annotated type or method only if
all specified conditions evaluate to true during pod resolution.
Purpose
In a modular JetLeaf application, certain Components or configuration classes may only be applicable under specific runtime contexts, such as environment, platform, or other application state. Conditional provides a declarative and compile-time safe mechanism to express these contextual dependencies.
Behavior
- Each class in conditions must implement Condition.
- Each condition class must have a
constconstructor so that Conditional can be used as a compile-time constant. - JetLeaf evaluates all conditions in the order they are declared. The
annotated construct is processed only if every condition returns
truevia Condition.matches.
Example
class OnProductionEnvironmentCondition implements Condition {
const OnProductionEnvironmentCondition();
@override
bool matches(Environment env) => env.isProduction();
}
@Conditional([OnProductionEnvironmentCondition()])
class ProductionDataSourceConfig {}
Declaring conditions as const ensures deterministic evaluation and
eliminates runtime instantiation overhead.
Related Components
- Condition: Interface that defines the logical predicate for conditional activation.
- ConditionalContext: JetLeaf context responsible for evaluating conditions and initializing pods.
- Annotations
-
- @Target.new({TargetKind.classType, TargetKind.method})
Constructors
Properties
- annotationType → Type
-
Returns the annotation _type of this annotation.
no setter
-
conditions
→ List<
Condition> -
Condition classes that must match for the annotated type or method
to be processed.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
equalizedProperties(
) → List< Object?> -
Mixin-style contract for value-based equality,
hashCode, andtoString. -
equals(
Object other) → bool -
Checks whether the given object is logically equivalent to this annotation.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String - Returns a string representation of this annotation.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Constants
- FIELD_KEY → const String
-
The key used to store or reference condition information for
a
Conditionalannotation. It matches conditions in Conditional