aas-core-codegen 0.0.16__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- aas_core_codegen/__init__.py +6 -0
- aas_core_codegen/__main__.py +8 -0
- aas_core_codegen/common.py +500 -0
- aas_core_codegen/cpp/__init__.py +1 -0
- aas_core_codegen/cpp/aas_common/__init__.py +6 -0
- aas_core_codegen/cpp/aas_common/_generate.py +713 -0
- aas_core_codegen/cpp/common.py +681 -0
- aas_core_codegen/cpp/constants/__init__.py +6 -0
- aas_core_codegen/cpp/constants/_generate.py +568 -0
- aas_core_codegen/cpp/description.py +654 -0
- aas_core_codegen/cpp/enhancing/__init__.py +4 -0
- aas_core_codegen/cpp/enhancing/_generate.py +993 -0
- aas_core_codegen/cpp/iteration/__init__.py +6 -0
- aas_core_codegen/cpp/iteration/_generate.py +2332 -0
- aas_core_codegen/cpp/jsonization/__init__.py +6 -0
- aas_core_codegen/cpp/jsonization/_generate.py +2619 -0
- aas_core_codegen/cpp/main.py +694 -0
- aas_core_codegen/cpp/naming.py +170 -0
- aas_core_codegen/cpp/optionaling.py +557 -0
- aas_core_codegen/cpp/pattern/__init__.py +6 -0
- aas_core_codegen/cpp/pattern/_generate.py +508 -0
- aas_core_codegen/cpp/revm/__init__.py +6 -0
- aas_core_codegen/cpp/revm/_generate.py +1149 -0
- aas_core_codegen/cpp/stringification/__init__.py +5 -0
- aas_core_codegen/cpp/stringification/_generate.py +955 -0
- aas_core_codegen/cpp/structure/__init__.py +7 -0
- aas_core_codegen/cpp/structure/_generate.py +1503 -0
- aas_core_codegen/cpp/transpilation.py +1383 -0
- aas_core_codegen/cpp/unrolling.py +159 -0
- aas_core_codegen/cpp/verification/__init__.py +6 -0
- aas_core_codegen/cpp/verification/_generate.py +3073 -0
- aas_core_codegen/cpp/visitation/__init__.py +6 -0
- aas_core_codegen/cpp/visitation/_generate.py +521 -0
- aas_core_codegen/cpp/wstringification/__init__.py +5 -0
- aas_core_codegen/cpp/wstringification/_generate.py +586 -0
- aas_core_codegen/cpp/xmlization/__init__.py +6 -0
- aas_core_codegen/cpp/xmlization/_generate.py +5373 -0
- aas_core_codegen/cpp/yielding.py +201 -0
- aas_core_codegen/csharp/__init__.py +1 -0
- aas_core_codegen/csharp/common.py +224 -0
- aas_core_codegen/csharp/constants/__init__.py +5 -0
- aas_core_codegen/csharp/constants/_generate.py +409 -0
- aas_core_codegen/csharp/copying/__init__.py +4 -0
- aas_core_codegen/csharp/copying/_generate.py +498 -0
- aas_core_codegen/csharp/description.py +1103 -0
- aas_core_codegen/csharp/enhancing/__init__.py +4 -0
- aas_core_codegen/csharp/enhancing/_generate.py +667 -0
- aas_core_codegen/csharp/jsonization/__init__.py +4 -0
- aas_core_codegen/csharp/jsonization/_generate.py +1630 -0
- aas_core_codegen/csharp/main.py +421 -0
- aas_core_codegen/csharp/naming.py +157 -0
- aas_core_codegen/csharp/reporting/__init__.py +4 -0
- aas_core_codegen/csharp/reporting/_generate.py +266 -0
- aas_core_codegen/csharp/stringification/__init__.py +4 -0
- aas_core_codegen/csharp/stringification/_generate.py +243 -0
- aas_core_codegen/csharp/structure/__init__.py +6 -0
- aas_core_codegen/csharp/structure/_generate.py +1341 -0
- aas_core_codegen/csharp/transpilation.py +990 -0
- aas_core_codegen/csharp/unrolling.py +211 -0
- aas_core_codegen/csharp/verification/__init__.py +6 -0
- aas_core_codegen/csharp/verification/_generate.py +1457 -0
- aas_core_codegen/csharp/visitation/__init__.py +5 -0
- aas_core_codegen/csharp/visitation/_generate.py +579 -0
- aas_core_codegen/csharp/xmlization/__init__.py +4 -0
- aas_core_codegen/csharp/xmlization/_generate.py +1980 -0
- aas_core_codegen/golang/__init__.py +1 -0
- aas_core_codegen/golang/aas_common/__init__.py +4 -0
- aas_core_codegen/golang/aas_common/_generate.py +152 -0
- aas_core_codegen/golang/common.py +303 -0
- aas_core_codegen/golang/constants/__init__.py +5 -0
- aas_core_codegen/golang/constants/_generate.py +339 -0
- aas_core_codegen/golang/description.py +501 -0
- aas_core_codegen/golang/enhancing/__init__.py +4 -0
- aas_core_codegen/golang/enhancing/_generate.py +527 -0
- aas_core_codegen/golang/jsonization/__init__.py +4 -0
- aas_core_codegen/golang/jsonization/_generate.py +1740 -0
- aas_core_codegen/golang/main.py +368 -0
- aas_core_codegen/golang/naming.py +412 -0
- aas_core_codegen/golang/pointering.py +631 -0
- aas_core_codegen/golang/reporting/__init__.py +4 -0
- aas_core_codegen/golang/reporting/_generate.py +218 -0
- aas_core_codegen/golang/stringification/__init__.py +4 -0
- aas_core_codegen/golang/stringification/_generate.py +394 -0
- aas_core_codegen/golang/structure/__init__.py +6 -0
- aas_core_codegen/golang/structure/_generate.py +1493 -0
- aas_core_codegen/golang/transpilation.py +1191 -0
- aas_core_codegen/golang/unrolling.py +159 -0
- aas_core_codegen/golang/verification/__init__.py +6 -0
- aas_core_codegen/golang/verification/_generate.py +1513 -0
- aas_core_codegen/golang/xmlization/__init__.py +4 -0
- aas_core_codegen/golang/xmlization/_generate.py +2507 -0
- aas_core_codegen/infer_for_schema/__init__.py +21 -0
- aas_core_codegen/infer_for_schema/_inline.py +693 -0
- aas_core_codegen/infer_for_schema/_len.py +527 -0
- aas_core_codegen/infer_for_schema/_pattern.py +311 -0
- aas_core_codegen/infer_for_schema/_set.py +394 -0
- aas_core_codegen/infer_for_schema/_stringify.py +201 -0
- aas_core_codegen/infer_for_schema/_types.py +135 -0
- aas_core_codegen/infer_for_schema/match.py +122 -0
- aas_core_codegen/intermediate/__init__.py +78 -0
- aas_core_codegen/intermediate/_hierarchy.py +397 -0
- aas_core_codegen/intermediate/_stringify.py +989 -0
- aas_core_codegen/intermediate/_translate.py +5128 -0
- aas_core_codegen/intermediate/_types.py +2901 -0
- aas_core_codegen/intermediate/construction.py +750 -0
- aas_core_codegen/intermediate/doc.py +344 -0
- aas_core_codegen/intermediate/pattern_verification.py +428 -0
- aas_core_codegen/intermediate/revm.py +985 -0
- aas_core_codegen/intermediate/type_inference.py +2266 -0
- aas_core_codegen/java/__init__.py +1 -0
- aas_core_codegen/java/common.py +197 -0
- aas_core_codegen/java/constants/__init__.py +5 -0
- aas_core_codegen/java/constants/_generate.py +334 -0
- aas_core_codegen/java/copying/__init__.py +4 -0
- aas_core_codegen/java/copying/_generate.py +502 -0
- aas_core_codegen/java/description.py +774 -0
- aas_core_codegen/java/enhancing/__init__.py +4 -0
- aas_core_codegen/java/enhancing/_generate.py +820 -0
- aas_core_codegen/java/generation/__init__.py +5 -0
- aas_core_codegen/java/generation/_generate.py +285 -0
- aas_core_codegen/java/jsonization/__init__.py +4 -0
- aas_core_codegen/java/jsonization/_generate.py +1472 -0
- aas_core_codegen/java/main.py +438 -0
- aas_core_codegen/java/naming.py +187 -0
- aas_core_codegen/java/optional.py +514 -0
- aas_core_codegen/java/reporting/__init__.py +4 -0
- aas_core_codegen/java/reporting/_generate.py +248 -0
- aas_core_codegen/java/stringification/__init__.py +4 -0
- aas_core_codegen/java/stringification/_generate.py +212 -0
- aas_core_codegen/java/structure/__init__.py +6 -0
- aas_core_codegen/java/structure/_generate.py +1767 -0
- aas_core_codegen/java/transpilation.py +1111 -0
- aas_core_codegen/java/verification/__init__.py +6 -0
- aas_core_codegen/java/verification/_generate.py +1536 -0
- aas_core_codegen/java/visitation/__init__.py +5 -0
- aas_core_codegen/java/visitation/_generate.py +689 -0
- aas_core_codegen/java/xmlization/__init__.py +4 -0
- aas_core_codegen/java/xmlization/_generate.py +2274 -0
- aas_core_codegen/jsonld/__init__.py +1 -0
- aas_core_codegen/jsonld/main.py +455 -0
- aas_core_codegen/jsonschema/__init__.py +1 -0
- aas_core_codegen/jsonschema/main.py +982 -0
- aas_core_codegen/main.py +245 -0
- aas_core_codegen/naming.py +133 -0
- aas_core_codegen/opcua/__init__.py +1 -0
- aas_core_codegen/opcua/main.py +1525 -0
- aas_core_codegen/opcua/naming.py +126 -0
- aas_core_codegen/parse/__init__.py +46 -0
- aas_core_codegen/parse/_rules.py +796 -0
- aas_core_codegen/parse/_stringify.py +532 -0
- aas_core_codegen/parse/_translate.py +3940 -0
- aas_core_codegen/parse/_types.py +973 -0
- aas_core_codegen/parse/retree/__init__.py +46 -0
- aas_core_codegen/parse/retree/_fix.py +434 -0
- aas_core_codegen/parse/retree/_parse.py +1143 -0
- aas_core_codegen/parse/retree/_render.py +298 -0
- aas_core_codegen/parse/retree/_stringify.py +199 -0
- aas_core_codegen/parse/retree/_types.py +362 -0
- aas_core_codegen/parse/retree/_visitor.py +70 -0
- aas_core_codegen/parse/tree.py +1303 -0
- aas_core_codegen/protobuf/__init__.py +1 -0
- aas_core_codegen/protobuf/common.py +225 -0
- aas_core_codegen/protobuf/description.py +1102 -0
- aas_core_codegen/protobuf/main.py +115 -0
- aas_core_codegen/protobuf/naming.py +143 -0
- aas_core_codegen/protobuf/structure/__init__.py +6 -0
- aas_core_codegen/protobuf/structure/_generate.py +502 -0
- aas_core_codegen/py.typed +1 -0
- aas_core_codegen/python/__init__.py +1 -0
- aas_core_codegen/python/aas_common/__init__.py +4 -0
- aas_core_codegen/python/aas_common/_generate.py +63 -0
- aas_core_codegen/python/common.py +406 -0
- aas_core_codegen/python/constants/__init__.py +5 -0
- aas_core_codegen/python/constants/_generate.py +377 -0
- aas_core_codegen/python/description.py +508 -0
- aas_core_codegen/python/jsonization/__init__.py +4 -0
- aas_core_codegen/python/jsonization/_generate.py +1391 -0
- aas_core_codegen/python/main.py +323 -0
- aas_core_codegen/python/naming.py +255 -0
- aas_core_codegen/python/stringification/__init__.py +4 -0
- aas_core_codegen/python/stringification/_generate.py +129 -0
- aas_core_codegen/python/structure/__init__.py +6 -0
- aas_core_codegen/python/structure/_generate.py +1801 -0
- aas_core_codegen/python/transpilation.py +958 -0
- aas_core_codegen/python/unrolling.py +156 -0
- aas_core_codegen/python/verification/__init__.py +6 -0
- aas_core_codegen/python/verification/_generate.py +1471 -0
- aas_core_codegen/python/xmlization/__init__.py +4 -0
- aas_core_codegen/python/xmlization/_generate.py +3003 -0
- aas_core_codegen/python_protobuf/__init__.py +1 -0
- aas_core_codegen/python_protobuf/main.py +1424 -0
- aas_core_codegen/python_protobuf/naming.py +85 -0
- aas_core_codegen/rdf_shacl/__init__.py +1 -0
- aas_core_codegen/rdf_shacl/_description.py +351 -0
- aas_core_codegen/rdf_shacl/common.py +206 -0
- aas_core_codegen/rdf_shacl/main.py +114 -0
- aas_core_codegen/rdf_shacl/naming.py +145 -0
- aas_core_codegen/rdf_shacl/rdf.py +435 -0
- aas_core_codegen/rdf_shacl/shacl.py +453 -0
- aas_core_codegen/run.py +124 -0
- aas_core_codegen/smoke/__init__.py +1 -0
- aas_core_codegen/smoke/main.py +219 -0
- aas_core_codegen/specific_implementations.py +72 -0
- aas_core_codegen/stringify.py +333 -0
- aas_core_codegen/typescript/__init__.py +1 -0
- aas_core_codegen/typescript/aas_common/__init__.py +4 -0
- aas_core_codegen/typescript/aas_common/_generate.py +472 -0
- aas_core_codegen/typescript/common.py +340 -0
- aas_core_codegen/typescript/constants/__init__.py +5 -0
- aas_core_codegen/typescript/constants/_generate.py +347 -0
- aas_core_codegen/typescript/description.py +530 -0
- aas_core_codegen/typescript/jsonization/__init__.py +4 -0
- aas_core_codegen/typescript/jsonization/_generate.py +1510 -0
- aas_core_codegen/typescript/main.py +258 -0
- aas_core_codegen/typescript/naming.py +189 -0
- aas_core_codegen/typescript/stringification/__init__.py +4 -0
- aas_core_codegen/typescript/stringification/_generate.py +367 -0
- aas_core_codegen/typescript/structure/__init__.py +6 -0
- aas_core_codegen/typescript/structure/_generate.py +2500 -0
- aas_core_codegen/typescript/transpilation.py +1051 -0
- aas_core_codegen/typescript/unrolling.py +159 -0
- aas_core_codegen/typescript/verification/__init__.py +6 -0
- aas_core_codegen/typescript/verification/_generate.py +1578 -0
- aas_core_codegen/xsd/__init__.py +1 -0
- aas_core_codegen/xsd/main.py +1187 -0
- aas_core_codegen/xsd/naming.py +83 -0
- aas_core_codegen/yielding/__init__.py +1 -0
- aas_core_codegen/yielding/flow.py +139 -0
- aas_core_codegen/yielding/linear.py +754 -0
- aas_core_codegen-0.0.16.dist-info/METADATA +211 -0
- aas_core_codegen-0.0.16.dist-info/RECORD +604 -0
- aas_core_codegen-0.0.16.dist-info/WHEEL +5 -0
- aas_core_codegen-0.0.16.dist-info/entry_points.txt +3 -0
- aas_core_codegen-0.0.16.dist-info/licenses/AUTHORS +9 -0
- aas_core_codegen-0.0.16.dist-info/licenses/LICENSE +23 -0
- aas_core_codegen-0.0.16.dist-info/top_level.txt +2 -0
- dev/continuous_integration/__init__.py +1 -0
- dev/continuous_integration/check_help_in_readme.py +208 -0
- dev/continuous_integration/check_init_and_pyproject_consistent.py +154 -0
- dev/continuous_integration/precommit.py +400 -0
- dev/dev_scripts/__init__.py +1 -0
- dev/dev_scripts/compare_rendered_regexes_against_source_py.py +42 -0
- dev/dev_scripts/copy_to_aas_core3_cpp.py +100 -0
- dev/dev_scripts/copy_to_aas_core3_java.py +90 -0
- dev/dev_scripts/download_latest_aas_core_meta_v3.py +114 -0
- dev/dev_scripts/draw_bipartite_graph_based_on_lines.py +37 -0
- dev/dev_scripts/run_tests_with_rerecord.py +69 -0
- dev/dev_scripts/update_to_aas_core_meta.py +174 -0
- dev/integration_tests/input/jsonschema/boilerplate/main.py +55 -0
- dev/integration_tests/input/meta_model.py +38 -0
- dev/integration_tests/input/python/boilerplate/main.py +153 -0
- dev/integration_tests/main.py +258 -0
- dev/test_data/csharp/test_structure/concrete_class_with_descendants/meta_model.py +15 -0
- dev/test_data/csharp/test_structure/constructor_without_arguments/all_properties_optional/meta_model.py +9 -0
- dev/test_data/csharp/test_structure/constructor_without_arguments/no_properties/meta_model.py +6 -0
- dev/test_data/csharp/test_verification/builtin_functions/len/on_list/meta_model.py +20 -0
- dev/test_data/csharp/test_verification/builtin_functions/len/on_str/meta_model.py +16 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_as_literal/as_prefix/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_as_literal/as_suffix/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_as_literal/in_group_with_quantifier/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_as_literal/in_the_middle/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_as_literal/in_union/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_as_literal/single_utf32_literal/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_as_literal/with_quantifier_within_group/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_as_literal/with_quantifier_without_group/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/literal/at_the_beginning/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/literal/at_the_end/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/literal/in_the_middle/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/literal/multiple/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/literal/single/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/literal/single_with_quantifier/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/range/mixed_with_non_utf32/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/range/more_than_two_high_surrogates/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/range/multiple_utf32_ranges/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/range/multiple_utf32_ranges_mixed_with_non_utf32/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/range/same_high_surrogate/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/range/same_high_surrogate_with_quantifier/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/range/two_high_surrogates/meta_model.py +8 -0
- dev/test_data/intermediate/expected/class/empty/meta_model.py +6 -0
- dev/test_data/intermediate/expected/class/implementation_specific_method/meta_model.py +8 -0
- dev/test_data/intermediate/expected/class/inheritance/meta_model.py +41 -0
- dev/test_data/intermediate/expected/class/methods_with_contracts/meta_model.py +15 -0
- dev/test_data/intermediate/expected/class/only_method_no_property/meta_model.py +7 -0
- dev/test_data/intermediate/expected/class/only_property_no_method/meta_model.py +9 -0
- dev/test_data/intermediate/expected/constant/constant_set/of_enum/meta_model.py +12 -0
- dev/test_data/intermediate/expected/constant/constant_set/of_str/meta_model.py +4 -0
- dev/test_data/intermediate/expected/constant/constant_set/with_description/meta_model.py +6 -0
- dev/test_data/intermediate/expected/constant/constant_set/with_superset_of/meta_model.py +14 -0
- dev/test_data/intermediate/expected/constant/constant_str/only_value/meta_model.py +7 -0
- dev/test_data/intermediate/expected/constant/constant_str/with_description/meta_model.py +5 -0
- dev/test_data/intermediate/expected/documentation/docstring_with_special_characters_in_literal/meta_model.py +20 -0
- dev/test_data/intermediate/expected/documentation/docstring_with_special_characters_outside_literal/meta_model.py +20 -0
- dev/test_data/intermediate/expected/empty/meta_model.py +2 -0
- dev/test_data/intermediate/expected/enumeration/meta_model.py +9 -0
- dev/test_data/intermediate/expected/interface/basic/meta_model.py +14 -0
- dev/test_data/intermediate/expected/interface/empty/meta_model.py +7 -0
- dev/test_data/intermediate/expected/interface/inheritance/meta_model.py +27 -0
- dev/test_data/intermediate/expected/interface/method_signature/meta_model.py +10 -0
- dev/test_data/intermediate/expected/interface/only_constructor/meta_model.py +11 -0
- dev/test_data/intermediate/expected/method/non_mutating/implementation_specific/meta_model.py +12 -0
- dev/test_data/intermediate/expected/method/non_mutating/understood/meta_model.py +11 -0
- dev/test_data/intermediate/expected/type_annotation/atomic/meta_model.py +9 -0
- dev/test_data/intermediate/expected/type_annotation/subscripted/class/meta_model.py +13 -0
- dev/test_data/intermediate/expected/type_annotation/subscripted/primitive/meta_model.py +9 -0
- dev/test_data/intermediate/unexpected/constant_set/of_enum/enumeration_literals_in_subset_outside_of_superset/meta_model.py +20 -0
- dev/test_data/intermediate/unexpected/constant_set/of_enum/invalid_literal/meta_model.py +11 -0
- dev/test_data/intermediate/unexpected/constant_set/of_enum/mismatch_between_enumeration_and_literal/meta_model.py +30 -0
- dev/test_data/intermediate/unexpected/constant_set/of_enum/mismatch_in_enumerations_between_subset_and_superset/meta_model.py +21 -0
- dev/test_data/intermediate/unexpected/constant_set/of_str/literals_in_subset_outside_of_superset/meta_model.py +18 -0
- dev/test_data/intermediate/unexpected/constant_set/of_str/mismatch_between_type_annotation_and_literals/meta_model.py +10 -0
- dev/test_data/intermediate/unexpected/constant_set/of_str/superset_and_subset_mismatch_in_type/meta_model.py +12 -0
- dev/test_data/intermediate/unexpected/constraints/dangling_constraintref/meta_model.py +18 -0
- dev/test_data/intermediate/unexpected/constraints/duplicate_constraints/meta_model.py +20 -0
- dev/test_data/intermediate/unexpected/documentation/unexpected_documentation_elements/meta_model.py +34 -0
- dev/test_data/intermediate/unexpected/invariant/class_invariant_uses_re/meta_model.py +10 -0
- dev/test_data/intermediate/unexpected/invariant/invariant_of_constrained_primitive_uses_re/meta_model.py +7 -0
- dev/test_data/intermediate/unexpected/invariant/unexpected_argument_count_to_len/meta_model.py +20 -0
- dev/test_data/intermediate/unexpected/invariant/unhandled_built_in_function/meta_model.py +16 -0
- dev/test_data/intermediate/unexpected/method_definitions/non_constant_default/meta_model.py +7 -0
- dev/test_data/intermediate/unexpected/optional_constructor_arguments_wo_default/default_non_none/meta_model.py +16 -0
- dev/test_data/intermediate/unexpected/optional_constructor_arguments_wo_default/no_default/meta_model.py +16 -0
- dev/test_data/intermediate/unexpected/properties_and_constructor_arguments_do_not_match/after_inheritance/meta_model.py +58 -0
- dev/test_data/intermediate/unexpected/properties_and_constructor_arguments_do_not_match/type_missmatch/meta_model.py +9 -0
- dev/test_data/intermediate/unexpected/properties_and_constructor_arguments_do_not_match/within_class/meta_model.py +22 -0
- dev/test_data/jsonschema/test_main/regression_when_len_constraints_on_inherited_property/meta_model.py +28 -0
- dev/test_data/opcua/test_main/abstract_and_concrete_classes/meta_model.py +37 -0
- dev/test_data/opcua/test_main/classes_with_invariants/meta_model.py +21 -0
- dev/test_data/opcua/test_main/concrete_class_with_descendant/meta_model.py +27 -0
- dev/test_data/opcua/test_main/concrete_class_with_enum/meta_model.py +21 -0
- dev/test_data/opcua/test_main/concrete_class_with_list_of_instances/meta_model.py +21 -0
- dev/test_data/opcua/test_main/concrete_class_with_primitive_attributes/meta_model.py +41 -0
- dev/test_data/opcua/test_main/concrete_class_with_string/meta_model.py +13 -0
- dev/test_data/opcua/test_main/constrained_primitive/meta_model.py +20 -0
- dev/test_data/opcua/test_main/multiple_inheritance/meta_model.py +25 -0
- dev/test_data/parse/expected/constant/constant_set/of_enum/meta_model.py +12 -0
- dev/test_data/parse/expected/constant/constant_set/of_str/meta_model.py +4 -0
- dev/test_data/parse/expected/constant/constant_set/with_description/meta_model.py +6 -0
- dev/test_data/parse/expected/constant/constant_set/with_superset_of/meta_model.py +14 -0
- dev/test_data/parse/expected/constant/constant_str/only_value/meta_model.py +7 -0
- dev/test_data/parse/expected/constant/constant_str/with_description/meta_model.py +5 -0
- dev/test_data/parse/expected/enum/ok/meta_model.py +15 -0
- dev/test_data/parse/expected/implementation_specific_class/properties_and_methods_in_implementation_specific_class/meta_model.py +17 -0
- dev/test_data/parse/expected/inheritance/basic/meta_model.py +11 -0
- dev/test_data/parse/expected/inheritance/diamond/meta_model.py +26 -0
- dev/test_data/parse/expected/inheritance/inheritance_from_concrete_class/meta_model.py +10 -0
- dev/test_data/parse/expected/invariants/in_relation/meta_model.py +16 -0
- dev/test_data/parse/expected/method/arguments/meta_model.py +7 -0
- dev/test_data/parse/expected/method/basic/meta_model.py +7 -0
- dev/test_data/parse/expected/method/contracts/condition_as_keyword_argument/meta_model.py +8 -0
- dev/test_data/parse/expected/method/contracts/condition_as_positional_argument/meta_model.py +8 -0
- dev/test_data/parse/expected/method/contracts/description_as_keyword_argument/meta_model.py +8 -0
- dev/test_data/parse/expected/method/contracts/description_as_positional_argument/meta_model.py +8 -0
- dev/test_data/parse/expected/method/contracts/multiple_contracts_in_order/meta_model.py +17 -0
- dev/test_data/parse/expected/method/contracts/postcondition/basic/meta_model.py +10 -0
- dev/test_data/parse/expected/method/contracts/postcondition/snapshot/with_keyword_arguments/meta_model.py +9 -0
- dev/test_data/parse/expected/method/contracts/postcondition/snapshot/with_positional_arguments/meta_model.py +9 -0
- dev/test_data/parse/expected/method/default/meta_model.py +9 -0
- dev/test_data/parse/expected/method/description/meta_model.py +8 -0
- dev/test_data/parse/expected/method/is_implementation_specific/meta_model.py +8 -0
- dev/test_data/parse/expected/method/non_mutating/meta_model.py +11 -0
- dev/test_data/parse/expected/method/returns_none/meta_model.py +7 -0
- dev/test_data/parse/expected/method/returns_something/meta_model.py +7 -0
- dev/test_data/parse/expected/single_class/description/meta_model.py +12 -0
- dev/test_data/parse/expected/single_class/empty/meta_model.py +6 -0
- dev/test_data/parse/expected/single_class/property/description/meta_model.py +14 -0
- dev/test_data/parse/expected/single_class/property/mandatory/meta_model.py +6 -0
- dev/test_data/parse/expected/single_class/property/optional/meta_model.py +6 -0
- dev/test_data/parse/expected/single_class/property/recursion_to_entity/meta_model.py +6 -0
- dev/test_data/parse/unexpected/class_decorators/non_name_decorator/meta_model.py +7 -0
- dev/test_data/parse/unexpected/class_decorators/unknown_decorator/meta_model.py +7 -0
- dev/test_data/parse/unexpected/class_definitions/is_abstract_and_implementation_specific/meta_model.py +8 -0
- dev/test_data/parse/unexpected/class_definitions/unexpected_docstring_before_a_method/meta_model.py +11 -0
- dev/test_data/parse/unexpected/class_definitions/unexpected_docstring_for_a_pass/meta_model.py +9 -0
- dev/test_data/parse/unexpected/class_definitions/unexpected_double_description_for_a_property/meta_model.py +10 -0
- dev/test_data/parse/unexpected/class_inheritances/inheriting_from_implementation_specific_parent/meta_model.py +20 -0
- dev/test_data/parse/unexpected/class_inheritances/non_name_super_class/meta_model.py +6 -0
- dev/test_data/parse/unexpected/enum/expression_as_assignment_value/meta_model.py +6 -0
- dev/test_data/parse/unexpected/enum/non_assignment/meta_model.py +8 -0
- dev/test_data/parse/unexpected/enum/non_string_literal/meta_model.py +6 -0
- dev/test_data/parse/unexpected/enum/unexpected_inheritance/meta_model.py +6 -0
- dev/test_data/parse/unexpected/method_contracts/contract/non_lambda_condition/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_contracts/contract/non_string_literal_description/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_contracts/contract/without_any_arguments/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_contracts/contract/without_condition/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_contracts/postcondition/OLD_in_postcondition_without_snapshot/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_contracts/postcondition/argument_missing_in_function/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_contracts/precondition/argument_missing_in_function/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_contracts/snapshot/argument_missing_in_function/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_contracts/snapshot/capture_not_a_lambda/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_contracts/snapshot/invalid_name/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_contracts/snapshot/name_not_a_string_literal/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_contracts/snapshot/without_a_capture/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_contracts/snapshot/without_a_name/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_decorators/non_mutating/non_mutating_constructor/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_decorators/non_mutating/non_mutating_verification_function/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_decorators/non_name_decorator/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_decorators/unknown_call_decorator/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_decorators/unknown_name_decorator/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_definitions/argument_with_final/meta_model.py +7 -0
- dev/test_data/parse/unexpected/method_definitions/argument_without_a_type_annotation/meta_model.py +7 -0
- dev/test_data/parse/unexpected/method_definitions/default_for_self/meta_model.py +7 -0
- dev/test_data/parse/unexpected/method_definitions/dunder/meta_model.py +7 -0
- dev/test_data/parse/unexpected/method_definitions/init_with_return_type/meta_model.py +7 -0
- dev/test_data/parse/unexpected/method_definitions/with_keyword_only_arguments/meta_model.py +7 -0
- dev/test_data/parse/unexpected/method_definitions/with_positional_arguments/meta_model.py +7 -0
- dev/test_data/parse/unexpected/method_definitions/with_type_annotation_for_self/meta_model.py +7 -0
- dev/test_data/parse/unexpected/method_definitions/with_variable_arguments/meta_model.py +7 -0
- dev/test_data/parse/unexpected/method_definitions/with_variable_keyword_arguments/meta_model.py +7 -0
- dev/test_data/parse/unexpected/method_definitions/without_arguments/meta_model.py +7 -0
- dev/test_data/parse/unexpected/method_definitions/without_self/meta_model.py +7 -0
- dev/test_data/parse/unexpected/method_definitions/without_type_annotation_for_result/meta_model.py +7 -0
- dev/test_data/parse/unexpected/property_definitions/final_without_subscript/meta_model.py +6 -0
- dev/test_data/parse/unexpected/property_definitions/nested_final/meta_model.py +6 -0
- dev/test_data/parse/unexpected/property_definitions/non_simple/meta_model.py +6 -0
- dev/test_data/parse/unexpected/property_definitions/unexpected_assignment/meta_model.py +6 -0
- dev/test_data/parse/unexpected/property_definitions/unexpected_non_name_property/meta_model.py +6 -0
- dev/test_data/parse/unexpected/property_definitions/without_type_annotation/meta_model.py +6 -0
- dev/test_data/parse/unexpected/symbol_table/constant_set_with_a_non_set_subset/meta_model.py +6 -0
- dev/test_data/parse/unexpected/symbol_table/dangling_inheritance/meta_model.py +6 -0
- dev/test_data/parse/unexpected/symbol_table/dangling_reference_in_type_annotation_of_a_property/meta_model.py +6 -0
- dev/test_data/parse/unexpected/symbol_table/dangling_reference_in_type_annotation_of_an_argument/meta_model.py +7 -0
- dev/test_data/parse/unexpected/symbol_table/dangling_reference_in_type_annotation_of_constant_set/meta_model.py +6 -0
- dev/test_data/parse/unexpected/symbol_table/dangling_subset_in_constant_set/meta_model.py +4 -0
- dev/test_data/parse/unexpected/symbol_table/inheritance_from_non_class/meta_model.py +10 -0
- dev/test_data/parse_retree/expected/character_set/common_escaping/source.py +1 -0
- dev/test_data/parse_retree/expected/character_set/complementing/double_caret/source.py +1 -0
- dev/test_data/parse_retree/expected/character_set/complementing/multiple_ranges/source.py +1 -0
- dev/test_data/parse_retree/expected/character_set/complementing/suffix_dash/source.py +1 -0
- dev/test_data/parse_retree/expected/character_set/escape_first_caret/source.py +1 -0
- dev/test_data/parse_retree/expected/character_set/literals_which_need_no_escaping_in_characters_set_but_need_escaping_outside/source.py +1 -0
- dev/test_data/parse_retree/expected/character_set/multiple_ranges/source.py +1 -0
- dev/test_data/parse_retree/expected/character_set/single_literal/source.py +1 -0
- dev/test_data/parse_retree/expected/character_set/single_range/source.py +1 -0
- dev/test_data/parse_retree/expected/character_set/unescaped_dash/only_dash/source.py +1 -0
- dev/test_data/parse_retree/expected/character_set/unescaped_dash/prefix_dash/source.py +1 -0
- dev/test_data/parse_retree/expected/character_set/unescaped_dash/suffix_dash/source.py +1 -0
- dev/test_data/parse_retree/expected/dot/source.py +1 -0
- dev/test_data/parse_retree/expected/empty/group/source.py +1 -0
- dev/test_data/parse_retree/expected/empty/group_in_a_group/source.py +1 -0
- dev/test_data/parse_retree/expected/empty/group_of_union_of_empty_concatenations/source.py +1 -0
- dev/test_data/parse_retree/expected/empty/regex/source.py +1 -0
- dev/test_data/parse_retree/expected/empty/union_of_empty_concatenations/source.py +1 -0
- dev/test_data/parse_retree/expected/escaped_literals/source.py +1 -0
- dev/test_data/parse_retree/expected/formatted_value/at_the_beginning/source.py +1 -0
- dev/test_data/parse_retree/expected/formatted_value/at_the_end/source.py +1 -0
- dev/test_data/parse_retree/expected/formatted_value/in_the_middle/source.py +1 -0
- dev/test_data/parse_retree/expected/formatted_value/single_formatted_value/source.py +1 -0
- dev/test_data/parse_retree/expected/literal/source.py +1 -0
- dev/test_data/parse_retree/expected/quantifier/greedy/at_least_3/source.py +1 -0
- dev/test_data/parse_retree/expected/quantifier/greedy/at_least_one/source.py +1 -0
- dev/test_data/parse_retree/expected/quantifier/greedy/at_most_3/source.py +1 -0
- dev/test_data/parse_retree/expected/quantifier/greedy/exactly_3/source.py +1 -0
- dev/test_data/parse_retree/expected/quantifier/greedy/maybe/source.py +1 -0
- dev/test_data/parse_retree/expected/quantifier/greedy/zero_or_more/source.py +1 -0
- dev/test_data/parse_retree/expected/quantifier/non_greedy/at_least_3/source.py +1 -0
- dev/test_data/parse_retree/expected/quantifier/non_greedy/at_least_one/source.py +1 -0
- dev/test_data/parse_retree/expected/quantifier/non_greedy/at_most_3/source.py +1 -0
- dev/test_data/parse_retree/expected/quantifier/non_greedy/exactly_3/source.py +1 -0
- dev/test_data/parse_retree/expected/quantifier/non_greedy/maybe/source.py +1 -0
- dev/test_data/parse_retree/expected/quantifier/non_greedy/zero_or_more/source.py +1 -0
- dev/test_data/parse_retree/expected/quantifier/on_a_character_set/source.py +1 -0
- dev/test_data/parse_retree/expected/quantifier/on_a_formatted_value/source.py +1 -0
- dev/test_data/parse_retree/expected/quantifier/on_a_group/source.py +1 -0
- dev/test_data/parse_retree/expected/quantifier/on_a_literal/source.py +1 -0
- dev/test_data/parse_retree/expected/start_and_stop_symbols/double_end_symbol/source.py +1 -0
- dev/test_data/parse_retree/expected/start_and_stop_symbols/double_start_symbol/source.py +1 -0
- dev/test_data/parse_retree/expected/start_and_stop_symbols/end_symbol_in_the_middle/source.py +1 -0
- dev/test_data/parse_retree/expected/start_and_stop_symbols/only_start_symbol/source.py +1 -0
- dev/test_data/parse_retree/expected/start_and_stop_symbols/only_stop_symbol/source.py +1 -0
- dev/test_data/parse_retree/expected/start_and_stop_symbols/start_symbol_at_the_beginning/source.py +1 -0
- dev/test_data/parse_retree/expected/start_and_stop_symbols/start_symbol_in_the_middle/source.py +1 -0
- dev/test_data/parse_retree/expected/start_and_stop_symbols/stop_symbol_at_the_end/source.py +1 -0
- dev/test_data/parse_retree/expected/union/of_character_sets/source.py +1 -0
- dev/test_data/parse_retree/expected/union/of_groups/source.py +1 -0
- dev/test_data/parse_retree/expected/union/of_string_literals/source.py +1 -0
- dev/test_data/parse_retree/expected/union/within_group/source.py +1 -0
- dev/test_data/parse_retree/expected/whitespace/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/character_literal/Uxxxxxxxx_out_of_range/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/character_literal/only_backslash/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/character_literal/short_Uxxxxxxxx/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/character_literal/short_uxxxx/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/character_literal/short_x/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/character_literal/unexpected_escaping/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/character_literal/unhandled/digit/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/character_literal/unhandled/not_digit/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/character_literal/unhandled/not_whitespace/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/character_literal/unhandled/not_word/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/character_literal/unhandled/whitespace/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/character_literal/unhandled/word/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/range_character/Uxxxxxxxx_out_of_range/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/range_character/only_backslash/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/range_character/short_Uxxxxxxxx/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/range_character/short_uxxxx/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/range_character/short_x/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/range_character/unexpected_escaping/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/range_character/unhandled/digit/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/range_character/unhandled/not_digit/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/range_character/unhandled/not_whitespace/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/range_character/unhandled/not_word/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/range_character/unhandled/whitespace/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/range_character/unhandled/word/source.py +1 -0
- dev/test_data/parse_retree/unexpected/invalid_character_range/source.py +1 -0
- dev/test_data/parse_retree/unexpected/invalid_quantifier/at_least_x/source.py +1 -0
- dev/test_data/parse_retree/unexpected/invalid_quantifier/between_3_and_x/source.py +1 -0
- dev/test_data/parse_retree/unexpected/invalid_quantifier/exactly_x/source.py +1 -0
- dev/test_data/parse_retree/unexpected/unhandled_group_directives/source.py +1 -0
- dev/test_data/parse_retree/unexpected/unterminated/character_set/source.py +1 -0
- dev/test_data/parse_retree/unexpected/unterminated/group/source.py +1 -0
- dev/test_data/parse_retree/unexpected/unterminated/group_of_union_of_empty_concatenations/source.py +1 -0
- dev/test_data/parse_retree/unexpected/unterminated/quantifier/source.py +1 -0
- dev/test_data/parse_retree/unexpected/unterminated/quantifier_with_comma/source.py +1 -0
- dev/test_data/parse_retree/unexpected/unterminated/quantifier_with_number_and_comma/source.py +1 -0
- dev/test_data/proto/test_main/expected/abstract_and_concrete_classes/meta_model.py +37 -0
- dev/test_data/proto/test_main/expected/concrete_class_with_descendants/meta_model.py +30 -0
- dev/test_data/proto/test_main/expected/concrete_class_with_enum/meta_model.py +21 -0
- dev/test_data/proto/test_main/expected/concrete_class_with_list_of_instances/meta_model.py +21 -0
- dev/test_data/proto/test_main/expected/concrete_class_with_primitive_attributes/meta_model.py +41 -0
- dev/test_data/python_protobuf/test_main/abstract_and_concrete_classes/expected_output/pbization.py +532 -0
- dev/test_data/python_protobuf/test_main/abstract_and_concrete_classes/meta_model.py +37 -0
- dev/test_data/python_protobuf/test_main/concrete_class_with_descendant/expected_output/pbization.py +527 -0
- dev/test_data/python_protobuf/test_main/concrete_class_with_descendant/meta_model.py +27 -0
- dev/test_data/python_protobuf/test_main/concrete_class_with_enum/expected_output/pbization.py +290 -0
- dev/test_data/python_protobuf/test_main/concrete_class_with_enum/meta_model.py +21 -0
- dev/test_data/python_protobuf/test_main/concrete_class_with_list_of_instances/expected_output/pbization.py +328 -0
- dev/test_data/python_protobuf/test_main/concrete_class_with_list_of_instances/meta_model.py +23 -0
- dev/test_data/python_protobuf/test_main/concrete_class_with_primitive_attributes/expected_output/pbization.py +274 -0
- dev/test_data/python_protobuf/test_main/concrete_class_with_primitive_attributes/meta_model.py +41 -0
- dev/test_data/rdf_shacl/test_main/expected/regression_when_lang_string_class_is_missing/meta_model.py +29 -0
- dev/test_data/rdf_shacl/test_main/expected/regression_when_len_constraints_on_inherited_property/meta_model.py +27 -0
- dev/test_data/rdf_shacl/test_main/unexpected/regression_len_constraint_on_class_property/meta_model.py +61 -0
- dev/test_data/real_meta_models/aas_core_meta.v3.py +5721 -0
- dev/test_data/smoke/test_main/unexpected/infer_for_schema_error/meta_model.py +12 -0
- dev/test_data/smoke/test_main/unexpected/intermediate_error/meta_model.py +18 -0
- dev/test_data/smoke/test_main/unexpected/parse_error/meta_model.py +5 -0
- dev/test_data/smoke/test_main/unexpected/pattern_verification_unparsable_regex/direct_match/meta_model.py +8 -0
- dev/test_data/smoke/test_main/unexpected/type_error/meta_model.py +18 -0
- dev/tests/__init__.py +1 -0
- dev/tests/common.py +197 -0
- dev/tests/cpp/__init__.py +0 -0
- dev/tests/cpp/test_common.py +32 -0
- dev/tests/cpp/test_main.py +144 -0
- dev/tests/cpp/test_pattern.py +188 -0
- dev/tests/cpp/test_verification.py +189 -0
- dev/tests/cpp/test_yielding.py +225 -0
- dev/tests/csharp/__init__.py +0 -0
- dev/tests/csharp/live_test_main.py +109 -0
- dev/tests/csharp/test_common.py +28 -0
- dev/tests/csharp/test_description.py +684 -0
- dev/tests/csharp/test_main.py +129 -0
- dev/tests/csharp/test_structure.py +93 -0
- dev/tests/csharp/test_verification.py +82 -0
- dev/tests/description.py +29 -0
- dev/tests/golang/__init__.py +0 -0
- dev/tests/golang/test_common.py +78 -0
- dev/tests/golang/test_main.py +128 -0
- dev/tests/infer_for_schema/__init__.py +0 -0
- dev/tests/infer_for_schema/common.py +47 -0
- dev/tests/infer_for_schema/test_len_on_properties.py +955 -0
- dev/tests/infer_for_schema/test_len_on_self.py +580 -0
- dev/tests/infer_for_schema/test_patterns_on_properties.py +686 -0
- dev/tests/infer_for_schema/test_patterns_on_self.py +258 -0
- dev/tests/infer_for_schema/test_property_in_set_of_enumeration_literals.py +600 -0
- dev/tests/infer_for_schema/test_property_in_set_of_primitives.py +549 -0
- dev/tests/intermediate/__init__.py +0 -0
- dev/tests/intermediate/test_constructor.py +719 -0
- dev/tests/intermediate/test_hierarchy.py +221 -0
- dev/tests/intermediate/test_revm.py +134 -0
- dev/tests/intermediate/test_translate.py +337 -0
- dev/tests/intermediate/test_type_inference.py +333 -0
- dev/tests/intermediate/test_types.py +169 -0
- dev/tests/java/__init__.py +0 -0
- dev/tests/java/test_common.py +20 -0
- dev/tests/java/test_description.py +128 -0
- dev/tests/java/test_main.py +234 -0
- dev/tests/jsonld_context/test_main.py +79 -0
- dev/tests/opcua/__init__.py +3 -0
- dev/tests/opcua/test_main.py +110 -0
- dev/tests/our_jsonschema/__init__.py +3 -0
- dev/tests/our_jsonschema/test_main.py +232 -0
- dev/tests/parse/__init__.py +0 -0
- dev/tests/parse/test_parse.py +503 -0
- dev/tests/parse/test_retree.py +272 -0
- dev/tests/proto/__init__.py +0 -0
- dev/tests/proto/test_main.py +112 -0
- dev/tests/python/__init__.py +0 -0
- dev/tests/python/test_common.py +124 -0
- dev/tests/python/test_main.py +126 -0
- dev/tests/python/test_xml_playground.py +254 -0
- dev/tests/python_protobuf/__init__.py +0 -0
- dev/tests/python_protobuf/test_main.py +111 -0
- dev/tests/rdf_shacl/__init__.py +0 -0
- dev/tests/rdf_shacl/test_common.py +32 -0
- dev/tests/rdf_shacl/test_description.py +223 -0
- dev/tests/rdf_shacl/test_main.py +194 -0
- dev/tests/smoke/__init__.py +0 -0
- dev/tests/smoke/test_main.py +83 -0
- dev/tests/test_common.py +94 -0
- dev/tests/typescript/__init__.py +0 -0
- dev/tests/typescript/test_common.py +108 -0
- dev/tests/typescript/test_main.py +125 -0
- dev/tests/xsd/__init__.py +0 -0
- dev/tests/xsd/test_main.py +227 -0
- dev/tests/yielding/__init__.py +0 -0
- dev/tests/yielding/test_linear.py +558 -0
|
@@ -0,0 +1,1767 @@
|
|
|
1
|
+
"""Generate the Java data structures from the intermediate representation."""
|
|
2
|
+
import io
|
|
3
|
+
import textwrap
|
|
4
|
+
from typing import (
|
|
5
|
+
cast,
|
|
6
|
+
Dict,
|
|
7
|
+
List,
|
|
8
|
+
Optional,
|
|
9
|
+
Tuple,
|
|
10
|
+
Union,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
from icontract import ensure, require
|
|
14
|
+
|
|
15
|
+
from aas_core_codegen import intermediate
|
|
16
|
+
from aas_core_codegen import specific_implementations
|
|
17
|
+
from aas_core_codegen.common import (
|
|
18
|
+
assert_never,
|
|
19
|
+
Error,
|
|
20
|
+
Identifier,
|
|
21
|
+
Stripped,
|
|
22
|
+
indent_but_first_line,
|
|
23
|
+
)
|
|
24
|
+
from aas_core_codegen.java import (
|
|
25
|
+
common as java_common,
|
|
26
|
+
description as java_description,
|
|
27
|
+
naming as java_naming,
|
|
28
|
+
)
|
|
29
|
+
from aas_core_codegen.java.common import (
|
|
30
|
+
INDENT as I,
|
|
31
|
+
INDENT2 as II,
|
|
32
|
+
INDENT3 as III,
|
|
33
|
+
)
|
|
34
|
+
from aas_core_codegen.intermediate import (
|
|
35
|
+
ListTypeAnnotation,
|
|
36
|
+
OptionalTypeAnnotation,
|
|
37
|
+
OurTypeAnnotation,
|
|
38
|
+
PrimitiveTypeAnnotation,
|
|
39
|
+
TypeAnnotationUnion,
|
|
40
|
+
construction as intermediate_construction,
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
# region Checks
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _human_readable_identifier(
|
|
48
|
+
something: Union[
|
|
49
|
+
intermediate.Enumeration, intermediate.AbstractClass, intermediate.ConcreteClass
|
|
50
|
+
]
|
|
51
|
+
) -> str:
|
|
52
|
+
"""
|
|
53
|
+
Represent ``something`` in a human-readable text.
|
|
54
|
+
|
|
55
|
+
The reader should be able to trace ``something`` back to the meta-model.
|
|
56
|
+
"""
|
|
57
|
+
result: str
|
|
58
|
+
|
|
59
|
+
if isinstance(something, intermediate.Enumeration):
|
|
60
|
+
result = f"meta-model enumeration {something.name!r}"
|
|
61
|
+
elif isinstance(something, intermediate.AbstractClass):
|
|
62
|
+
result = f"meta-model abstract class {something.name!r}"
|
|
63
|
+
elif isinstance(something, intermediate.ConcreteClass):
|
|
64
|
+
result = f"meta-model concrete class {something.name!r}"
|
|
65
|
+
else:
|
|
66
|
+
assert_never(something)
|
|
67
|
+
|
|
68
|
+
return result
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _verify_intra_structure_collisions(
|
|
72
|
+
our_type: intermediate.OurType,
|
|
73
|
+
) -> Optional[Error]:
|
|
74
|
+
"""Verify that no member names collide in the Java structure of our type."""
|
|
75
|
+
errors = [] # type: List[Error]
|
|
76
|
+
|
|
77
|
+
if isinstance(our_type, intermediate.Enumeration):
|
|
78
|
+
pass
|
|
79
|
+
|
|
80
|
+
elif isinstance(our_type, intermediate.ConstrainedPrimitive):
|
|
81
|
+
pass
|
|
82
|
+
|
|
83
|
+
elif isinstance(our_type, intermediate.Class):
|
|
84
|
+
observed_member_names = {} # type: Dict[Identifier, str]
|
|
85
|
+
|
|
86
|
+
for prop in our_type.properties:
|
|
87
|
+
prop_name = java_naming.property_name(prop.name)
|
|
88
|
+
if prop_name in observed_member_names:
|
|
89
|
+
# BEFORE-RELEASE (mristin, 2021-12-13): test
|
|
90
|
+
errors.append(
|
|
91
|
+
Error(
|
|
92
|
+
prop.parsed.node,
|
|
93
|
+
f"Java property {prop_name!r} corresponding "
|
|
94
|
+
f"to the meta-model property {prop.name!r} collides with "
|
|
95
|
+
f"the {observed_member_names[prop_name]}",
|
|
96
|
+
)
|
|
97
|
+
)
|
|
98
|
+
else:
|
|
99
|
+
observed_member_names[prop_name] = (
|
|
100
|
+
f"Java property {prop_name!r} corresponding to "
|
|
101
|
+
f"the meta-model property {prop.name!r}"
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
for method in our_type.methods:
|
|
105
|
+
method_name = java_naming.method_name(method.name)
|
|
106
|
+
|
|
107
|
+
if method_name in observed_member_names:
|
|
108
|
+
# BEFORE-RELEASE (mristin, 2021-12-13): test
|
|
109
|
+
errors.append(
|
|
110
|
+
Error(
|
|
111
|
+
method.parsed.node,
|
|
112
|
+
f"Java method {method_name!r} corresponding "
|
|
113
|
+
f"to the meta-model method {method.name!r} collides with "
|
|
114
|
+
f"the {observed_member_names[method_name]}",
|
|
115
|
+
)
|
|
116
|
+
)
|
|
117
|
+
else:
|
|
118
|
+
observed_member_names[method_name] = (
|
|
119
|
+
f"Java method {method_name!r} corresponding to "
|
|
120
|
+
f"the meta-model method {method.name!r}"
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
else:
|
|
124
|
+
assert_never(our_type)
|
|
125
|
+
|
|
126
|
+
if len(errors) > 0:
|
|
127
|
+
errors.append(
|
|
128
|
+
Error(
|
|
129
|
+
our_type.parsed.node,
|
|
130
|
+
f"Naming collision(s) in Java code for our type {our_type.name!r}",
|
|
131
|
+
underlying=errors,
|
|
132
|
+
)
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
return None
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def _verify_structure_name_collisions(
|
|
139
|
+
symbol_table: intermediate.SymbolTable,
|
|
140
|
+
) -> List[Error]:
|
|
141
|
+
"""Verify that the Java names of the structures do not collide."""
|
|
142
|
+
observed_structure_names: Dict[
|
|
143
|
+
Identifier,
|
|
144
|
+
Union[
|
|
145
|
+
intermediate.Enumeration,
|
|
146
|
+
intermediate.AbstractClass,
|
|
147
|
+
intermediate.ConcreteClass,
|
|
148
|
+
],
|
|
149
|
+
] = dict()
|
|
150
|
+
|
|
151
|
+
errors = [] # type: List[Error]
|
|
152
|
+
|
|
153
|
+
# region Inter-structure collisions
|
|
154
|
+
|
|
155
|
+
for our_type in symbol_table.our_types:
|
|
156
|
+
if not isinstance(
|
|
157
|
+
our_type,
|
|
158
|
+
(
|
|
159
|
+
intermediate.Enumeration,
|
|
160
|
+
intermediate.AbstractClass,
|
|
161
|
+
intermediate.ConcreteClass,
|
|
162
|
+
),
|
|
163
|
+
):
|
|
164
|
+
continue
|
|
165
|
+
|
|
166
|
+
if isinstance(our_type, intermediate.Enumeration):
|
|
167
|
+
name = java_naming.enum_name(our_type.name)
|
|
168
|
+
other = observed_structure_names.get(name, None)
|
|
169
|
+
|
|
170
|
+
if other is not None:
|
|
171
|
+
errors.append(
|
|
172
|
+
Error(
|
|
173
|
+
our_type.parsed.node,
|
|
174
|
+
f"The Java name {name!r} for the enumeration {our_type.name!r} "
|
|
175
|
+
f"collides with the same Java name "
|
|
176
|
+
f"coming from the {_human_readable_identifier(other)}",
|
|
177
|
+
)
|
|
178
|
+
)
|
|
179
|
+
else:
|
|
180
|
+
observed_structure_names[name] = our_type
|
|
181
|
+
|
|
182
|
+
elif isinstance(
|
|
183
|
+
our_type, (intermediate.AbstractClass, intermediate.ConcreteClass)
|
|
184
|
+
):
|
|
185
|
+
interface_name = java_naming.interface_name(our_type.name)
|
|
186
|
+
|
|
187
|
+
other = observed_structure_names.get(interface_name, None)
|
|
188
|
+
|
|
189
|
+
if other is not None:
|
|
190
|
+
errors.append(
|
|
191
|
+
Error(
|
|
192
|
+
our_type.parsed.node,
|
|
193
|
+
f"The Java name {interface_name!r} of the interface "
|
|
194
|
+
f"for the class {our_type.name!r} "
|
|
195
|
+
f"collides with the same Java name "
|
|
196
|
+
f"coming from the {_human_readable_identifier(other)}",
|
|
197
|
+
)
|
|
198
|
+
)
|
|
199
|
+
else:
|
|
200
|
+
observed_structure_names[interface_name] = our_type
|
|
201
|
+
|
|
202
|
+
if isinstance(our_type, intermediate.ConcreteClass):
|
|
203
|
+
class_name = java_naming.class_name(our_type.name)
|
|
204
|
+
|
|
205
|
+
other = observed_structure_names.get(class_name, None)
|
|
206
|
+
|
|
207
|
+
if other is not None:
|
|
208
|
+
errors.append(
|
|
209
|
+
Error(
|
|
210
|
+
our_type.parsed.node,
|
|
211
|
+
f"The Java name {class_name!r} "
|
|
212
|
+
f"for the class {our_type.name!r} "
|
|
213
|
+
f"collides with the same Java name "
|
|
214
|
+
f"coming from the {_human_readable_identifier(other)}",
|
|
215
|
+
)
|
|
216
|
+
)
|
|
217
|
+
else:
|
|
218
|
+
observed_structure_names[class_name] = our_type
|
|
219
|
+
else:
|
|
220
|
+
assert_never(our_type)
|
|
221
|
+
|
|
222
|
+
# endregion
|
|
223
|
+
|
|
224
|
+
# region Intra-structure collisions
|
|
225
|
+
|
|
226
|
+
for our_type in symbol_table.our_types:
|
|
227
|
+
collision_error = _verify_intra_structure_collisions(our_type=our_type)
|
|
228
|
+
|
|
229
|
+
if collision_error is not None:
|
|
230
|
+
errors.append(collision_error)
|
|
231
|
+
|
|
232
|
+
# endregion
|
|
233
|
+
|
|
234
|
+
return errors
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
class VerifiedIntermediateSymbolTable(intermediate.SymbolTable):
|
|
238
|
+
"""Represent a verified symbol table which can be used for code generation."""
|
|
239
|
+
|
|
240
|
+
# noinspection PyInitNewSignature
|
|
241
|
+
def __new__(
|
|
242
|
+
cls, symbol_table: intermediate.SymbolTable
|
|
243
|
+
) -> "VerifiedIntermediateSymbolTable":
|
|
244
|
+
raise AssertionError("Only for type annotation")
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
@ensure(lambda result: (result[0] is None) ^ (result[1] is None))
|
|
248
|
+
def verify(
|
|
249
|
+
symbol_table: intermediate.SymbolTable,
|
|
250
|
+
) -> Tuple[Optional[VerifiedIntermediateSymbolTable], Optional[List[Error]]]:
|
|
251
|
+
"""Verify that Java code can be generated from the ``symbol_table``."""
|
|
252
|
+
|
|
253
|
+
errors = [] # type: List[Error]
|
|
254
|
+
|
|
255
|
+
structure_name_collisions = _verify_structure_name_collisions(
|
|
256
|
+
symbol_table=symbol_table
|
|
257
|
+
)
|
|
258
|
+
|
|
259
|
+
errors.extend(structure_name_collisions)
|
|
260
|
+
|
|
261
|
+
if len(errors) > 0:
|
|
262
|
+
return None, errors
|
|
263
|
+
|
|
264
|
+
return cast(VerifiedIntermediateSymbolTable, symbol_table), None
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
# endregion
|
|
268
|
+
|
|
269
|
+
# region Generation
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
def _beneath_optional_or_list(
|
|
273
|
+
type_anno: TypeAnnotationUnion,
|
|
274
|
+
) -> Union[PrimitiveTypeAnnotation, OurTypeAnnotation]:
|
|
275
|
+
while isinstance(type_anno, (ListTypeAnnotation, OptionalTypeAnnotation)):
|
|
276
|
+
if isinstance(type_anno, ListTypeAnnotation):
|
|
277
|
+
type_anno = type_anno.items
|
|
278
|
+
else:
|
|
279
|
+
type_anno = type_anno.value
|
|
280
|
+
|
|
281
|
+
return type_anno
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
def _has_descendable_properties(cls: intermediate.Class) -> bool:
|
|
285
|
+
for prop in cls.properties:
|
|
286
|
+
type_anno = _beneath_optional_or_list(prop.type_annotation)
|
|
287
|
+
|
|
288
|
+
if not isinstance(type_anno, intermediate.OurTypeAnnotation):
|
|
289
|
+
continue
|
|
290
|
+
|
|
291
|
+
our_type = type_anno.our_type
|
|
292
|
+
|
|
293
|
+
if isinstance(
|
|
294
|
+
our_type,
|
|
295
|
+
(
|
|
296
|
+
intermediate.Enumeration,
|
|
297
|
+
intermediate.ConstrainedPrimitive,
|
|
298
|
+
),
|
|
299
|
+
):
|
|
300
|
+
continue
|
|
301
|
+
|
|
302
|
+
descendability = intermediate.map_descendability(
|
|
303
|
+
type_annotation=prop.type_annotation
|
|
304
|
+
)
|
|
305
|
+
|
|
306
|
+
if descendability:
|
|
307
|
+
return True
|
|
308
|
+
|
|
309
|
+
return False
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
def _generate_descend_body(cls: intermediate.ConcreteClass, recurse: bool) -> Stripped:
|
|
313
|
+
"""Generate the iterator function body for recursive and non-recursive descend methods.
|
|
314
|
+
|
|
315
|
+
We leverage lazily evaluated streams to iterate over the object stream one by one.
|
|
316
|
+
"""
|
|
317
|
+
class_name = java_naming.class_name(cls.name)
|
|
318
|
+
|
|
319
|
+
blocks = [
|
|
320
|
+
Stripped("Stream<IClass> memberStream = Stream.empty();")
|
|
321
|
+
] # type: List[Stripped]
|
|
322
|
+
|
|
323
|
+
# region Streams
|
|
324
|
+
|
|
325
|
+
for prop in cls.properties:
|
|
326
|
+
descendability = intermediate.map_descendability(
|
|
327
|
+
type_annotation=prop.type_annotation
|
|
328
|
+
)
|
|
329
|
+
|
|
330
|
+
if not descendability[prop.type_annotation]:
|
|
331
|
+
continue
|
|
332
|
+
|
|
333
|
+
prop_expr = None # type: Optional[Stripped]
|
|
334
|
+
|
|
335
|
+
prop_name = java_naming.property_name(prop.name)
|
|
336
|
+
|
|
337
|
+
type_anno = intermediate.beneath_optional(prop.type_annotation)
|
|
338
|
+
|
|
339
|
+
if isinstance(type_anno, intermediate.PrimitiveTypeAnnotation):
|
|
340
|
+
continue
|
|
341
|
+
elif isinstance(type_anno, intermediate.OurTypeAnnotation):
|
|
342
|
+
if isinstance(type_anno.our_type, intermediate.Enumeration):
|
|
343
|
+
continue
|
|
344
|
+
elif isinstance(type_anno.our_type, intermediate.ConstrainedPrimitive):
|
|
345
|
+
continue
|
|
346
|
+
elif isinstance(
|
|
347
|
+
type_anno.our_type,
|
|
348
|
+
(intermediate.AbstractClass, intermediate.ConcreteClass),
|
|
349
|
+
):
|
|
350
|
+
if not descendability[type_anno] or not recurse:
|
|
351
|
+
prop_expr = Stripped(
|
|
352
|
+
f"Stream.<IClass>of({class_name}.this.{prop_name})"
|
|
353
|
+
)
|
|
354
|
+
else:
|
|
355
|
+
prop_expr = Stripped(
|
|
356
|
+
f"""\
|
|
357
|
+
Stream.concat(Stream.<IClass>of({class_name}.this.{prop_name}),
|
|
358
|
+
{I}StreamSupport.stream({class_name}.this.{prop_name}.descend().spliterator(), false))"""
|
|
359
|
+
)
|
|
360
|
+
else:
|
|
361
|
+
assert_never(type_anno.our_type)
|
|
362
|
+
|
|
363
|
+
elif isinstance(type_anno, intermediate.ListTypeAnnotation):
|
|
364
|
+
assert isinstance(
|
|
365
|
+
type_anno.items, intermediate.OurTypeAnnotation
|
|
366
|
+
) and isinstance(
|
|
367
|
+
type_anno.items.our_type,
|
|
368
|
+
(intermediate.AbstractClass, intermediate.ConcreteClass),
|
|
369
|
+
), (
|
|
370
|
+
f"We expect only list of classes "
|
|
371
|
+
f"at the moment, but you specified {type_anno}. "
|
|
372
|
+
f"Please contact the developers if you need this feature."
|
|
373
|
+
)
|
|
374
|
+
|
|
375
|
+
if not recurse:
|
|
376
|
+
prop_expr = Stripped(f"{class_name}.this.{prop_name}.stream()")
|
|
377
|
+
else:
|
|
378
|
+
prop_expr = Stripped(
|
|
379
|
+
f"""\
|
|
380
|
+
{class_name}.this.{prop_name}.stream()
|
|
381
|
+
{I}.flatMap(item -> Stream.concat(Stream.<IClass>of(item),
|
|
382
|
+
{II}StreamSupport.stream(item.descend().spliterator(), false)))"""
|
|
383
|
+
)
|
|
384
|
+
|
|
385
|
+
else:
|
|
386
|
+
assert_never(type_anno)
|
|
387
|
+
|
|
388
|
+
stream_stmt = Stripped(
|
|
389
|
+
f"""\
|
|
390
|
+
if ({prop_name} != null) {{
|
|
391
|
+
{I}memberStream = Stream.concat(memberStream,
|
|
392
|
+
{II}{indent_but_first_line(prop_expr, II)});
|
|
393
|
+
}}"""
|
|
394
|
+
)
|
|
395
|
+
|
|
396
|
+
blocks.append(stream_stmt)
|
|
397
|
+
|
|
398
|
+
# endregion
|
|
399
|
+
|
|
400
|
+
blocks.append(Stripped("return memberStream;"))
|
|
401
|
+
|
|
402
|
+
return Stripped("\n\n".join(blocks))
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
def _generate_descend_iterable(
|
|
406
|
+
cls: intermediate.ConcreteClass, recursive: bool
|
|
407
|
+
) -> Stripped:
|
|
408
|
+
"""Generate the iterator for the descend method."""
|
|
409
|
+
|
|
410
|
+
cls_name = java_naming.class_name(cls.name)
|
|
411
|
+
|
|
412
|
+
iterable_name: Stripped
|
|
413
|
+
|
|
414
|
+
if recursive:
|
|
415
|
+
iterable_name = Stripped(f"{cls_name}RecursiveIterable")
|
|
416
|
+
else:
|
|
417
|
+
iterable_name = Stripped(f"{cls_name}Iterable")
|
|
418
|
+
|
|
419
|
+
iterable_body = _generate_descend_body(cls, recursive)
|
|
420
|
+
|
|
421
|
+
iterable = Stripped(
|
|
422
|
+
f"""\
|
|
423
|
+
private class {iterable_name} implements Iterable<IClass> {{
|
|
424
|
+
{I}@Override
|
|
425
|
+
{I}public Iterator<IClass> iterator() {{
|
|
426
|
+
{II}Stream<IClass> stream = stream();
|
|
427
|
+
|
|
428
|
+
{II}return stream.iterator();
|
|
429
|
+
{I}}}
|
|
430
|
+
|
|
431
|
+
{I}@Override
|
|
432
|
+
{I}public void forEach(Consumer<? super IClass> action) {{
|
|
433
|
+
{II}Stream<IClass> stream = stream();
|
|
434
|
+
|
|
435
|
+
{II}stream.forEach(action);
|
|
436
|
+
{I}}}
|
|
437
|
+
|
|
438
|
+
{I}@Override
|
|
439
|
+
{I}public Spliterator<IClass> spliterator() {{
|
|
440
|
+
{II}Stream<IClass> stream = stream();
|
|
441
|
+
|
|
442
|
+
{II}return stream.spliterator();
|
|
443
|
+
{I}}}
|
|
444
|
+
|
|
445
|
+
{I}private Stream<IClass> stream() {{
|
|
446
|
+
{II}{indent_but_first_line(iterable_body, II)}
|
|
447
|
+
{I}}}
|
|
448
|
+
}}"""
|
|
449
|
+
)
|
|
450
|
+
|
|
451
|
+
return iterable
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
def _generate_descend_method(
|
|
455
|
+
cls: intermediate.ConcreteClass, descendable: bool
|
|
456
|
+
) -> Stripped:
|
|
457
|
+
"""Generate the recursive ``Descend`` method for the concrete class ``cls``."""
|
|
458
|
+
|
|
459
|
+
cls_name = java_naming.class_name(cls.name)
|
|
460
|
+
|
|
461
|
+
iterable_name = Stripped(f"{cls_name}RecursiveIterable")
|
|
462
|
+
|
|
463
|
+
descend_body: Stripped
|
|
464
|
+
|
|
465
|
+
if descendable:
|
|
466
|
+
descend_body = Stripped(f"return new {iterable_name}();")
|
|
467
|
+
else:
|
|
468
|
+
descend_body = Stripped("return Collections.emptyList();")
|
|
469
|
+
|
|
470
|
+
return Stripped(
|
|
471
|
+
f"""\
|
|
472
|
+
/**
|
|
473
|
+
* Iterate recursively over all the class instances referenced from this instance.
|
|
474
|
+
*/
|
|
475
|
+
public Iterable<IClass> descend() {{
|
|
476
|
+
{I}{descend_body}
|
|
477
|
+
}}"""
|
|
478
|
+
)
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
def _generate_descend_once_method(
|
|
482
|
+
cls: intermediate.ConcreteClass, descendable: bool
|
|
483
|
+
) -> Stripped:
|
|
484
|
+
"""Generate the recursive ``Descend`` method for the concrete class ``cls``."""
|
|
485
|
+
|
|
486
|
+
cls_name = java_naming.class_name(cls.name)
|
|
487
|
+
|
|
488
|
+
iterable_name = Stripped(f"{cls_name}Iterable")
|
|
489
|
+
|
|
490
|
+
descend_body: Stripped
|
|
491
|
+
if descendable:
|
|
492
|
+
descend_body = Stripped(f"return new {iterable_name}();")
|
|
493
|
+
else:
|
|
494
|
+
descend_body = Stripped("return Collections.emptyList();")
|
|
495
|
+
|
|
496
|
+
return Stripped(
|
|
497
|
+
f"""\
|
|
498
|
+
/**
|
|
499
|
+
* Iterate over all the class instances referenced from this instance.
|
|
500
|
+
*/
|
|
501
|
+
public Iterable<IClass> descendOnce() {{
|
|
502
|
+
{I}{descend_body}
|
|
503
|
+
}}"""
|
|
504
|
+
)
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+
def _generate_imports_for_interface(
|
|
508
|
+
cls: intermediate.ClassUnion,
|
|
509
|
+
package: java_common.PackageIdentifier,
|
|
510
|
+
) -> Stripped:
|
|
511
|
+
"""
|
|
512
|
+
Generate necessary Java Platform imports for the given class ``cls``.
|
|
513
|
+
|
|
514
|
+
The ``package`` defines the root Java package.
|
|
515
|
+
"""
|
|
516
|
+
imports = [
|
|
517
|
+
Stripped(f"{package}.types.enums.*"),
|
|
518
|
+
Stripped(f"{package}.types.impl.*"),
|
|
519
|
+
Stripped(f"{package}.types.model.*"),
|
|
520
|
+
Stripped("java.util.List"),
|
|
521
|
+
] # type: List[Stripped]
|
|
522
|
+
|
|
523
|
+
if len(cls.inheritances) == 0:
|
|
524
|
+
import_name = Stripped(f"{package}.types.{java_common.INTERFACE_PKG}.IClass")
|
|
525
|
+
imports.append(import_name)
|
|
526
|
+
else:
|
|
527
|
+
for inheritance in cls.inheritances:
|
|
528
|
+
super_name = java_naming.interface_name(inheritance.name)
|
|
529
|
+
|
|
530
|
+
import_name = Stripped(
|
|
531
|
+
f"{package}.types.{java_common.INTERFACE_PKG}.{super_name}"
|
|
532
|
+
)
|
|
533
|
+
|
|
534
|
+
imports.append(import_name)
|
|
535
|
+
|
|
536
|
+
if any(prop for prop in cls.properties if prop.specified_for is cls):
|
|
537
|
+
imports.append(Stripped("java.util.Optional"))
|
|
538
|
+
|
|
539
|
+
return Stripped("\n".join(map(lambda imp: f"import {imp};", imports)))
|
|
540
|
+
|
|
541
|
+
|
|
542
|
+
def _generate_imports_for_class(
|
|
543
|
+
cls: intermediate.Class,
|
|
544
|
+
package: java_common.PackageIdentifier,
|
|
545
|
+
) -> Stripped:
|
|
546
|
+
"""
|
|
547
|
+
Generate necessary Java Platform imports for the given class ``cls``.
|
|
548
|
+
|
|
549
|
+
The ``package`` defines the root Java package.
|
|
550
|
+
"""
|
|
551
|
+
if cls.is_implementation_specific:
|
|
552
|
+
return Stripped("")
|
|
553
|
+
|
|
554
|
+
imports = [
|
|
555
|
+
Stripped(f"{package}.visitation.IVisitor"),
|
|
556
|
+
Stripped(f"{package}.visitation.IVisitorWithContext"),
|
|
557
|
+
Stripped(f"{package}.visitation.ITransformer"),
|
|
558
|
+
Stripped(f"{package}.visitation.ITransformerWithContext"),
|
|
559
|
+
Stripped(f"{package}.types.enums.*"),
|
|
560
|
+
Stripped(f"{package}.types.impl.*"),
|
|
561
|
+
Stripped(f"{package}.types.model.*"),
|
|
562
|
+
Stripped("java.util.Collections"),
|
|
563
|
+
Stripped("java.util.List"),
|
|
564
|
+
Stripped("java.util.Optional"),
|
|
565
|
+
Stripped("java.util.Objects"),
|
|
566
|
+
] # type: List[Stripped]
|
|
567
|
+
|
|
568
|
+
if _has_descendable_properties(cls):
|
|
569
|
+
imports.extend(
|
|
570
|
+
[
|
|
571
|
+
Stripped("java.util.Iterator"),
|
|
572
|
+
Stripped("java.util.Spliterator"),
|
|
573
|
+
Stripped("java.util.function.Consumer"),
|
|
574
|
+
Stripped("java.util.stream.Stream"),
|
|
575
|
+
Stripped("java.util.stream.StreamSupport"),
|
|
576
|
+
]
|
|
577
|
+
)
|
|
578
|
+
|
|
579
|
+
interface_name = java_naming.interface_name(cls.name)
|
|
580
|
+
|
|
581
|
+
interface_import = Stripped(
|
|
582
|
+
f"{package}.types.{java_common.INTERFACE_PKG}.{interface_name}"
|
|
583
|
+
)
|
|
584
|
+
|
|
585
|
+
imports.append(interface_import)
|
|
586
|
+
|
|
587
|
+
if any(prop for prop in cls.properties if prop.specified_for is cls):
|
|
588
|
+
imports.extend(
|
|
589
|
+
[
|
|
590
|
+
Stripped("java.util.Collections"),
|
|
591
|
+
Stripped("java.util.List"),
|
|
592
|
+
Stripped("java.util.Objects"),
|
|
593
|
+
]
|
|
594
|
+
)
|
|
595
|
+
|
|
596
|
+
return Stripped("\n".join(map(lambda imp: f"import {imp};", imports)))
|
|
597
|
+
|
|
598
|
+
|
|
599
|
+
@ensure(lambda result: (result[0] is None) ^ (result[1] is None))
|
|
600
|
+
def _generate_interface(
|
|
601
|
+
cls: intermediate.ClassUnion, package: java_common.PackageIdentifier
|
|
602
|
+
) -> Tuple[Optional[Stripped], Optional[Error]]:
|
|
603
|
+
"""
|
|
604
|
+
Generate Java interface for the given class ``cls``.
|
|
605
|
+
|
|
606
|
+
The ``package`` defines the root Java package.
|
|
607
|
+
"""
|
|
608
|
+
writer = io.StringIO()
|
|
609
|
+
|
|
610
|
+
if cls.description is not None:
|
|
611
|
+
comment, comment_errors = java_description.generate_comment_for_our_type(
|
|
612
|
+
description=cls.description,
|
|
613
|
+
context=java_description.Context(package=package, cls_or_enum=cls),
|
|
614
|
+
)
|
|
615
|
+
|
|
616
|
+
if comment_errors is not None:
|
|
617
|
+
return None, Error(
|
|
618
|
+
cls.description.parsed.node,
|
|
619
|
+
"Failed to generate the documentation comment",
|
|
620
|
+
comment_errors,
|
|
621
|
+
)
|
|
622
|
+
|
|
623
|
+
assert comment is not None
|
|
624
|
+
|
|
625
|
+
writer.write(comment)
|
|
626
|
+
writer.write("\n")
|
|
627
|
+
|
|
628
|
+
name = java_naming.interface_name(cls.name)
|
|
629
|
+
|
|
630
|
+
inheritances = [inheritance.name for inheritance in cls.inheritances]
|
|
631
|
+
if len(inheritances) == 0:
|
|
632
|
+
inheritances = [Identifier("Class")]
|
|
633
|
+
|
|
634
|
+
inheritance_names = list(map(java_naming.interface_name, inheritances))
|
|
635
|
+
|
|
636
|
+
assert len(inheritances) > 0
|
|
637
|
+
if len(inheritances) == 1:
|
|
638
|
+
writer.write(
|
|
639
|
+
f"""\
|
|
640
|
+
public interface {name} extends {inheritance_names[0]} {{\n"""
|
|
641
|
+
)
|
|
642
|
+
else:
|
|
643
|
+
writer.write(
|
|
644
|
+
f"""
|
|
645
|
+
public interface {name} extends\n"""
|
|
646
|
+
)
|
|
647
|
+
for i, inheritance_name in enumerate(inheritance_names):
|
|
648
|
+
if i > 0:
|
|
649
|
+
writer.write(",\n")
|
|
650
|
+
|
|
651
|
+
writer.write(textwrap.indent(inheritance_name, II))
|
|
652
|
+
|
|
653
|
+
writer.write(" {\n")
|
|
654
|
+
|
|
655
|
+
# Code blocks separated by double newlines and indented once
|
|
656
|
+
blocks = [] # type: List[Stripped]
|
|
657
|
+
|
|
658
|
+
# region Getters and setters
|
|
659
|
+
|
|
660
|
+
for prop in cls.properties:
|
|
661
|
+
if prop.specified_for is not cls:
|
|
662
|
+
continue
|
|
663
|
+
|
|
664
|
+
type_anno = intermediate.beneath_optional(prop.type_annotation)
|
|
665
|
+
|
|
666
|
+
prop_type = java_common.generate_type(type_annotation=prop.type_annotation)
|
|
667
|
+
arg_type = java_common.generate_type(type_annotation=type_anno)
|
|
668
|
+
|
|
669
|
+
prop_name = java_naming.property_name(prop.name)
|
|
670
|
+
|
|
671
|
+
getter_name = java_naming.getter_name(prop.name)
|
|
672
|
+
setter_name = java_naming.setter_name(prop.name)
|
|
673
|
+
|
|
674
|
+
if prop.description is not None:
|
|
675
|
+
(
|
|
676
|
+
prop_comment,
|
|
677
|
+
prop_comment_errors,
|
|
678
|
+
) = java_description.generate_comment_for_property(
|
|
679
|
+
description=prop.description,
|
|
680
|
+
context=java_description.Context(package=package, cls_or_enum=cls),
|
|
681
|
+
)
|
|
682
|
+
|
|
683
|
+
if prop_comment_errors is not None:
|
|
684
|
+
return None, Error(
|
|
685
|
+
prop.description.parsed.node,
|
|
686
|
+
f"Failed to generate the documentation comment "
|
|
687
|
+
f"for the property {prop.name!r}",
|
|
688
|
+
prop_comment_errors,
|
|
689
|
+
)
|
|
690
|
+
|
|
691
|
+
blocks.append(Stripped(f"{prop_comment}\n{prop_type} {getter_name}();"))
|
|
692
|
+
else:
|
|
693
|
+
blocks.append(Stripped(f"{prop_type} {getter_name}();"))
|
|
694
|
+
|
|
695
|
+
blocks.append(Stripped(f"void {setter_name}({arg_type} {prop_name});"))
|
|
696
|
+
|
|
697
|
+
# endregion
|
|
698
|
+
|
|
699
|
+
# region Signatures
|
|
700
|
+
|
|
701
|
+
for method in cls.methods:
|
|
702
|
+
if method.specified_for is not cls:
|
|
703
|
+
continue
|
|
704
|
+
|
|
705
|
+
signature_blocks = [] # type: List[Stripped]
|
|
706
|
+
|
|
707
|
+
if method.description is not None:
|
|
708
|
+
(
|
|
709
|
+
signature_comment,
|
|
710
|
+
signature_comment_errors,
|
|
711
|
+
) = java_description.generate_comment_for_signature(
|
|
712
|
+
description=method.description,
|
|
713
|
+
context=java_description.Context(package=package, cls_or_enum=cls),
|
|
714
|
+
)
|
|
715
|
+
|
|
716
|
+
if signature_comment_errors is not None:
|
|
717
|
+
return None, Error(
|
|
718
|
+
method.description.parsed.node,
|
|
719
|
+
f"Failed to generate the documentation comment "
|
|
720
|
+
f"for the method {method.name!r}",
|
|
721
|
+
signature_comment_errors,
|
|
722
|
+
)
|
|
723
|
+
|
|
724
|
+
assert signature_comment is not None
|
|
725
|
+
|
|
726
|
+
signature_blocks.append(signature_comment)
|
|
727
|
+
|
|
728
|
+
# fmt: off
|
|
729
|
+
returns = (
|
|
730
|
+
java_common.generate_type(type_annotation=method.returns)
|
|
731
|
+
if method.returns is not None else "void"
|
|
732
|
+
)
|
|
733
|
+
# fmt: on
|
|
734
|
+
|
|
735
|
+
arg_codes = [] # type: List[Stripped]
|
|
736
|
+
for arg in method.arguments:
|
|
737
|
+
arg_type = java_common.generate_type(type_annotation=arg.type_annotation)
|
|
738
|
+
arg_name = java_naming.argument_name(arg.name)
|
|
739
|
+
arg_codes.append(Stripped(f"{arg_type} {arg_name}"))
|
|
740
|
+
|
|
741
|
+
signature_name = java_naming.method_name(method.name)
|
|
742
|
+
if len(arg_codes) > 2:
|
|
743
|
+
arg_block = ",\n".join(arg_codes)
|
|
744
|
+
arg_block_indented = textwrap.indent(arg_block, I)
|
|
745
|
+
signature_blocks.append(
|
|
746
|
+
Stripped(f"{returns} {signature_name}(\n{arg_block_indented});")
|
|
747
|
+
)
|
|
748
|
+
elif len(arg_codes) == 1:
|
|
749
|
+
signature_blocks.append(
|
|
750
|
+
Stripped(f"{returns} {signature_name}({arg_codes[0]});")
|
|
751
|
+
)
|
|
752
|
+
else:
|
|
753
|
+
assert len(arg_codes) == 0
|
|
754
|
+
signature_blocks.append(Stripped(f"{returns} {signature_name}();"))
|
|
755
|
+
|
|
756
|
+
blocks.append(Stripped("\n".join(signature_blocks)))
|
|
757
|
+
|
|
758
|
+
for prop in cls.properties:
|
|
759
|
+
if prop.specified_for is not cls:
|
|
760
|
+
continue
|
|
761
|
+
|
|
762
|
+
if isinstance(
|
|
763
|
+
prop.type_annotation, intermediate.OptionalTypeAnnotation
|
|
764
|
+
) and isinstance(prop.type_annotation.value, intermediate.ListTypeAnnotation):
|
|
765
|
+
prop_name = java_naming.property_name(prop.name)
|
|
766
|
+
method_name = f"over{java_naming.class_name(prop.name)}OrEmpty"
|
|
767
|
+
items_type = java_common.generate_type(prop.type_annotation.value.items)
|
|
768
|
+
blocks.append(
|
|
769
|
+
Stripped(
|
|
770
|
+
f"""\
|
|
771
|
+
/**
|
|
772
|
+
* Iterate over {prop_name}, if set, and otherwise return an empty enumerable.
|
|
773
|
+
*/
|
|
774
|
+
Iterable<{items_type}> {method_name}();"""
|
|
775
|
+
)
|
|
776
|
+
)
|
|
777
|
+
|
|
778
|
+
# endregion
|
|
779
|
+
|
|
780
|
+
if len(blocks) == 0:
|
|
781
|
+
blocks = [Stripped("// Intentionally empty.")]
|
|
782
|
+
|
|
783
|
+
for i, code in enumerate(blocks):
|
|
784
|
+
if i > 0:
|
|
785
|
+
writer.write("\n\n")
|
|
786
|
+
|
|
787
|
+
writer.write(textwrap.indent(code, I))
|
|
788
|
+
|
|
789
|
+
writer.write("\n}")
|
|
790
|
+
|
|
791
|
+
return Stripped(writer.getvalue()), None
|
|
792
|
+
|
|
793
|
+
|
|
794
|
+
@require(lambda cls: not cls.is_implementation_specific)
|
|
795
|
+
@require(lambda cls: not cls.constructor.is_implementation_specific)
|
|
796
|
+
@ensure(lambda result: (result[0] is not None) ^ (result[1] is not None))
|
|
797
|
+
def _generate_mandatory_constructor(
|
|
798
|
+
cls: intermediate.ConcreteClass,
|
|
799
|
+
) -> Tuple[Optional[Stripped], Optional[Error]]:
|
|
800
|
+
"""
|
|
801
|
+
Generate a default constructor for the given concrete class ``cls``.
|
|
802
|
+
|
|
803
|
+
Return empty string if there is an empty constructor or no default constructor
|
|
804
|
+
can be constructed.
|
|
805
|
+
"""
|
|
806
|
+
if (
|
|
807
|
+
len(cls.constructor.arguments) == 0
|
|
808
|
+
and len(cls.constructor.inlined_statements) == 0
|
|
809
|
+
):
|
|
810
|
+
return Stripped(""), None
|
|
811
|
+
|
|
812
|
+
if all(
|
|
813
|
+
isinstance(arg.type_annotation, intermediate.OptionalTypeAnnotation)
|
|
814
|
+
for arg in cls.constructor.arguments
|
|
815
|
+
):
|
|
816
|
+
return Stripped(""), None
|
|
817
|
+
|
|
818
|
+
cls_name = java_naming.class_name(cls.name)
|
|
819
|
+
|
|
820
|
+
blocks = [] # type: List[str]
|
|
821
|
+
|
|
822
|
+
arg_codes = [] # type: List[Stripped]
|
|
823
|
+
for arg in cls.constructor.arguments:
|
|
824
|
+
type_anno = arg.type_annotation
|
|
825
|
+
|
|
826
|
+
if isinstance(type_anno, intermediate.OptionalTypeAnnotation):
|
|
827
|
+
continue
|
|
828
|
+
|
|
829
|
+
arg_type = java_common.generate_type(type_annotation=type_anno)
|
|
830
|
+
|
|
831
|
+
arg_name = java_naming.argument_name(arg.name)
|
|
832
|
+
|
|
833
|
+
arg_codes.append(Stripped(f"{arg_type} {arg_name}"))
|
|
834
|
+
|
|
835
|
+
assert len(arg_codes) > 0
|
|
836
|
+
|
|
837
|
+
if len(arg_codes) == 1:
|
|
838
|
+
blocks.append(f"public {cls_name}({arg_codes[0]}) {{")
|
|
839
|
+
else:
|
|
840
|
+
arg_block = ",\n".join(arg_codes)
|
|
841
|
+
arg_block_indented = textwrap.indent(arg_block, I)
|
|
842
|
+
blocks.append(f"public {cls_name}(\n{arg_block_indented}) {{")
|
|
843
|
+
|
|
844
|
+
body = [] # type: List[Stripped]
|
|
845
|
+
|
|
846
|
+
for stmt in cls.constructor.inlined_statements:
|
|
847
|
+
if isinstance(stmt, intermediate_construction.AssignArgument):
|
|
848
|
+
if stmt.default is None:
|
|
849
|
+
prop_name = java_naming.property_name(stmt.name)
|
|
850
|
+
|
|
851
|
+
arg_name = java_naming.argument_name(stmt.argument)
|
|
852
|
+
|
|
853
|
+
if isinstance(
|
|
854
|
+
cls.properties_by_name[stmt.name].type_annotation,
|
|
855
|
+
intermediate.OptionalTypeAnnotation,
|
|
856
|
+
):
|
|
857
|
+
continue
|
|
858
|
+
|
|
859
|
+
assignment = Stripped(
|
|
860
|
+
f"""\
|
|
861
|
+
this.{prop_name} = Objects.requireNonNull(
|
|
862
|
+
{I}{arg_name},
|
|
863
|
+
{I}"Argument \\"{arg_name}\\" must be non-null.");"""
|
|
864
|
+
)
|
|
865
|
+
|
|
866
|
+
body.append(assignment)
|
|
867
|
+
else:
|
|
868
|
+
if isinstance(stmt.default, intermediate_construction.EmptyList):
|
|
869
|
+
prop = cls.properties_by_name[stmt.name]
|
|
870
|
+
|
|
871
|
+
type_anno = intermediate.beneath_optional(prop.type_annotation)
|
|
872
|
+
|
|
873
|
+
prop_type = java_common.generate_type(
|
|
874
|
+
type_annotation=type_anno,
|
|
875
|
+
)
|
|
876
|
+
|
|
877
|
+
prop_name = java_naming.property_name(stmt.name)
|
|
878
|
+
|
|
879
|
+
arg_name = java_naming.argument_name(stmt.argument)
|
|
880
|
+
|
|
881
|
+
# Write the assignment as a ternary operator
|
|
882
|
+
|
|
883
|
+
assignment = Stripped(
|
|
884
|
+
f"""\
|
|
885
|
+
this.{prop_name} = ({arg_name} != null)
|
|
886
|
+
{I}? {arg_name}
|
|
887
|
+
{I}: new {prop_type}();"""
|
|
888
|
+
)
|
|
889
|
+
|
|
890
|
+
body.append(assignment)
|
|
891
|
+
elif isinstance(
|
|
892
|
+
stmt.default, intermediate_construction.DefaultEnumLiteral
|
|
893
|
+
):
|
|
894
|
+
enum_name = java_naming.enum_name(stmt.default.enum.name)
|
|
895
|
+
|
|
896
|
+
enum_literal = java_naming.enum_literal_name(
|
|
897
|
+
stmt.default.literal.name
|
|
898
|
+
)
|
|
899
|
+
|
|
900
|
+
prop_name = java_naming.property_name(stmt.name)
|
|
901
|
+
|
|
902
|
+
arg_name = java_naming.argument_name(stmt.argument)
|
|
903
|
+
|
|
904
|
+
# Write the assignment as a ternary operator
|
|
905
|
+
|
|
906
|
+
body.append(
|
|
907
|
+
Stripped(
|
|
908
|
+
f"""\
|
|
909
|
+
this.{prop_name} = ({arg_name} != null)
|
|
910
|
+
{I}? {arg_name}
|
|
911
|
+
{I}: {enum_name}.{enum_literal};"""
|
|
912
|
+
)
|
|
913
|
+
)
|
|
914
|
+
else:
|
|
915
|
+
assert_never(stmt.default)
|
|
916
|
+
|
|
917
|
+
else:
|
|
918
|
+
assert_never(stmt)
|
|
919
|
+
|
|
920
|
+
blocks.append("\n".join(textwrap.indent(stmt_code, I) for stmt_code in body))
|
|
921
|
+
|
|
922
|
+
blocks.append("}")
|
|
923
|
+
|
|
924
|
+
return Stripped("\n".join(blocks)), None
|
|
925
|
+
|
|
926
|
+
|
|
927
|
+
@require(lambda cls: not cls.is_implementation_specific)
|
|
928
|
+
@require(lambda cls: not cls.constructor.is_implementation_specific)
|
|
929
|
+
@ensure(lambda result: (result[0] is not None) ^ (result[1] is not None))
|
|
930
|
+
def _generate_full_constructor(
|
|
931
|
+
cls: intermediate.ConcreteClass,
|
|
932
|
+
) -> Tuple[Optional[Stripped], Optional[Error]]:
|
|
933
|
+
"""
|
|
934
|
+
Generate the constructor functions for the given concrete class ``cls``.
|
|
935
|
+
|
|
936
|
+
Return empty string if there is an empty constructor.
|
|
937
|
+
"""
|
|
938
|
+
if (
|
|
939
|
+
len(cls.constructor.arguments) == 0
|
|
940
|
+
and len(cls.constructor.inlined_statements) == 0
|
|
941
|
+
):
|
|
942
|
+
return Stripped(""), None
|
|
943
|
+
|
|
944
|
+
if not any(
|
|
945
|
+
isinstance(arg.type_annotation, intermediate.OptionalTypeAnnotation)
|
|
946
|
+
for arg in cls.constructor.arguments
|
|
947
|
+
):
|
|
948
|
+
return Stripped(""), None
|
|
949
|
+
|
|
950
|
+
cls_name = java_naming.class_name(cls.name)
|
|
951
|
+
|
|
952
|
+
blocks = [] # type: List[str]
|
|
953
|
+
|
|
954
|
+
arg_codes = [] # type: List[Stripped]
|
|
955
|
+
for arg in cls.constructor.arguments:
|
|
956
|
+
type_anno = intermediate.beneath_optional(arg.type_annotation)
|
|
957
|
+
|
|
958
|
+
arg_type = java_common.generate_type(type_annotation=type_anno)
|
|
959
|
+
|
|
960
|
+
arg_name = java_naming.argument_name(arg.name)
|
|
961
|
+
|
|
962
|
+
arg_codes.append(Stripped(f"{arg_type} {arg_name}"))
|
|
963
|
+
|
|
964
|
+
if len(arg_codes) == 0:
|
|
965
|
+
blocks.append(f"public {cls_name}() {{")
|
|
966
|
+
elif len(arg_codes) == 1:
|
|
967
|
+
blocks.append(f"public {cls_name}({arg_codes[0]}) {{")
|
|
968
|
+
else:
|
|
969
|
+
arg_block = ",\n".join(arg_codes)
|
|
970
|
+
arg_block_indented = textwrap.indent(arg_block, I)
|
|
971
|
+
blocks.append(f"public {cls_name}(\n{arg_block_indented}) {{")
|
|
972
|
+
|
|
973
|
+
body = [] # type: List[Stripped]
|
|
974
|
+
|
|
975
|
+
for stmt in cls.constructor.inlined_statements:
|
|
976
|
+
if isinstance(stmt, intermediate_construction.AssignArgument):
|
|
977
|
+
if stmt.default is None:
|
|
978
|
+
prop_name = java_naming.property_name(stmt.name)
|
|
979
|
+
|
|
980
|
+
arg_name = java_naming.argument_name(stmt.argument)
|
|
981
|
+
|
|
982
|
+
if isinstance(
|
|
983
|
+
cls.properties_by_name[stmt.name].type_annotation,
|
|
984
|
+
intermediate.OptionalTypeAnnotation,
|
|
985
|
+
):
|
|
986
|
+
assignment = Stripped(f"this.{prop_name} = {arg_name};")
|
|
987
|
+
else:
|
|
988
|
+
assignment = Stripped(
|
|
989
|
+
f"""\
|
|
990
|
+
this.{prop_name} = Objects.requireNonNull(
|
|
991
|
+
{I}{arg_name},
|
|
992
|
+
{I}"Argument \\"{arg_name}\\" must be non-null.");"""
|
|
993
|
+
)
|
|
994
|
+
|
|
995
|
+
body.append(assignment)
|
|
996
|
+
else:
|
|
997
|
+
if isinstance(stmt.default, intermediate_construction.EmptyList):
|
|
998
|
+
prop = cls.properties_by_name[stmt.name]
|
|
999
|
+
|
|
1000
|
+
type_anno = intermediate.beneath_optional(prop.type_annotation)
|
|
1001
|
+
|
|
1002
|
+
prop_type = java_common.generate_type(
|
|
1003
|
+
type_annotation=type_anno,
|
|
1004
|
+
)
|
|
1005
|
+
|
|
1006
|
+
prop_name = java_naming.property_name(stmt.name)
|
|
1007
|
+
|
|
1008
|
+
arg_name = java_naming.argument_name(stmt.argument)
|
|
1009
|
+
|
|
1010
|
+
# Write the assignment as a ternary operator
|
|
1011
|
+
|
|
1012
|
+
assignment = Stripped(
|
|
1013
|
+
f"""\
|
|
1014
|
+
this.{prop_name} = ({arg_name} != null)
|
|
1015
|
+
{I}? {arg_name}
|
|
1016
|
+
{I}: new {prop_type}();"""
|
|
1017
|
+
)
|
|
1018
|
+
|
|
1019
|
+
body.append(assignment)
|
|
1020
|
+
elif isinstance(
|
|
1021
|
+
stmt.default, intermediate_construction.DefaultEnumLiteral
|
|
1022
|
+
):
|
|
1023
|
+
enum_name = java_naming.enum_name(stmt.default.enum.name)
|
|
1024
|
+
|
|
1025
|
+
enum_literal = java_naming.enum_literal_name(
|
|
1026
|
+
stmt.default.literal.name
|
|
1027
|
+
)
|
|
1028
|
+
|
|
1029
|
+
prop_name = java_naming.property_name(stmt.name)
|
|
1030
|
+
|
|
1031
|
+
arg_name = java_naming.argument_name(stmt.argument)
|
|
1032
|
+
|
|
1033
|
+
# Write the assignment as a ternary operator
|
|
1034
|
+
|
|
1035
|
+
body.append(
|
|
1036
|
+
Stripped(
|
|
1037
|
+
f"""\
|
|
1038
|
+
this.{prop_name} = ({arg_name} != null)
|
|
1039
|
+
{I}? {arg_name}
|
|
1040
|
+
{I}: {enum_name}.{enum_literal};"""
|
|
1041
|
+
)
|
|
1042
|
+
)
|
|
1043
|
+
else:
|
|
1044
|
+
assert_never(stmt.default)
|
|
1045
|
+
|
|
1046
|
+
else:
|
|
1047
|
+
assert_never(stmt)
|
|
1048
|
+
|
|
1049
|
+
blocks.append("\n".join(textwrap.indent(stmt_code, I) for stmt_code in body))
|
|
1050
|
+
|
|
1051
|
+
blocks.append(Stripped("}"))
|
|
1052
|
+
|
|
1053
|
+
return Stripped("\n".join(blocks)), None
|
|
1054
|
+
|
|
1055
|
+
|
|
1056
|
+
# fmt: off
|
|
1057
|
+
@ensure(lambda result: (result[0] is None) ^ (result[1] is None))
|
|
1058
|
+
# fmt: on
|
|
1059
|
+
def _generate_class(
|
|
1060
|
+
cls: intermediate.ConcreteClass,
|
|
1061
|
+
spec_impls: specific_implementations.SpecificImplementations,
|
|
1062
|
+
package: java_common.PackageIdentifier,
|
|
1063
|
+
) -> Tuple[Optional[Stripped], Optional[Error]]:
|
|
1064
|
+
"""
|
|
1065
|
+
Generate Java code for the class ``cls``.
|
|
1066
|
+
|
|
1067
|
+
The ``package`` defines the root Java package.
|
|
1068
|
+
"""
|
|
1069
|
+
# Code blocks to be later joined by double newlines and indented once
|
|
1070
|
+
|
|
1071
|
+
blocks = [] # type: List[Stripped]
|
|
1072
|
+
|
|
1073
|
+
errors = [] # type: List[Error]
|
|
1074
|
+
|
|
1075
|
+
descendable = _has_descendable_properties(cls)
|
|
1076
|
+
|
|
1077
|
+
# region Properties
|
|
1078
|
+
|
|
1079
|
+
for prop in cls.properties:
|
|
1080
|
+
type_anno = intermediate.beneath_optional(prop.type_annotation)
|
|
1081
|
+
|
|
1082
|
+
prop_type = java_common.generate_type(type_annotation=type_anno)
|
|
1083
|
+
|
|
1084
|
+
prop_name = java_naming.property_name(prop.name)
|
|
1085
|
+
|
|
1086
|
+
prop_blocks = [] # type: List[Stripped]
|
|
1087
|
+
|
|
1088
|
+
if prop.description is not None:
|
|
1089
|
+
(
|
|
1090
|
+
prop_comment,
|
|
1091
|
+
prop_comment_errors,
|
|
1092
|
+
) = java_description.generate_comment_for_property(
|
|
1093
|
+
description=prop.description,
|
|
1094
|
+
context=java_description.Context(package=package, cls_or_enum=cls),
|
|
1095
|
+
)
|
|
1096
|
+
if prop_comment_errors:
|
|
1097
|
+
return None, Error(
|
|
1098
|
+
prop.description.parsed.node,
|
|
1099
|
+
f"Failed to generate the documentation comment "
|
|
1100
|
+
f"for the property {prop.name!r}",
|
|
1101
|
+
prop_comment_errors,
|
|
1102
|
+
)
|
|
1103
|
+
|
|
1104
|
+
assert prop_comment is not None
|
|
1105
|
+
|
|
1106
|
+
prop_blocks.append(prop_comment)
|
|
1107
|
+
|
|
1108
|
+
prop_blocks.append(
|
|
1109
|
+
Stripped(
|
|
1110
|
+
f"""\
|
|
1111
|
+
private {prop_type} {prop_name};"""
|
|
1112
|
+
)
|
|
1113
|
+
)
|
|
1114
|
+
|
|
1115
|
+
blocks.append(Stripped("\n".join(prop_blocks)))
|
|
1116
|
+
|
|
1117
|
+
# endregion
|
|
1118
|
+
|
|
1119
|
+
# region Methods
|
|
1120
|
+
|
|
1121
|
+
# region Constructor
|
|
1122
|
+
|
|
1123
|
+
if cls.constructor.is_implementation_specific:
|
|
1124
|
+
implementation_key = specific_implementations.ImplementationKey(
|
|
1125
|
+
f"Types/{cls.name}/{cls.name}.java"
|
|
1126
|
+
)
|
|
1127
|
+
implementation = spec_impls.get(implementation_key, None)
|
|
1128
|
+
|
|
1129
|
+
if implementation is None:
|
|
1130
|
+
errors.append(
|
|
1131
|
+
Error(
|
|
1132
|
+
cls.parsed.node,
|
|
1133
|
+
f"The implementation of the implementation-specific constructor "
|
|
1134
|
+
f"is missing: {implementation_key}",
|
|
1135
|
+
)
|
|
1136
|
+
)
|
|
1137
|
+
else:
|
|
1138
|
+
blocks.append(implementation)
|
|
1139
|
+
else:
|
|
1140
|
+
mandatory_constructor_block, error = _generate_mandatory_constructor(cls=cls)
|
|
1141
|
+
|
|
1142
|
+
if error is not None:
|
|
1143
|
+
errors.append(error)
|
|
1144
|
+
else:
|
|
1145
|
+
if mandatory_constructor_block != "":
|
|
1146
|
+
assert mandatory_constructor_block is not None
|
|
1147
|
+
blocks.append(mandatory_constructor_block)
|
|
1148
|
+
|
|
1149
|
+
full_constructor_block, error = _generate_full_constructor(cls=cls)
|
|
1150
|
+
|
|
1151
|
+
if error is not None:
|
|
1152
|
+
errors.append(error)
|
|
1153
|
+
else:
|
|
1154
|
+
if full_constructor_block != "":
|
|
1155
|
+
assert full_constructor_block is not None
|
|
1156
|
+
blocks.append(full_constructor_block)
|
|
1157
|
+
|
|
1158
|
+
# endregion
|
|
1159
|
+
|
|
1160
|
+
# region Getters and setters
|
|
1161
|
+
|
|
1162
|
+
for prop in cls.properties:
|
|
1163
|
+
type_anno = intermediate.beneath_optional(prop.type_annotation)
|
|
1164
|
+
|
|
1165
|
+
prop_type = java_common.generate_type(type_annotation=prop.type_annotation)
|
|
1166
|
+
|
|
1167
|
+
arg_type = java_common.generate_type(type_annotation=type_anno)
|
|
1168
|
+
|
|
1169
|
+
prop_name = java_naming.property_name(prop.name)
|
|
1170
|
+
|
|
1171
|
+
getter_name = java_naming.getter_name(prop.name)
|
|
1172
|
+
setter_name = java_naming.setter_name(prop.name)
|
|
1173
|
+
|
|
1174
|
+
get_set_blocks = [] # type: List[Stripped]
|
|
1175
|
+
|
|
1176
|
+
if isinstance(prop.type_annotation, intermediate.OptionalTypeAnnotation):
|
|
1177
|
+
get_set_blocks.append(
|
|
1178
|
+
Stripped(
|
|
1179
|
+
f"""\
|
|
1180
|
+
@Override
|
|
1181
|
+
public {prop_type} {getter_name}() {{
|
|
1182
|
+
{I}return Optional.ofNullable({prop_name});
|
|
1183
|
+
}}"""
|
|
1184
|
+
)
|
|
1185
|
+
)
|
|
1186
|
+
|
|
1187
|
+
get_set_blocks.append(
|
|
1188
|
+
Stripped(
|
|
1189
|
+
f"""\
|
|
1190
|
+
@Override
|
|
1191
|
+
public void {setter_name}({arg_type} {prop_name}) {{
|
|
1192
|
+
{I}this.{prop_name} = {prop_name};
|
|
1193
|
+
}}"""
|
|
1194
|
+
)
|
|
1195
|
+
)
|
|
1196
|
+
else:
|
|
1197
|
+
get_set_blocks.append(
|
|
1198
|
+
Stripped(
|
|
1199
|
+
f"""\
|
|
1200
|
+
@Override
|
|
1201
|
+
public {prop_type} {getter_name}() {{
|
|
1202
|
+
{I}return {prop_name};
|
|
1203
|
+
}}"""
|
|
1204
|
+
)
|
|
1205
|
+
)
|
|
1206
|
+
|
|
1207
|
+
get_set_blocks.append(
|
|
1208
|
+
Stripped(
|
|
1209
|
+
f"""\
|
|
1210
|
+
@Override
|
|
1211
|
+
public void {setter_name}({arg_type} {prop_name}) {{
|
|
1212
|
+
{I}this.{prop_name} = Objects.requireNonNull(
|
|
1213
|
+
{II}{prop_name},
|
|
1214
|
+
{II}"Argument \\"{prop_name}\\" must be non-null.");
|
|
1215
|
+
}}"""
|
|
1216
|
+
)
|
|
1217
|
+
)
|
|
1218
|
+
|
|
1219
|
+
blocks.append(Stripped("\n\n".join(get_set_blocks)))
|
|
1220
|
+
|
|
1221
|
+
# endregion
|
|
1222
|
+
|
|
1223
|
+
# region OverXOrEmpty getter
|
|
1224
|
+
|
|
1225
|
+
cls_name = java_naming.class_name(cls.name)
|
|
1226
|
+
|
|
1227
|
+
for prop in cls.properties:
|
|
1228
|
+
if isinstance(
|
|
1229
|
+
prop.type_annotation, intermediate.OptionalTypeAnnotation
|
|
1230
|
+
) and isinstance(prop.type_annotation.value, intermediate.ListTypeAnnotation):
|
|
1231
|
+
prop_name = java_naming.property_name(prop.name)
|
|
1232
|
+
method_name = f"over{java_naming.class_name(prop.name)}OrEmpty"
|
|
1233
|
+
getter_name = java_naming.getter_name(prop.name)
|
|
1234
|
+
items_type = java_common.generate_type(prop.type_annotation.value.items)
|
|
1235
|
+
|
|
1236
|
+
blocks.append(
|
|
1237
|
+
Stripped(
|
|
1238
|
+
f"""\
|
|
1239
|
+
/**
|
|
1240
|
+
* Iterate over {{@link {cls_name}#{prop_name}}}, if set,
|
|
1241
|
+
* and otherwise return an empty iterator.
|
|
1242
|
+
*/
|
|
1243
|
+
public Iterable<{items_type}> {method_name}() {{
|
|
1244
|
+
{I}return {getter_name}().orElseGet(Collections::emptyList);
|
|
1245
|
+
}}"""
|
|
1246
|
+
)
|
|
1247
|
+
)
|
|
1248
|
+
|
|
1249
|
+
# endregion
|
|
1250
|
+
|
|
1251
|
+
# region Public methods
|
|
1252
|
+
|
|
1253
|
+
for method in cls.methods:
|
|
1254
|
+
if isinstance(method, intermediate.ImplementationSpecificMethod):
|
|
1255
|
+
implementation_key = specific_implementations.ImplementationKey(
|
|
1256
|
+
f"Types/{method.specified_for.name}/{method.name}.java"
|
|
1257
|
+
)
|
|
1258
|
+
|
|
1259
|
+
implementation = spec_impls.get(implementation_key, None)
|
|
1260
|
+
|
|
1261
|
+
if implementation is None:
|
|
1262
|
+
errors.append(
|
|
1263
|
+
Error(
|
|
1264
|
+
method.parsed.node,
|
|
1265
|
+
f"The implementation is missing for "
|
|
1266
|
+
f"the implementation-specific method: {implementation_key}",
|
|
1267
|
+
)
|
|
1268
|
+
)
|
|
1269
|
+
continue
|
|
1270
|
+
|
|
1271
|
+
blocks.append(implementation)
|
|
1272
|
+
else:
|
|
1273
|
+
errors.append(
|
|
1274
|
+
Error(
|
|
1275
|
+
cls.parsed.node,
|
|
1276
|
+
"At the moment, we do not transpile the method body and "
|
|
1277
|
+
"its contracts. We want to finish the meta-model for the V3 and "
|
|
1278
|
+
"fix de/serialization before taking on this rather hard task.",
|
|
1279
|
+
)
|
|
1280
|
+
)
|
|
1281
|
+
|
|
1282
|
+
visit_name = java_naming.method_name(Identifier(f"visit_{cls.name}"))
|
|
1283
|
+
|
|
1284
|
+
blocks.append(_generate_descend_method(cls=cls, descendable=descendable))
|
|
1285
|
+
blocks.append(_generate_descend_once_method(cls=cls, descendable=descendable))
|
|
1286
|
+
blocks.append(
|
|
1287
|
+
Stripped(
|
|
1288
|
+
f"""\
|
|
1289
|
+
/**
|
|
1290
|
+
* Accept the {{@code visitor}} to visit this instance for double dispatch.
|
|
1291
|
+
**/
|
|
1292
|
+
@Override
|
|
1293
|
+
public void accept(IVisitor visitor) {{
|
|
1294
|
+
{I}visitor.{visit_name}(this);
|
|
1295
|
+
}}"""
|
|
1296
|
+
)
|
|
1297
|
+
)
|
|
1298
|
+
|
|
1299
|
+
blocks.append(
|
|
1300
|
+
Stripped(
|
|
1301
|
+
f"""\
|
|
1302
|
+
/**
|
|
1303
|
+
* Accept the {{@code visitor}} to visit this instance for double dispatch
|
|
1304
|
+
* with the {{@code context}}.
|
|
1305
|
+
**/
|
|
1306
|
+
@Override
|
|
1307
|
+
public <ContextT> void accept(
|
|
1308
|
+
{II}IVisitorWithContext<ContextT> visitor,
|
|
1309
|
+
{II}ContextT context) {{
|
|
1310
|
+
{I}visitor.{visit_name}(this, context);
|
|
1311
|
+
}}"""
|
|
1312
|
+
)
|
|
1313
|
+
)
|
|
1314
|
+
|
|
1315
|
+
transform_name = java_naming.method_name(Identifier(f"transform_{cls.name}"))
|
|
1316
|
+
|
|
1317
|
+
blocks.append(
|
|
1318
|
+
Stripped(
|
|
1319
|
+
f"""\
|
|
1320
|
+
/**
|
|
1321
|
+
* Accept the {{@code transformer}} to visit this instance for double dispatch.
|
|
1322
|
+
**/
|
|
1323
|
+
@Override
|
|
1324
|
+
public <T> T transform(ITransformer<T> transformer) {{
|
|
1325
|
+
{I}return transformer.{transform_name}(this);
|
|
1326
|
+
}}"""
|
|
1327
|
+
)
|
|
1328
|
+
)
|
|
1329
|
+
|
|
1330
|
+
blocks.append(
|
|
1331
|
+
Stripped(
|
|
1332
|
+
f"""\
|
|
1333
|
+
/**
|
|
1334
|
+
* Accept the {{@code transformer}} to visit this instance for double dispatch
|
|
1335
|
+
* with the {{@code context}}.
|
|
1336
|
+
**/
|
|
1337
|
+
@Override
|
|
1338
|
+
public <ContextT, T> T transform(
|
|
1339
|
+
{II}ITransformerWithContext<ContextT, T> transformer,
|
|
1340
|
+
{II}ContextT context) {{
|
|
1341
|
+
{I}return transformer.{transform_name}(this, context);
|
|
1342
|
+
}}"""
|
|
1343
|
+
)
|
|
1344
|
+
)
|
|
1345
|
+
|
|
1346
|
+
# endregion
|
|
1347
|
+
|
|
1348
|
+
# endregion
|
|
1349
|
+
|
|
1350
|
+
# region Inner classes
|
|
1351
|
+
|
|
1352
|
+
if descendable:
|
|
1353
|
+
blocks.append(_generate_descend_iterable(cls=cls, recursive=False))
|
|
1354
|
+
|
|
1355
|
+
blocks.append(_generate_descend_iterable(cls=cls, recursive=True))
|
|
1356
|
+
|
|
1357
|
+
# endregion
|
|
1358
|
+
|
|
1359
|
+
if len(errors) > 0:
|
|
1360
|
+
return None, Error(
|
|
1361
|
+
cls.parsed.node,
|
|
1362
|
+
f"Failed to generate the code for the class {cls.name}",
|
|
1363
|
+
errors,
|
|
1364
|
+
)
|
|
1365
|
+
|
|
1366
|
+
interface_name = java_naming.interface_name(cls.name)
|
|
1367
|
+
|
|
1368
|
+
name = java_naming.class_name(cls.name)
|
|
1369
|
+
|
|
1370
|
+
writer = io.StringIO()
|
|
1371
|
+
|
|
1372
|
+
if cls.description is not None:
|
|
1373
|
+
comment, comment_errors = java_description.generate_comment_for_our_type(
|
|
1374
|
+
description=cls.description,
|
|
1375
|
+
context=java_description.Context(package=package, cls_or_enum=cls),
|
|
1376
|
+
)
|
|
1377
|
+
if comment_errors is not None:
|
|
1378
|
+
return None, Error(
|
|
1379
|
+
cls.description.parsed.node,
|
|
1380
|
+
"Failed to generate the comment description",
|
|
1381
|
+
comment_errors,
|
|
1382
|
+
)
|
|
1383
|
+
|
|
1384
|
+
assert comment is not None
|
|
1385
|
+
|
|
1386
|
+
writer.write(comment)
|
|
1387
|
+
writer.write("\n")
|
|
1388
|
+
|
|
1389
|
+
writer.write(
|
|
1390
|
+
f"""\
|
|
1391
|
+
public class {name} implements {interface_name} {{\n"""
|
|
1392
|
+
)
|
|
1393
|
+
|
|
1394
|
+
for i, block in enumerate(blocks):
|
|
1395
|
+
if i > 0:
|
|
1396
|
+
writer.write("\n\n")
|
|
1397
|
+
|
|
1398
|
+
writer.write(textwrap.indent(block, I))
|
|
1399
|
+
|
|
1400
|
+
writer.write("\n}")
|
|
1401
|
+
|
|
1402
|
+
return Stripped(writer.getvalue()), None
|
|
1403
|
+
|
|
1404
|
+
|
|
1405
|
+
@ensure(lambda result: (result[0] is None) ^ (result[1] is None))
|
|
1406
|
+
def _generate_enum(
|
|
1407
|
+
enum: intermediate.Enumeration, package: java_common.PackageIdentifier
|
|
1408
|
+
) -> Tuple[Optional[Stripped], Optional[Error]]:
|
|
1409
|
+
"""
|
|
1410
|
+
Generate Java code for the enumeration `enum`.
|
|
1411
|
+
|
|
1412
|
+
The ``package`` defines the root Java package.
|
|
1413
|
+
"""
|
|
1414
|
+
writer = io.StringIO()
|
|
1415
|
+
|
|
1416
|
+
if enum.description is not None:
|
|
1417
|
+
comment, comment_errors = java_description.generate_comment_for_our_type(
|
|
1418
|
+
description=enum.description,
|
|
1419
|
+
context=java_description.Context(package=package, cls_or_enum=enum),
|
|
1420
|
+
)
|
|
1421
|
+
if comment_errors:
|
|
1422
|
+
return None, Error(
|
|
1423
|
+
enum.description.parsed.node,
|
|
1424
|
+
"Failed to generate the documentation comment",
|
|
1425
|
+
comment_errors,
|
|
1426
|
+
)
|
|
1427
|
+
|
|
1428
|
+
assert comment is not None
|
|
1429
|
+
|
|
1430
|
+
writer.write(comment)
|
|
1431
|
+
writer.write("\n")
|
|
1432
|
+
|
|
1433
|
+
name = java_naming.enum_name(enum.name)
|
|
1434
|
+
if len(enum.literals) == 0:
|
|
1435
|
+
writer.write(
|
|
1436
|
+
f"""\
|
|
1437
|
+
public enum {name} {{\n}}"""
|
|
1438
|
+
)
|
|
1439
|
+
return Stripped(writer.getvalue()), None
|
|
1440
|
+
|
|
1441
|
+
writer.write(
|
|
1442
|
+
f"""\
|
|
1443
|
+
public enum {name} {{\n"""
|
|
1444
|
+
)
|
|
1445
|
+
for i, literal in enumerate(enum.literals):
|
|
1446
|
+
if i > 0:
|
|
1447
|
+
writer.write(",\n")
|
|
1448
|
+
|
|
1449
|
+
if literal.description:
|
|
1450
|
+
(
|
|
1451
|
+
literal_comment,
|
|
1452
|
+
literal_comment_errors,
|
|
1453
|
+
) = java_description.generate_comment_for_enumeration_literal(
|
|
1454
|
+
description=literal.description,
|
|
1455
|
+
context=java_description.Context(package=package, cls_or_enum=enum),
|
|
1456
|
+
)
|
|
1457
|
+
|
|
1458
|
+
if literal_comment_errors:
|
|
1459
|
+
return None, Error(
|
|
1460
|
+
literal.description.parsed.node,
|
|
1461
|
+
f"Failed to generate the comment "
|
|
1462
|
+
f"for the enumeration literal {literal.name!r}",
|
|
1463
|
+
literal_comment_errors,
|
|
1464
|
+
)
|
|
1465
|
+
|
|
1466
|
+
assert literal_comment is not None
|
|
1467
|
+
|
|
1468
|
+
writer.write(textwrap.indent(literal_comment, I))
|
|
1469
|
+
writer.write("\n")
|
|
1470
|
+
|
|
1471
|
+
writer.write(
|
|
1472
|
+
textwrap.indent(
|
|
1473
|
+
f"{java_naming.enum_literal_name(literal.name)}",
|
|
1474
|
+
I,
|
|
1475
|
+
)
|
|
1476
|
+
)
|
|
1477
|
+
|
|
1478
|
+
writer.write("\n}")
|
|
1479
|
+
|
|
1480
|
+
return Stripped(writer.getvalue()), None
|
|
1481
|
+
|
|
1482
|
+
|
|
1483
|
+
@require(lambda file_name: file_name.endswith(".java"))
|
|
1484
|
+
def _generate_java_file(
|
|
1485
|
+
file_name: Stripped,
|
|
1486
|
+
imports: Optional[Stripped],
|
|
1487
|
+
code: Stripped,
|
|
1488
|
+
package: java_common.PackageIdentifier,
|
|
1489
|
+
) -> java_common.JavaFile:
|
|
1490
|
+
writer = io.StringIO()
|
|
1491
|
+
|
|
1492
|
+
writer.write(
|
|
1493
|
+
f"""\
|
|
1494
|
+
{java_common.WARNING}
|
|
1495
|
+
|
|
1496
|
+
package {package};\n\n"""
|
|
1497
|
+
)
|
|
1498
|
+
|
|
1499
|
+
if imports is not None and len(imports) > 0:
|
|
1500
|
+
writer.write(f"{imports}")
|
|
1501
|
+
writer.write("\n\n")
|
|
1502
|
+
|
|
1503
|
+
writer.write(
|
|
1504
|
+
f"""\
|
|
1505
|
+
{code}
|
|
1506
|
+
|
|
1507
|
+
{java_common.WARNING}
|
|
1508
|
+
"""
|
|
1509
|
+
)
|
|
1510
|
+
|
|
1511
|
+
file_content = writer.getvalue()
|
|
1512
|
+
|
|
1513
|
+
return java_common.JavaFile(file_name, file_content)
|
|
1514
|
+
|
|
1515
|
+
|
|
1516
|
+
def _generate_iclass(
|
|
1517
|
+
package: java_common.PackageIdentifier,
|
|
1518
|
+
) -> java_common.JavaFile:
|
|
1519
|
+
structure_name = Stripped("IClass")
|
|
1520
|
+
file_name = java_common.interface_package_path(structure_name)
|
|
1521
|
+
file_content = f"""\
|
|
1522
|
+
{java_common.WARNING}
|
|
1523
|
+
|
|
1524
|
+
package {package}.types.model;
|
|
1525
|
+
|
|
1526
|
+
import {package}.visitation.ITransformer;
|
|
1527
|
+
import {package}.visitation.ITransformerWithContext;
|
|
1528
|
+
import {package}.visitation.IVisitor;
|
|
1529
|
+
import {package}.visitation.IVisitorWithContext;
|
|
1530
|
+
import java.lang.Iterable;
|
|
1531
|
+
|
|
1532
|
+
/**
|
|
1533
|
+
* Represent a general class of an AAS model.
|
|
1534
|
+
*/
|
|
1535
|
+
public interface IClass {{
|
|
1536
|
+
{I}/**
|
|
1537
|
+
{I} * Iterate over all the class instances referenced from this instance
|
|
1538
|
+
{I} * without further recursion.
|
|
1539
|
+
{I} */
|
|
1540
|
+
{I}Iterable<IClass> descendOnce();
|
|
1541
|
+
|
|
1542
|
+
{I}/**
|
|
1543
|
+
{I} * Iterate recursively over all the class instances referenced from this instance.
|
|
1544
|
+
{I} */
|
|
1545
|
+
{I}Iterable<IClass> descend();
|
|
1546
|
+
|
|
1547
|
+
{I}/**
|
|
1548
|
+
{I} * Accept the {{@code visitor}} to visit this instance
|
|
1549
|
+
{I} * for double dispatch.
|
|
1550
|
+
{I} */
|
|
1551
|
+
{I}void accept(IVisitor visitor);
|
|
1552
|
+
|
|
1553
|
+
{I}/**
|
|
1554
|
+
{I} * Accept the visitor to visit this instance for double dispatch
|
|
1555
|
+
{I} * with the {{@code context}}.
|
|
1556
|
+
{I} */
|
|
1557
|
+
{I}<ContextT> void accept(
|
|
1558
|
+
{III}IVisitorWithContext<ContextT> visitor,
|
|
1559
|
+
{III}ContextT context);
|
|
1560
|
+
|
|
1561
|
+
{I}/**
|
|
1562
|
+
{I} * Accept the {{@code transformer}} to transform this instance
|
|
1563
|
+
{I} * for double dispatch.
|
|
1564
|
+
{I} */
|
|
1565
|
+
{I}<T> T transform(ITransformer<T> transformer);
|
|
1566
|
+
|
|
1567
|
+
{I}/**
|
|
1568
|
+
{I} * Accept the {{@code transformer}} to visit this instance
|
|
1569
|
+
{I} * for double dispatch with the {{@code context}}.
|
|
1570
|
+
{I} */
|
|
1571
|
+
{I}<ContextT, T> T transform(
|
|
1572
|
+
{III}ITransformerWithContext<ContextT, T> transformer,
|
|
1573
|
+
{III}ContextT context);
|
|
1574
|
+
}}
|
|
1575
|
+
|
|
1576
|
+
{java_common.WARNING}\n"""
|
|
1577
|
+
|
|
1578
|
+
return java_common.JavaFile(file_name, file_content)
|
|
1579
|
+
|
|
1580
|
+
|
|
1581
|
+
# fmt: off
|
|
1582
|
+
@ensure(lambda result: (result[0] is not None) ^ (result[1] is not None))
|
|
1583
|
+
# fmt: on
|
|
1584
|
+
def _generate_structure(
|
|
1585
|
+
our_type: intermediate.OurType,
|
|
1586
|
+
package: java_common.PackageIdentifier,
|
|
1587
|
+
spec_impls: specific_implementations.SpecificImplementations,
|
|
1588
|
+
) -> Tuple[Optional[List[java_common.JavaFile]], Optional[Error]]:
|
|
1589
|
+
"""
|
|
1590
|
+
Generate the Java code for a single structure.
|
|
1591
|
+
|
|
1592
|
+
The ``package`` defines the root Java package.
|
|
1593
|
+
"""
|
|
1594
|
+
assert isinstance(
|
|
1595
|
+
our_type,
|
|
1596
|
+
(
|
|
1597
|
+
intermediate.Enumeration,
|
|
1598
|
+
intermediate.AbstractClass,
|
|
1599
|
+
intermediate.ConcreteClass,
|
|
1600
|
+
),
|
|
1601
|
+
)
|
|
1602
|
+
|
|
1603
|
+
files = [] # List[java_common.JavaFile]
|
|
1604
|
+
|
|
1605
|
+
if isinstance(our_type, intermediate.Class) and our_type.is_implementation_specific:
|
|
1606
|
+
implementation_key = specific_implementations.ImplementationKey(
|
|
1607
|
+
f"Types/{our_type.name}.java"
|
|
1608
|
+
)
|
|
1609
|
+
|
|
1610
|
+
imports = _generate_imports_for_class(cls=our_type, package=package)
|
|
1611
|
+
|
|
1612
|
+
code = spec_impls.get(implementation_key, None)
|
|
1613
|
+
if code is None:
|
|
1614
|
+
return None, Error(
|
|
1615
|
+
our_type.parsed.node,
|
|
1616
|
+
f"The implementation is missing "
|
|
1617
|
+
f"for the implementation-specific class: {implementation_key}",
|
|
1618
|
+
)
|
|
1619
|
+
|
|
1620
|
+
structure_name = java_naming.class_name(our_type.name)
|
|
1621
|
+
|
|
1622
|
+
package_name = java_common.PackageIdentifier(
|
|
1623
|
+
f"{package}.types.{java_common.CLASS_PKG}"
|
|
1624
|
+
)
|
|
1625
|
+
|
|
1626
|
+
java_source = _generate_java_file(
|
|
1627
|
+
file_name=structure_name, imports=imports, code=code, package=package_name
|
|
1628
|
+
)
|
|
1629
|
+
|
|
1630
|
+
files.append(java_source)
|
|
1631
|
+
else:
|
|
1632
|
+
if isinstance(
|
|
1633
|
+
our_type, (intermediate.AbstractClass, intermediate.ConcreteClass)
|
|
1634
|
+
):
|
|
1635
|
+
imports = _generate_imports_for_interface(cls=our_type, package=package)
|
|
1636
|
+
|
|
1637
|
+
code, error = _generate_interface(cls=our_type, package=package)
|
|
1638
|
+
if error is not None:
|
|
1639
|
+
return None, Error(
|
|
1640
|
+
our_type.parsed.node,
|
|
1641
|
+
f"Failed to generate the interface code for "
|
|
1642
|
+
f"the class {our_type.name!r}",
|
|
1643
|
+
[error],
|
|
1644
|
+
)
|
|
1645
|
+
|
|
1646
|
+
assert code is not None
|
|
1647
|
+
|
|
1648
|
+
structure_name = java_naming.interface_name(our_type.name)
|
|
1649
|
+
|
|
1650
|
+
file_name = java_common.interface_package_path(structure_name)
|
|
1651
|
+
|
|
1652
|
+
package_name = java_common.PackageIdentifier(
|
|
1653
|
+
f"{package}.types.{java_common.INTERFACE_PKG}"
|
|
1654
|
+
)
|
|
1655
|
+
|
|
1656
|
+
java_source = _generate_java_file(
|
|
1657
|
+
file_name=file_name, imports=imports, code=code, package=package_name
|
|
1658
|
+
)
|
|
1659
|
+
|
|
1660
|
+
files.append(java_source)
|
|
1661
|
+
|
|
1662
|
+
if isinstance(our_type, intermediate.ConcreteClass):
|
|
1663
|
+
imports = _generate_imports_for_class(cls=our_type, package=package)
|
|
1664
|
+
|
|
1665
|
+
code, error = _generate_class(
|
|
1666
|
+
cls=our_type, spec_impls=spec_impls, package=package
|
|
1667
|
+
)
|
|
1668
|
+
if error is not None:
|
|
1669
|
+
return None, Error(
|
|
1670
|
+
our_type.parsed.node,
|
|
1671
|
+
f"Failed to generate the class code for "
|
|
1672
|
+
f"the class {our_type.name!r}",
|
|
1673
|
+
[error],
|
|
1674
|
+
)
|
|
1675
|
+
|
|
1676
|
+
assert code is not None
|
|
1677
|
+
|
|
1678
|
+
structure_name = java_naming.class_name(our_type.name)
|
|
1679
|
+
|
|
1680
|
+
file_name = java_common.class_package_path(structure_name)
|
|
1681
|
+
|
|
1682
|
+
package_name = java_common.PackageIdentifier(
|
|
1683
|
+
f"{package}.types.{java_common.CLASS_PKG}"
|
|
1684
|
+
)
|
|
1685
|
+
|
|
1686
|
+
java_source = _generate_java_file(
|
|
1687
|
+
file_name=file_name,
|
|
1688
|
+
imports=imports,
|
|
1689
|
+
code=code,
|
|
1690
|
+
package=package_name,
|
|
1691
|
+
)
|
|
1692
|
+
|
|
1693
|
+
files.append(java_source)
|
|
1694
|
+
elif isinstance(our_type, intermediate.Enumeration):
|
|
1695
|
+
code, error = _generate_enum(enum=our_type, package=package)
|
|
1696
|
+
if error is not None:
|
|
1697
|
+
return None, Error(
|
|
1698
|
+
our_type.parsed.node,
|
|
1699
|
+
f"Failed to generate the code for "
|
|
1700
|
+
f"the enumeration {our_type.name!r}",
|
|
1701
|
+
[error],
|
|
1702
|
+
)
|
|
1703
|
+
|
|
1704
|
+
assert code is not None
|
|
1705
|
+
structure_name = java_naming.enum_name(our_type.name)
|
|
1706
|
+
|
|
1707
|
+
file_name = java_common.enum_package_path(structure_name)
|
|
1708
|
+
|
|
1709
|
+
package_name = java_common.PackageIdentifier(
|
|
1710
|
+
f"{package}.types.{java_common.ENUM_PKG}"
|
|
1711
|
+
)
|
|
1712
|
+
|
|
1713
|
+
java_source = _generate_java_file(
|
|
1714
|
+
file_name=file_name, imports=None, code=code, package=package_name
|
|
1715
|
+
)
|
|
1716
|
+
|
|
1717
|
+
files.append(java_source)
|
|
1718
|
+
else:
|
|
1719
|
+
assert_never(our_type)
|
|
1720
|
+
|
|
1721
|
+
return files, None
|
|
1722
|
+
|
|
1723
|
+
|
|
1724
|
+
# fmt: off
|
|
1725
|
+
@ensure(lambda result: (result[0] is not None) ^ (result[1] is not None))
|
|
1726
|
+
# fmt: on
|
|
1727
|
+
def generate(
|
|
1728
|
+
symbol_table: VerifiedIntermediateSymbolTable,
|
|
1729
|
+
package: java_common.PackageIdentifier,
|
|
1730
|
+
spec_impls: specific_implementations.SpecificImplementations,
|
|
1731
|
+
) -> Tuple[Optional[List[java_common.JavaFile]], Optional[List[Error]]]:
|
|
1732
|
+
"""
|
|
1733
|
+
Generate the Java code of the structures based on the symbol table.
|
|
1734
|
+
|
|
1735
|
+
The ``package`` defines the root Java package.
|
|
1736
|
+
"""
|
|
1737
|
+
|
|
1738
|
+
files = [] # type: List[java_common.JavaFile]
|
|
1739
|
+
errors = [] # type: List[Error]
|
|
1740
|
+
|
|
1741
|
+
files.append(_generate_iclass(package))
|
|
1742
|
+
|
|
1743
|
+
for our_type in symbol_table.our_types:
|
|
1744
|
+
if not isinstance(
|
|
1745
|
+
our_type,
|
|
1746
|
+
(
|
|
1747
|
+
intermediate.Enumeration,
|
|
1748
|
+
intermediate.AbstractClass,
|
|
1749
|
+
intermediate.ConcreteClass,
|
|
1750
|
+
),
|
|
1751
|
+
):
|
|
1752
|
+
continue
|
|
1753
|
+
|
|
1754
|
+
new_files, error = _generate_structure(our_type, package, spec_impls)
|
|
1755
|
+
|
|
1756
|
+
if new_files is not None:
|
|
1757
|
+
files.extend(new_files)
|
|
1758
|
+
elif error is not None:
|
|
1759
|
+
errors.append(error)
|
|
1760
|
+
|
|
1761
|
+
if len(errors) > 0:
|
|
1762
|
+
return None, errors
|
|
1763
|
+
|
|
1764
|
+
return files, None
|
|
1765
|
+
|
|
1766
|
+
|
|
1767
|
+
# endregion
|