1{{!
2
3  Copyright (c) Facebook, Inc. and its affiliates.
4
5  Licensed under the Apache License, Version 2.0 (the "License");
6  you may not use this file except in compliance with the License.
7  You may obtain a copy of the License at
8
9      http://www.apache.org/licenses/LICENSE-2.0
10
11  Unless required by applicable law or agreed to in writing, software
12  distributed under the License is distributed on an "AS IS" BASIS,
13  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  See the License for the specific language governing permissions and
15  limitations under the License.
16
17}}{{!
18
19  Note:
20
21  This template works by simultaneously traversing the `type` and `value` maps
22  so that the type of the constant is known. Before including this template,
23  open constant:type and constant:value. On recursive calls, make sure to open
24  the next subtree's :type and :value elements as well. See the section titled
25  'Map Constants' for an example.
26
27
28}}{{#type:typedef?}}{{!
29}}{{#type:typedef_type}}{{> DefaultValue}}{{/type:typedef_type}}{{!
30}}{{/type:typedef?}}{{!
31}}{{^type:typedef?}}{{!
32    Integer constants
33  }}{{#type:byte?}}(byte){{value:integer_value}}{{/type:byte?}}{{!
34  }}{{#type:i16?}}(short){{value:integer_value}}{{/type:i16?}}{{!
35  }}{{#type:i32?}}{{value:integer_value}}{{/type:i32?}}{{!
36  }}{{#type:i64?}}{{value:integer_value}}L{{/type:i64?}}{{!
37
38    Boolean constants
39  }}{{#type:bool?}}{{!
40    }}{{#value:nonzero?}}true{{/value:nonzero?}}{{!
41    }}{{^value:nonzero?}}false{{/value:nonzero?}}{{!
42  }}{{/type:bool?}}{{!
43
44    Floating point constants
45  }}{{#type:double?}}{{!
46  }}{{#value:double?}}(double){{value:double_value}}{{/value:double?}}{{!
47    }}{{#value:integer?}}{{value:integer_value}}.0{{/value:integer?}}{{!
48  }}{{/type:double?}}{{!
49  }}{{#type:float?}}{{!
50  }}{{#value:double?}}(float){{value:double_value}}{{/value:double?}}{{!
51  }}{{#value:integer?}}(float){{value:integer_value}}.0{{/value:integer?}}{{!
52  }}{{/type:float?}}{{!
53
54    String constants
55  }}{{#type:string?}}{{value:quotedString}}{{/type:string?}}{{!
56  }}{{#type:binary?}}{{value:quotedString}}.getBytes(){{/type:binary?}}{{!
57
58    Map constants
59  }}{{#type:map?}}{{!
60
61      }}{{#struct:asBean?}}com.google.common.collect.Maps.newHashMap({{/struct:asBean?}}ImmutableMap.<{{#type:key_type}}{{> BoxedType}}{{/type:key_type}}, {{#type:value_type}}{{> BoxedType}}{{/type:value_type}}>builder()
62        {{#value:map_elements}}
63        .put({{#element:key}}{{#type:key_type}}{{> DefaultValue}}{{/type:key_type}}{{/element:key}}, {{!
64        }}{{#element:value}}{{#type:value_type}}{{> DefaultValue}}{{/type:value_type}}{{/element:value}})
65        {{/value:map_elements}}
66        .build(){{#struct:asBean?}}){{/struct:asBean?}}{{!
67
68  }}{{/type:map?}}{{!
69
70    List constants
71  }}{{#type:list?}}{{!
72
73      }}{{#struct:asBean?}}com.google.common.collect.Lists.newArrayList({{/struct:asBean?}}ImmutableList.<{{#type:list_elem_type}}{{> BoxedType}}{{/type:list_elem_type}}>builder()
74        {{#value:list_elements}}
75        .add({{#type:list_elem_type}}{{> DefaultValue}}{{/type:list_elem_type}})
76        {{/value:list_elements}}
77        .build(){{#struct:asBean?}}){{/struct:asBean?}}{{!
78
79  }}{{/type:list?}}{{!
80
81    Set constants
82  }}{{#type:set?}}{{!
83
84      }}{{#struct:asBean?}}com.google.common.collect.Sets.newHashSet({{/struct:asBean?}}ImmutableSet.<{{#type:set_elem_type}}{{> BoxedType}}{{/type:set_elem_type}}>builder()
85        {{#value:list_elements}}
86        .add({{#type:set_elem_type}}{{> DefaultValue}}{{/type:set_elem_type}})
87        {{/value:list_elements}}
88        .build(){{#struct:asBean?}}){{/struct:asBean?}}{{!
89
90  }}{{/type:set?}}{{!
91
92    Enum Constants
93  }}{{#type:enum?}}{{> BoxedType}}.{{value:javaEnumValueName}}{{/type:enum?}}{{!
94
95    Struct Constants
96  }}{{#type:struct?}}{{!
97    }}{{#type:struct}}{{!
98      }}{{#value:referenceable?}}{{!
99        }}{{#value:owning_const}}{{!
100          }}{{#constant:program}}{{!
101            }}{{program:javaPackage}}.Constants.{{constant:javaCapitalName}}{{!
102          }}{{/constant:program}}{{!
103        }}{{/value:owning_const}}{{!
104      }}{{/value:referenceable?}}{{!
105      }}{{^value:referenceable?}}{{!
106        }}{{#struct:plain?}}{{> ConstantStruct}}{{/struct:plain?}}{{!
107        }}{{#struct:union?}}{{> ConstantUnion}}{{/struct:union?}}{{!
108      }}{{/value:referenceable?}}{{!
109    }}{{/type:struct}}{{!
110  }}{{/type:struct?}}{{!
111}}{{/type:typedef?}}
112