nimbus_fml/backends/kotlin/gen_structs/
feature.rs
1use std::fmt::Display;
6
7use askama::Template;
8
9use super::filters;
10use super::object::object_literal;
11use crate::{
12 backends::{CodeDeclaration, CodeOracle, LiteralRenderer, TypeIdentifier},
13 intermediate_representation::{FeatureDef, FeatureManifest, Literal},
14};
15
16#[derive(Template)]
17#[template(syntax = "kt", escape = "none", path = "FeatureTemplate.kt")]
18pub(crate) struct FeatureCodeDeclaration {
19 inner: FeatureDef,
20 fm: FeatureManifest,
21}
22
23impl FeatureCodeDeclaration {
24 pub fn new(fm: &FeatureManifest, inner: &FeatureDef) -> Self {
25 Self {
26 inner: inner.clone(),
27 fm: fm.clone(),
28 }
29 }
30 pub fn inner(&self) -> &FeatureDef {
31 &self.inner
32 }
33}
34
35impl CodeDeclaration for FeatureCodeDeclaration {
36 fn definition_code(&self, _oracle: &dyn CodeOracle) -> Option<String> {
37 Some(self.render().unwrap())
38 }
39
40 fn imports(&self, _oracle: &dyn CodeOracle) -> Option<Vec<String>> {
41 Some(vec![
42 "org.mozilla.experiments.nimbus.internal.FeatureHolder".to_string(),
43 "org.mozilla.experiments.nimbus.internal.FMLFeatureInterface".to_string(),
44 "org.mozilla.experiments.nimbus.NullVariables".to_string(),
45 ])
46 }
47}
48
49impl LiteralRenderer for FeatureCodeDeclaration {
50 fn literal(
51 &self,
52 oracle: &dyn CodeOracle,
53 typ: &TypeIdentifier,
54 value: &Literal,
55 ctx: &dyn Display,
56 ) -> String {
57 object_literal(&self.fm, ctx, &self, oracle, typ, value)
58 }
59}