Generate the Fory schema module class. Args: outer_classname: If set, all type references will be prefixed with this outer class.
(
self, outer_classname: Optional[str] = None
)
| 2137 | return lines |
| 2138 | |
| 2139 | def generate_module_file( |
| 2140 | self, outer_classname: Optional[str] = None |
| 2141 | ) -> GeneratedFile: |
| 2142 | """Generate the Fory schema module class. |
| 2143 | |
| 2144 | Args: |
| 2145 | outer_classname: If set, all type references will be prefixed with this outer class. |
| 2146 | """ |
| 2147 | lines = [] |
| 2148 | java_package = self.get_java_package() |
| 2149 | |
| 2150 | # Determine class name |
| 2151 | class_name = self.get_module_class_name() |
| 2152 | |
| 2153 | # License header |
| 2154 | lines.append(self.get_license_header()) |
| 2155 | lines.append("") |
| 2156 | |
| 2157 | # Package |
| 2158 | if java_package: |
| 2159 | lines.append(f"package {java_package};") |
| 2160 | lines.append("") |
| 2161 | |
| 2162 | # Imports |
| 2163 | lines.append("import org.apache.fory.Fory;") |
| 2164 | lines.append("import org.apache.fory.ThreadSafeFory;") |
| 2165 | lines.append("") |
| 2166 | |
| 2167 | # Class |
| 2168 | lines.append( |
| 2169 | f"public final class {class_name} implements org.apache.fory.ForyModule {{" |
| 2170 | ) |
| 2171 | lines.append( |
| 2172 | f" public static final {class_name} INSTANCE = new {class_name}();" |
| 2173 | ) |
| 2174 | lines.append("") |
| 2175 | lines.append(f" private {class_name}() {{") |
| 2176 | lines.append(" }") |
| 2177 | lines.append("") |
| 2178 | lines.append(" static ThreadSafeFory getFory() {") |
| 2179 | lines.append(" return Holder.FORY;") |
| 2180 | lines.append(" }") |
| 2181 | lines.append("") |
| 2182 | lines.append(" private static ThreadSafeFory createFory() {") |
| 2183 | lines.append( |
| 2184 | " return Fory.builder().withXlang(true).withCompatible(true).withRefTracking(true).withModule(INSTANCE).buildThreadSafeFory();" |
| 2185 | ) |
| 2186 | lines.append(" }") |
| 2187 | lines.append("") |
| 2188 | lines.append(" private static class Holder {") |
| 2189 | lines.append(" private static final ThreadSafeFory FORY = createFory();") |
| 2190 | lines.append(" }") |
| 2191 | lines.append("") |
| 2192 | # When outer_classname is set, all top-level types become inner classes. |
| 2193 | # The outer class is a JVM code-shape owner only; it is not part of the |
| 2194 | # schema namespace used for name registration. |
| 2195 | class_prefix = outer_classname if outer_classname else "" |
| 2196 |
no test coverage detected