Skip to content

Commit 18f9b06

Browse files
author
Stephen Cobbe
committed
Revert "Make serializers public."
This reverts commit 877ed68.
1 parent aa80765 commit 18f9b06

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

generator/java.stoneg.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1652,7 +1652,48 @@ def update_by_reference(data_type, namespace):
16521652

16531653
@staticmethod
16541654
def _resolve_serializer_visibility(api):
1655-
return defaultdict(lambda: Visibility.PUBLIC)
1655+
visibility = defaultdict(lambda: Visibility.NONE)
1656+
1657+
def update(data_type, new_visibility):
1658+
visibility[data_type] = max(visibility[data_type], new_visibility)
1659+
1660+
def update_by_reference(data_type, namespace):
1661+
if data_type.namespace == namespace:
1662+
update(data_type, Visibility.PACKAGE)
1663+
else:
1664+
update(data_type, Visibility.PUBLIC)
1665+
1666+
# Calculate initial visibility state based on routes that use our data types.
1667+
for namespace in api.namespaces.values():
1668+
for route in namespace.routes:
1669+
for data_type in (route.arg_data_type, route.result_data_type, route.error_data_type):
1670+
data_type = get_underlying_type(data_type)
1671+
if is_user_defined_type(data_type):
1672+
update_by_reference(data_type, namespace)
1673+
1674+
# Not iterate repeatedly, cascading the visibility out to other required data types as necessary
1675+
prev_state = None
1676+
cur_state = visibility.copy()
1677+
while prev_state != cur_state:
1678+
for namespace in api.namespaces.values():
1679+
for data_type in namespace.data_types:
1680+
if not visibility[data_type].is_visible:
1681+
continue
1682+
1683+
for field in data_type.all_fields:
1684+
field_data_type = get_underlying_type(field.data_type)
1685+
if is_user_defined_type(field_data_type):
1686+
update_by_reference(field_data_type, namespace)
1687+
1688+
# parents need access to their enumerated subtype serializers
1689+
if is_struct_type(data_type) and data_type.has_enumerated_subtypes():
1690+
for subtype in data_type.get_enumerated_subtypes():
1691+
update_by_reference(subtype.data_type, namespace)
1692+
1693+
prev_state = cur_state
1694+
cur_state = visibility.copy()
1695+
1696+
return visibility
16561697

16571698
@staticmethod
16581699
def get_spec_filename(element):
@@ -3784,6 +3825,7 @@ def generate_struct_serializer(self, data_type):
37843825
generics=[j.java_class(data_type)])
37853826

37863827
w.out('')
3828+
w.javadoc("For internal use only.")
37873829
with w.class_block(j.serializer_class(data_type), visibility=visibility, parent_class=parent_class):
37883830
w.out('public static final %s INSTANCE = new %s();',
37893831
j.serializer_class(data_type),

0 commit comments

Comments
 (0)