Add JImport model for structured Java import declarations#150
Merged
sinha108 merged 1 commit intocodellm-devkit:mainfrom Mar 5, 2026
Merged
Add JImport model for structured Java import declarations#150sinha108 merged 1 commit intocodellm-devkit:mainfrom
sinha108 merged 1 commit intocodellm-devkit:mainfrom
Conversation
…e codeanalyzer to 2.3.7
sinha108
approved these changes
Mar 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
These changes introduce the
JImportPydantic model to capture structured Java import metadata (path,is_static,is_wildcard) lost in previous versions, and adds a backward-compatibleimport_declarationsfield toJCompilationUnit. They also bump thecodeanalyzer-javaversion from 2.3.3 to 2.3.7.Motivation and Context
Previously, Java imports were stored as plain strings (
List[str]), losing information about whether an import wasstaticor used wildcard syntax. When two imports share the same path (e.g.,import static Foo.barandimport Foo.bar.*), the string-only representation makes them indistinguishable. The newJImportmodel preserves this metadata.How Has This Been Tested?
Model-layer tests (
tests/models/java/test_java_models.py):test_jcompilationunit_supports_legacy_import_list: verifies that plain-string imports are accepted and thatimport_declarationsis automatically constructed with correct defaults (is_static=False,is_wildcard=False).test_jcompilationunit_supports_structured_import_list: verifies that dict-based structured imports populate bothimportsandimport_declarations, preservingis_staticandis_wildcardflags.test_jcompilationunit_uses_imports_when_import_declarations_is_empty: covers the edge case whereimport_declarationsis present but empty, ensuring the validator falls back to theimportsfield.test_jcompilationunit_prefers_non_empty_import_declarations: confirms that when both fields are provided andimport_declarationsis non-empty, the structured data takes precedence andimportsis re-derived from it.test_jcompilationunit_imports_round_trip_through_dump_apis: exercisesmodel_dump()andmodel_dump_json()followed by re-parsing, ensuring no data is lost or mutated across serialization boundaries.Codeanalyzer-layer tests (
tests/analysis/java/test_jcodeanalyzer.py):test_init_japplication_supports_legacy_import_schema: round-trips a v2.3.6-style JSON payload through_init_japplicationand checks that both import fields are correctly populated.test_init_japplication_supports_structured_import_schema: same flow with a v2.3.7-style structured payload, verifyingis_static=Trueis preserved.test_check_existing_analysis_file_level_accepts_legacy_import_schema/..._structured_import_schema: writes temporaryanalysis.jsonfiles in each format and asserts that the cache-compatibility check passes for both.test_check_existing_analysis_file_level_rejects_invalid_json: writes malformed JSON and confirms the checker returnsFalseinstead of raising, exercising the newJSONDecodeError/OSErrorhandling.test_init_codeanalyzer_reuses_legacy_cache_when_compatible: constructs aJCodeanalyzerwith a pre-written legacy cache file and patchessubprocess.runto confirm the backend is never invoked, validating end-to-end cache reuse with the old schema.test_source_analysis_imports_disambiguate_static_and_wildcard: analyses a snippet containingimport static Foo.barandimport Foo.bar.*and asserts that the two declarations are distinguishable by theiris_static/is_wildcardflags despite sharing the samepath(this previously would have been impossible).Breaking Changes
No. The existing
imports: List[str]field onJCompilationUnitis preserved and continues to be populated automatically. Users who only readimportswill see no change. The newimport_declarations: List[JImport]field is additive. Cachedanalysis.jsonfiles using the old string-based schema remain loadable without regeneration.Types of changes
Checklist
Additional context
treesitter_java.pyget_all_importsmethod is annotated with a note that it is currently unused and does not returnJImportobjects. It should be updated if it gets wired into a real code path.check_exisiting_analysis_file_levelnow catchesjson.JSONDecodeErrorandOSErrorinstead of letting corrupt cache files crash the initialization flow. This better aligns with the return type and allows regeneration.