Skip to content

Commit f738c9f

Browse files
author
Karl Rieb
committed
Don't generate unused/orphaned data types caused by route filtering.
Fixes T98053
1 parent 8430d26 commit f738c9f

1 file changed

Lines changed: 20 additions & 9 deletions

File tree

generator/java.stoneg.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2121,36 +2121,47 @@ def _lookup_data_type(self, namespace, data_type, context):
21212121
if namespace: assert data_type, "Cannot specify namespace name without data_type name"
21222122

21232123
stone_namespace = self._lookup_stone_namespace(namespace, context)
2124+
data_type_ref = None
21242125

21252126
if stone_namespace and data_type:
21262127
stone_data_type = stone_namespace.data_type_by_name.get(data_type)
21272128
if stone_data_type:
2128-
return DataTypeWrapper(self._ctx, stone_data_type)
2129+
data_type_ref = DataTypeWrapper(self._ctx, stone_data_type)
21292130
elif context and not data_type:
21302131
if isinstance(context, FieldWrapper):
21312132
# we might be within a field, which has a containing data type
2132-
return context.containing_data_type
2133+
data_type_ref = context.containing_data_type
21332134
elif isinstance(context, DataTypeWrapper):
2134-
return context
2135+
data_type_ref = context
21352136

2136-
return None
2137+
# Do not return references to orphaned types we intend to remove
2138+
if data_type_ref and is_data_type_referenced(data_type_ref):
2139+
return data_type_ref
2140+
else:
2141+
return None
21372142

21382143
def _lookup_field(self, namespace, data_type, field, context):
21392144
assert isinstance(field, str) or field is None, repr(data_type)
21402145
if data_type: assert field, "Cannot specify data_type name without field name"
21412146

21422147
data_type = self._lookup_data_type(namespace, data_type, context)
2148+
field_ref = None
21432149

21442150
if data_type and field:
21452151
for data_type_field in data_type.all_fields:
21462152
if data_type_field.stone_name == field:
2147-
return data_type_field
2153+
field_ref = data_type_field
21482154
elif context and not field:
21492155
if isinstance(context, FieldWrapper):
2150-
return context
2156+
field_ref = context
21512157

21522158
# Field is the lowest you can go. No way to use context to derive field
2153-
return None
2159+
2160+
# Do not return references to orphaned types we intend to remove
2161+
if field_ref and is_data_type_referenced(field_ref.containing_data_type):
2162+
return field_ref
2163+
else:
2164+
return None
21542165

21552166
def _javadoc_route_ref(self, route, builder=False):
21562167
assert isinstance(route, RouteWrapper), repr(route)
@@ -2952,8 +2963,8 @@ def generate_data_type(self, data_type):
29522963

29532964
# some data types get orphaned by route filtering
29542965
# TODO(krieb): enable this when the bugs are worked out
2955-
#if not is_data_type_referenced(data_type):
2956-
# return
2966+
if not is_data_type_referenced(data_type):
2967+
return
29572968

29582969
with self.new_file(data_type):
29592970
self.importer.add_imports_for_data_type(data_type)

0 commit comments

Comments
 (0)