{{! Copyright (c) Meta Platforms, Inc. and its affiliates. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. }}{{! Note: This template works by simultaneously traversing the `type` and `value` maps so that the type of the constant is known. Before including this template, open constant:type and constant:value. On recursive calls, make sure to open the next subtree's :type and :value elements as well. See the section titled 'Map Constants' for an example. }}{{#type:typedef?}}{{! }}{{#type:typedef_type}}{{> DefaultValue}}{{/type:typedef_type}}{{! }}{{/type:typedef?}}{{! }}{{^type:typedef?}}{{! Integer constants }}{{#type:byte?}}(byte){{value:integer_value}}{{/type:byte?}}{{! }}{{#type:i16?}}(short){{value:integer_value}}{{/type:i16?}}{{! }}{{#type:i32?}}{{value:integer_value}}{{/type:i32?}}{{! }}{{#type:i64?}}{{value:integer_value}}L{{/type:i64?}}{{! Boolean constants }}{{#type:bool?}}{{! }}{{#value:nonzero?}}true{{/value:nonzero?}}{{! }}{{^value:nonzero?}}false{{/value:nonzero?}}{{! }}{{/type:bool?}}{{! Floating point constants }}{{#type:double?}}{{! }}{{#value:double?}}(double){{value:double_value}}{{/value:double?}}{{! }}{{#value:integer?}}{{value:integer_value}}.0{{/value:integer?}}{{! }}{{/type:double?}}{{! }}{{#type:float?}}{{! }}{{#value:double?}}(float){{value:double_value}}{{/value:double?}}{{! }}{{#value:integer?}}(float){{value:integer_value}}.0{{/value:integer?}}{{! }}{{/type:float?}}{{! String constants }}{{#type:string?}}{{value:quotedString}}{{/type:string?}}{{! }}{{#type:binary?}}{{#field:hasAdapter?}}io.netty.buffer.Unpooled.wrappedBuffer({{value:quotedString}}.getBytes()){{/field:hasAdapter?}}{{^field:hasAdapter?}}{{value:quotedString}}.getBytes(){{/field:hasAdapter?}}{{/type:binary?}}{{! Map constants }}{{#type:map?}}{{! }}{{#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() {{#value:map_elements}} .put({{#element:key}}{{#type:key_type}}{{#type:hasAdapter?}}__{{type:name}}_Adapter.fromThrift({{/type:hasAdapter?}}{{> DefaultValue}}{{#type:hasAdapter?}}){{/type:hasAdapter?}}{{/type:key_type}}{{/element:key}}, {{! }}{{#element:value}}{{#type:value_type}}{{#type:hasAdapter?}}__{{type:name}}_Adapter.fromThrift({{/type:hasAdapter?}}{{> DefaultValue}}{{#type:hasAdapter?}}){{/type:hasAdapter?}}{{/type:value_type}}{{/element:value}}) {{/value:map_elements}} .build(){{#struct:asBean?}}){{/struct:asBean?}}{{! }}{{/type:map?}}{{! List constants }}{{#type:list?}}{{! }}{{#struct:asBean?}}com.google.common.collect.Lists.newArrayList({{/struct:asBean?}}ImmutableList.<{{#type:list_elem_type}}{{> BoxedType}}{{/type:list_elem_type}}>builder() {{#value:list_elements}} .add({{#type:list_elem_type}}{{#type:hasAdapter?}}__{{type:name}}_Adapter.fromThrift({{/type:hasAdapter?}}{{> DefaultValue}}{{#type:hasAdapter?}}){{/type:hasAdapter?}}{{/type:list_elem_type}}) {{/value:list_elements}} .build(){{#struct:asBean?}}){{/struct:asBean?}}{{! }}{{/type:list?}}{{! Set constants }}{{#type:set?}}{{! }}{{#struct:asBean?}}com.google.common.collect.Sets.newHashSet({{/struct:asBean?}}ImmutableSet.<{{#type:set_elem_type}}{{> BoxedType}}{{/type:set_elem_type}}>builder() {{#value:list_elements}} .add({{#type:set_elem_type}}{{#type:hasAdapter?}}__{{type:name}}_Adapter.fromThrift({{/type:hasAdapter?}}{{> DefaultValue}}{{#type:hasAdapter?}}){{/type:hasAdapter?}}{{/type:set_elem_type}}) {{/value:list_elements}} .build(){{#struct:asBean?}}){{/struct:asBean?}}{{! }}{{/type:set?}}{{! Enum Constants }}{{#type:enum?}}{{> BoxedType}}.{{value:javaEnumValueName}}{{/type:enum?}}{{! Struct Constants }}{{#type:struct?}}{{! }}{{#type:struct}}{{! }}{{#value:referenceable?}}{{! }}{{#value:owning_const}}{{! }}{{#constant:program}}{{! }}{{program:javaPackage}}.Constants.{{constant:javaCapitalName}}{{! }}{{/constant:program}}{{! }}{{/value:owning_const}}{{! }}{{/value:referenceable?}}{{! }}{{^value:referenceable?}}{{! }}{{#struct:plain?}}{{> ConstantStruct}}{{/struct:plain?}}{{! }}{{#struct:union?}}{{> ConstantUnion}}{{/struct:union?}}{{! }}{{/value:referenceable?}}{{! }}{{/type:struct}}{{! }}{{/type:struct?}}{{! }}{{/type:typedef?}}