auryn-java 0.1.0__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.
@@ -0,0 +1,289 @@
1
+ """Java binding for the AUTHORED-SHARED incremental resync engine (core/incremental_scoped.py,
2
+ ADR 0005) -- an aggregation-tier language like Go: a Class/Interface/Enum/Record/Method is keyed
3
+ `java://<proj>/module/<mod>/package/<pkg>...` (or `java://<proj>/package/...` for a root-level file,
4
+ which has no Module), NOT under a file, and the `Module` (Maven/Gradle subproject) and `Package`
5
+ nodes are aggregation points many files feed. The per-file ownership
6
+ handle is the `File-[:DEFINES]->entity` edge (added in
7
+ resolution.py, uniform with C/Go), emitted for every type AND method (a Java method is always
8
+ co-located with its type, so both source at the same File). No headers -> no declaration/definition
9
+ split (definition_rels == provenance_rels == ("DEFINES",)); Java forbids duplicate FQNs so the
10
+ multi-definer collision path is a no-op here.
11
+
12
+ Supplies the two language-specific pieces -- reconstructing Java's resolution tables from the graph
13
+ (`read_java_index`) and emitting a subset against them (`resolution.resolve_incremental`) -- plus the
14
+ declarative spec. Correctness (incremental == full) is enforced by the language-agnostic gate
15
+ (tests/sync/test_delta_differential.py + test_delta_cross_repo.py).
16
+ """
17
+
18
+ from __future__ import annotations
19
+
20
+ from auryn.core.graph_client import SHARED_NODE_LABEL, GraphWriter, semantic_label
21
+ from auryn.core.graph_model import GraphNode
22
+ from auryn.core.incremental_scoped import ChangeSet, ScopedSpec, incremental_sync_authored
23
+ from auryn.ingestors.java import ids, javamod, resolution
24
+ from auryn.ingestors.java.file_parser import parse_source
25
+ from auryn.ingestors.java.plugin import EXCLUDED_DIR_NAMES as _EXCLUDED_DIR_NAMES
26
+ from auryn.ingestors.java.plugin import FILE_SUFFIXES as _FILE_SUFFIXES
27
+ from auryn.ingestors.java.schema import NODE_SCHEMAS
28
+
29
+ __all__ = ["ChangeSet", "JAVA_SPEC", "read_java_index", "incremental_java_sync"]
30
+
31
+ # Edge classification (see core/incremental_scoped.read_authored_fingerprints):
32
+ # - provenance (File→entity ownership handle): DEFINES (types + methods).
33
+ # - lateral (source-owned): CALLS + DEPENDS_ON + EXTENDS + IMPLEMENTS + DEFINED_IN. DEFINED_IN
34
+ # (type->its File) is source-owned by the type: when the type MOVES to another file its old DEFINED_IN
35
+ # must be diffed away, so it has to be read back with the type -- else the stale edge survives
36
+ # (incremental != full).
37
+ # - containment (target-owned): the structural spine (incl. HAS_PACKAGE/HAS_FILE).
38
+ # - symbol-ref (reverse-dep closure): a change to a type/method affects its callers/subtypes/
39
+ # implementers/dependents -> CALLS + DEPENDS_ON + EXTENDS + IMPLEMENTS (NOT DEFINED_IN: moving a type's
40
+ # file doesn't change the type node, so dependents need no re-resolve).
41
+ _PROVENANCE_RELS = ("DEFINES",)
42
+ _LATERAL_RELS = ("CALLS", "DEPENDS_ON", "EXTENDS", "IMPLEMENTS", "DEFINED_IN")
43
+ _CONTAINMENT_RELS = ("HAS_MODULE", "HAS_PACKAGE", "HAS_SUBPACKAGE", "HAS_FILE", "HAS_TYPE", "HAS_NESTED_TYPE",
44
+ "HAS_METHOD", "HAS_FIELD", "HAS_PARAMETER", "HAS_ENUM_MEMBER")
45
+ _SYMBOL_REF_RELS = ("CALLS", "DEPENDS_ON", "EXTENDS", "IMPLEMENTS")
46
+ _TARGETABLE = ("Class", "Interface", "Enum", "Record", "Method")
47
+
48
+
49
+ def _scope_key(path: str) -> str:
50
+ """A file's stable scope key = normalized path -- exactly what `File.path`/`file_id` use."""
51
+ return path.replace("\\", "/").lstrip("./")
52
+
53
+
54
+ def _java_project_node(project_name, repo_uri, proj_id, target_sha, ref) -> GraphNode:
55
+ return GraphNode("Project", {"id": proj_id},
56
+ {"name": project_name, "repo_uri": repo_uri, "commit_sha": target_sha, "ref": ref})
57
+
58
+
59
+ def _walk_types(rf):
60
+ """Yield (type, package) for every type in a file, recursing into nested types (which share the
61
+ file's package, as the emitter models them)."""
62
+ def walk(rt):
63
+ yield rt
64
+ for nested in rt.nested_types:
65
+ yield from walk(nested)
66
+ for rt in rf.types:
67
+ yield from walk(rt)
68
+
69
+
70
+ def _java_referenced_names(rf) -> set[str]:
71
+ """Simple names an emit file references cross-file (call names, super/interface names, param/
72
+ return/field type tokens). Only bounds the seed; read_java_index seeds the whole non-emit index,
73
+ so over-collecting is harmless."""
74
+ names: set[str] = set()
75
+ for rt in _walk_types(rf):
76
+ if rt.superclass:
77
+ names.add(rt.superclass)
78
+ names.update(rt.interfaces)
79
+ for m in rt.methods:
80
+ names.update(c.name for c in m.calls)
81
+ names.update(resolution._referenced_names(m.return_type))
82
+ for p in m.parameters:
83
+ names.update(resolution._referenced_names(p.type))
84
+ for f in rt.fields:
85
+ names.update(resolution._referenced_names(f.type))
86
+ return {n for n in names if n}
87
+
88
+
89
+ def _java_satisfied_linkage_keys(raws) -> set[str]:
90
+ """The extern:// linkages the emit set's externally-visible methods can satisfy: a caller pointing
91
+ at `extern://java/<owner-fqcn>#<method>` (a type that wasn't in this project when it resolved)
92
+ re-binds when an emit file adds that public/protected method. Mirrors _emit_method's key exactly."""
93
+ out: set[str] = set()
94
+ for rf in raws:
95
+ for rt in _walk_types(rf):
96
+ fqcn = f"{rt.package}.{rt.name}" if rt.package else rt.name
97
+ for m in rt.methods:
98
+ if m.accessibility in ("public", "protected"):
99
+ out.add(ids.extern_method_key(f"{fqcn}#{m.name}"))
100
+ return out
101
+
102
+
103
+ def _java_displaced_caller_files(writer: GraphWriter, proj_id: str, emit_raws) -> set[str]:
104
+ """Finding-3 displacement (ADR 0005): a newly-ADDED type can out-bias a reference already bound to
105
+ a DIFFERENT type of the same SIMPLE NAME. The resolver matches by simple name with a precedence --
106
+ same-module+package, then same-package, then same-module, then any (by id) -- so adding `Helper`
107
+ anywhere can retarget an EXTENDS/IMPLEMENTS/DEPENDS_ON that pointed at another `Helper` (and, via a
108
+ receiver's field/parameter type, a CALLS). Neither the reverse-dep nor the placeholder closure
109
+ revisits such a reference -- it points at a real node, not an extern:// placeholder -- so without
110
+ this it stays stale (full != incremental).
111
+
112
+ Re-emit EXACTLY the files whose definitions reference a project type of an added simple name, so
113
+ they re-resolve as a full recompute would. Keying on the real reference edges (not on a scope
114
+ guess) makes it correct across every precedence tier at once -- a root-scoped caller, a same-module
115
+ caller in another package, a cross-module caller -- and precise: only files that actually reference
116
+ the name are pulled. A no-op when the edit adds no NEW type (a body edit keeps the same id, so it's
117
+ excluded) or when nothing references the added name."""
118
+ lo, hi = proj_id + "/", proj_id + "/" + chr(0xFFFF)
119
+ # (type_id, simple name) of every type the emit set defines (nested included).
120
+ defined: list[tuple[str, str]] = []
121
+ for raw in emit_raws:
122
+ module = javamod.module_for_path(raw.path)
123
+ scope_root = resolution._scope_root(proj_id, module)
124
+ entries: list = []
125
+ for rt in raw.types:
126
+ resolution._flatten(rt, "", scope_root, None, raw.package, entries, module)
127
+ defined.extend((e.type_id, e.name) for e in entries)
128
+ if not defined:
129
+ return set()
130
+ # Only a genuinely ADDED type (id not already in the graph) can change an existing reference's
131
+ # preferred target; a body edit reuses the id, so it's skipped -- no needless reparse (PR #9 #3).
132
+ # Match the shared :Entity label (every node carries it) so this is an id-INDEX seek over just the
133
+ # emitted ids, not a full-graph scan -- the hook runs on every Java edit, including body-only ones.
134
+ existing = {str(tid) for (tid,) in writer.ro_query(
135
+ f"MATCH (t:{SHARED_NODE_LABEL}) WHERE t.id IN $ids RETURN t.id", {"ids": [t for t, _ in defined]}).result_set}
136
+ added_names = {name for tid, name in defined if tid not in existing}
137
+ if not added_names:
138
+ return set()
139
+ names = list(added_names)
140
+ # (a) Files whose definitions reference a project type of that simple name via a TYPE edge. The
141
+ # referencing source is a Type (EXTENDS/IMPLEMENTS -> its own DEFINED_IN file) or a Method/Field
142
+ # whose owning Type has DEFINED_IN (DEPENDS_ON -- a param/field/return type ref).
143
+ rows = writer.ro_query(
144
+ "MATCH (src)-[:EXTENDS|IMPLEMENTS|DEPENDS_ON]->(t) "
145
+ "WHERE t.name IN $names AND (t:Class OR t:Interface OR t:Enum OR t:Record) "
146
+ "AND t.id >= $lo AND t.id < $hi "
147
+ "OPTIONAL MATCH (src)-[:DEFINED_IN]->(f1:File) "
148
+ "OPTIONAL MATCH (owner)-[:HAS_METHOD|HAS_FIELD]->(src), (owner)-[:DEFINED_IN]->(f2:File) "
149
+ "RETURN f1.id, f2.id",
150
+ {"names": names, "lo": lo, "hi": hi},
151
+ ).result_set
152
+ out = {str(fid) for row in rows for fid in row if fid is not None}
153
+ # (b) Constructor-ONLY callers: `new X()` is a CALLS to X's constructor Method, NOT a DEPENDS_ON,
154
+ # so a method that merely constructs X (no field/param/extends of it) is invisible to (a). Follow
155
+ # the CALLS through the constructor's owning type to the caller's file (PR #9 follow-up #1).
156
+ ctor_rows = writer.ro_query(
157
+ "MATCH (f:File)-[:DEFINES]->(:Method)-[:CALLS]->(ctor:Method)<-[:HAS_METHOD]-(t) "
158
+ "WHERE ctor.kind = 'CONSTRUCTOR' AND t.name IN $names "
159
+ "AND (t:Class OR t:Interface OR t:Enum OR t:Record) "
160
+ "AND t.id >= $lo AND t.id < $hi RETURN DISTINCT f.id",
161
+ {"names": names, "lo": lo, "hi": hi},
162
+ ).result_set
163
+ return out | {str(fid) for (fid,) in ctor_rows if fid is not None}
164
+
165
+
166
+ def _java_defined_symbol_ids(raw, proj_id: str) -> list[tuple[str, str]]:
167
+ """(node_id, label) of the program-global symbols this file defines -- types and their methods --
168
+ via the SAME id functions the emitter uses (drives v2 reverse-dep narrowing). Methods CAN be
169
+ included (unlike Go): a Java method's id depends only on its type, which is always in the same
170
+ file, so it's precisely computable from the parse. The module scope root is path-derived (same
171
+ rule as the full resolve), so the ids match even though this callback never sees the source body."""
172
+ module = javamod.module_for_path(raw.path)
173
+ scope_root = resolution._scope_root(proj_id, module)
174
+ entries: list = []
175
+ for rt in raw.types:
176
+ resolution._flatten(rt, "", scope_root, None, raw.package, entries, module)
177
+ out: list[tuple[str, str]] = []
178
+ for e in entries:
179
+ out.append((e.type_id, e.kind))
180
+ for m in e.raw_type.methods:
181
+ out.append((resolution._method_id(e.type_id, m), "Method"))
182
+ return out
183
+
184
+
185
+ def read_java_index(writer: GraphWriter, proj_id: str, exclude_keys: set[str], names: set[str]) -> resolution.JavaGraphIndex:
186
+ """Reconstruct Java's resolution tables from the graph for every file EXCEPT `exclude_keys` (the
187
+ emit + removed set), so `resolve_incremental` resolves an emit file's cross-file/cross-package
188
+ refs without re-parsing the project. Types come back as lightweight stubs (id/kind/name/package +
189
+ a constructor id for `new` targets); method_index carries the graph method ids directly (no
190
+ recompute). Every query is an id-index seek."""
191
+ idx = resolution.JavaGraphIndex()
192
+ lo, hi = proj_id + "/", proj_id + "/" + chr(0xFFFF)
193
+ exclude_file_ids = {ids.file_id(proj_id, k) for k in exclude_keys}
194
+ seed_file_ids = [
195
+ str(fid) for (fid,) in writer.ro_query(
196
+ "MATCH (f:File) WHERE f.id >= $lo AND f.id < $hi RETURN f.id", {"lo": lo, "hi": hi}
197
+ ).result_set if str(fid) not in exclude_file_ids
198
+ ]
199
+
200
+ idx.packages = {
201
+ str(name) for (name,) in writer.ro_query(
202
+ "MATCH (p:Package) WHERE p.id >= $lo AND p.id < $hi RETURN p.name", {"lo": lo, "hi": hi}
203
+ ).result_set
204
+ }
205
+ if not seed_file_ids:
206
+ return idx
207
+
208
+ # A `new X()` on a non-emit type needs X's constructor id (the emitter derives it from the raw
209
+ # body, absent in a stub) -> reconstruct type_id -> constructor method id. Must match the full
210
+ # resolve, which binds `new X(...)` to `next((m for m in raw_type.methods if m.kind=='CONSTRUCTOR'))`
211
+ # -- the FIRST constructor in SOURCE order, ignoring the call's args. So order by line_start
212
+ # (ascending) and keep the first per type; an unordered query would pick an arbitrary overload
213
+ # for a multi-ctor type (e.g. JsonIOException(String) vs (Throwable)) and diverge from full.
214
+ ctor_by_type: dict[str, str] = {}
215
+ for tid, mid in writer.ro_query(
216
+ "MATCH (file:File)-[:DEFINES]->(m:Method), (t)-[:HAS_METHOD]->(m) "
217
+ "WHERE file.id IN $fids AND m.kind = 'CONSTRUCTOR' RETURN t.id, m.id ORDER BY m.line_start",
218
+ {"fids": seed_file_ids},
219
+ ).result_set:
220
+ ctor_by_type.setdefault(str(tid), str(mid))
221
+
222
+ for tid, label, tname, qn, module in writer.ro_query(
223
+ f"MATCH (file:File)-[:DEFINES]->(t) WHERE file.id IN $fids "
224
+ f"AND (t:Class OR t:Interface OR t:Enum OR t:Record) "
225
+ f"RETURN DISTINCT t.id, {semantic_label('t')}, t.name, t.qualified_name, t.module", {"fids": seed_file_ids},
226
+ ).result_set:
227
+ tid, label, tname = str(tid), str(label), str(tname)
228
+ qn = str(qn) if qn is not None else tname
229
+ pkg = qn.rsplit(".", 1)[0] if "." in qn else ""
230
+ idx.type_index.setdefault(tname, []).append(
231
+ resolution.make_type_stub(tid, label, tname, pkg, str(module) if module is not None else "", ctor_by_type.get(tid))
232
+ )
233
+
234
+ # method_index carries the owner type's module (via t.module) so an incremental resolve biases
235
+ # same-module method binding exactly as the full resolve does (keeps two modules' same-package
236
+ # methods from cross-binding).
237
+ for mname, owner_id, mid, qn, module in writer.ro_query(
238
+ "MATCH (file:File)-[:DEFINES]->(m:Method), (t)-[:HAS_METHOD]->(m) "
239
+ "WHERE file.id IN $fids RETURN m.name, t.id, m.id, t.qualified_name, t.module", {"fids": seed_file_ids},
240
+ ).result_set:
241
+ qn = str(qn) if qn is not None else ""
242
+ pkg = qn.rsplit(".", 1)[0] if "." in qn else ""
243
+ idx.method_index.setdefault(str(mname), []).append(
244
+ (str(owner_id), str(mid), pkg, str(module) if module is not None else ""))
245
+ return idx
246
+
247
+
248
+ JAVA_SPEC = ScopedSpec(
249
+ language="java",
250
+ node_schemas=tuple(NODE_SCHEMAS),
251
+ node_labels=tuple(s.label for s in NODE_SCHEMAS),
252
+ file_suffixes=tuple(_FILE_SUFFIXES),
253
+ excluded_dir_names=frozenset(_EXCLUDED_DIR_NAMES),
254
+ symbol_ref_rels=_SYMBOL_REF_RELS,
255
+ lateral_rels=_LATERAL_RELS,
256
+ containment_rels=_CONTAINMENT_RELS,
257
+ targetable_labels=_TARGETABLE,
258
+ import_rel=None, # no IMPORTS edge; cross-package/repo unresolved calls are extern:// placeholders
259
+ import_target_labels=(),
260
+ project_id=ids.project_id,
261
+ scope_id_for_path=ids.file_id,
262
+ scope_key_for_path=_scope_key,
263
+ parse=parse_source,
264
+ is_broken=lambda rf: False, # tree-sitter best-effort; identical in both engines (matches C/Go/Bash)
265
+ referenced_names=_java_referenced_names,
266
+ read_index=read_java_index,
267
+ resolve_incremental=resolution.resolve_incremental,
268
+ project_node=_java_project_node,
269
+ satisfied_linkage_keys=_java_satisfied_linkage_keys,
270
+ # A newly-added type can out-bias a reference already bound cross-module (two Gradle modules
271
+ # sharing a package); re-emit the shadowed module/package so it re-resolves (ADR 0005). No-op
272
+ # unless subprojects with a duplicated FQCN are in play.
273
+ displaced_caller_files=_java_displaced_caller_files,
274
+ provenance_rels=_PROVENANCE_RELS,
275
+ definition_rels=("DEFINES",), # no headers -> no declaration/definition split
276
+ linkable_labels=("Method",),
277
+ defined_symbol_ids=_java_defined_symbol_ids,
278
+ # A Package prefix (e.g. `com`) -- and the Module it nests under -- is co-declared by every file
279
+ # beneath it; props are id-derived, so both are excluded from the co-DEFINER winner closure (editing
280
+ # one file must not pull the whole subtree). They stay provenance-owned (File-DEFINES-Package/Module)
281
+ # for refcount GC + in the co-contributor closure, so a module/package is reclaimed with its last file.
282
+ aggregation_labels=("Package", "Module"),
283
+ )
284
+
285
+
286
+ def incremental_java_sync(writer, source, target_sha, changes, *, project_name, repo_uri, ref=None):
287
+ """Thin wrapper over the shared authored-shared engine (git_sync routes through the same one)."""
288
+ return incremental_sync_authored(writer, JAVA_SPEC, source, target_sha, changes,
289
+ project_name=project_name, repo_uri=repo_uri, ref=ref)
@@ -0,0 +1,47 @@
1
+ """Maven/Gradle module awareness for the Java ingestor.
2
+
3
+ A Maven/Gradle *module* (subproject) is a build + (with JPMS) a namespacing unit: within one build
4
+ only that module's own packages are on the classpath, so two modules that each declare package
5
+ `com.acme.util` with a class `Helper` are DIFFERENT types. The standard Maven/Gradle layout nests a
6
+ module's sources under `<module>/src/{main,test}/{java,kotlin}/<package-path>/…`, so the module a
7
+ file belongs to is derivable FROM ITS PATH ALONE -- the directory holding that `src/<set>/<lang>`
8
+ marker -- with no pom.xml/build.gradle parse. Before this, the ingestor keyed every package/type by
9
+ its dotted package under the PROJECT, so two modules' `com.acme.util.Helper` collapsed onto one node.
10
+
11
+ This mirrors the Rust crate / Go package / Swift target work: the module is the per-file scope root
12
+ over the package tier, keyed by a pure-path rule. One difference from Go/Swift: a consumer imports a
13
+ Java type by its fully-qualified *package* name, never the Gradle module name, so the Java module is
14
+ purely INTERNAL structure -- it scopes node ids and biases resolution, but carries no cross-repo
15
+ linkage key and heals nothing. Cross-repo healing stays FQCN-based (ADR 0004), unchanged.
16
+ """
17
+
18
+ from __future__ import annotations
19
+
20
+ # Maven/Gradle nest a module's sources under `src/{main,test}/{java,kotlin}`. Both language leaves
21
+ # are accepted so a module with mixed Java/Kotlin sources resolves to the SAME module dir whichever
22
+ # ingestor walks it.
23
+ _SRC_SETS = frozenset({"main", "test"})
24
+ _SRC_LANGS = frozenset({"java", "kotlin"})
25
+
26
+
27
+ def _norm(path: str) -> str:
28
+ return path.replace("\\", "/").lstrip("./")
29
+
30
+
31
+ def module_for_path(path: str) -> str:
32
+ """The Maven/Gradle module (subproject) a source file belongs to, from its path:
33
+
34
+ <module>/src/{main,test}/{java,kotlin}/** -> "<module>" (a subproject; may be nested: `libs/data`)
35
+ src/{main,test}/{java,kotlin}/** -> "" (a root-level / single-module layout)
36
+ anything else (loose file, no src layout) -> "" (root)
37
+
38
+ A subproject is the repo-relative directory holding `src/…` -- stable, path-derived, unique --
39
+ and is used verbatim as both the Module id segment and its display name. The empty string marks a
40
+ ROOT-level file, which the caller scopes under the Project itself (NOT a Module named after the
41
+ project): that keeps a root file and a subproject literally named after the project from colliding,
42
+ and means the Module tier appears only when there genuinely are subprojects."""
43
+ parts = _norm(path).split("/")
44
+ for i in range(len(parts) - 3): # room for src/<set>/<lang>/ + at least a filename after it
45
+ if parts[i] == "src" and parts[i + 1] in _SRC_SETS and parts[i + 2] in _SRC_LANGS:
46
+ return "/".join(parts[:i]) # "" when the marker is at the repo root
47
+ return ""
@@ -0,0 +1,36 @@
1
+ """Import-light Java language registration -- the `auryn.languages` entry-point target.
2
+
3
+ Importing this module registers the Java GitLanguage without importing tree-sitter: the
4
+ GitLanguage's `sync` is a lazy thunk that imports auryn.ingestors.java.git_sync only when a
5
+ source actually contains `.java` files. Single-phase today (fast tree-sitter-java); a deep
6
+ pass -- Eclipse JDT / javac symbol resolution for resolved types, cross-file overload
7
+ selection, and inherited-member calls -- would slot in here as `deep_sync` (making Java
8
+ two-phase like Python). Suffix/exclude constants live here (single source of truth); git_sync
9
+ imports them back."""
10
+
11
+ from __future__ import annotations
12
+
13
+ from auryn.core.registry import GitLanguage, register_git_language
14
+
15
+ LANGUAGE = "java"
16
+ FILE_SUFFIXES = (".java",)
17
+ EXCLUDED_DIR_NAMES = frozenset(
18
+ {".git", "target", "build", "out", "bin", ".gradle", ".idea", "node_modules"}
19
+ )
20
+
21
+
22
+ def _sync(*args, **kwargs):
23
+ """Deferred until a source has Java files -- imports the tree-sitter-java engine."""
24
+ from auryn.ingestors.java.git_sync import _git_language_sync
25
+
26
+ return _git_language_sync(*args, **kwargs)
27
+
28
+
29
+ register_git_language(
30
+ GitLanguage(
31
+ language=LANGUAGE,
32
+ file_suffixes=FILE_SUFFIXES,
33
+ excluded_dir_names=EXCLUDED_DIR_NAMES,
34
+ sync=_sync,
35
+ )
36
+ )
@@ -0,0 +1,115 @@
1
+ """Picklable dataclasses produced by file_parser (phase-1, per-file, no shared state -- safe
2
+ under a ProcessPoolExecutor). No tree-sitter node ever crosses this boundary; resolution.py
3
+ turns these into graph nodes/edges once every file has been parsed.
4
+
5
+ Everything here is what a single tree-sitter parse of one .java file can know on its own --
6
+ names, types-as-written (text), modifiers, annotations, call *names*. Cross-file decisions
7
+ (does this call resolve to a project method? does a base name name a project type?) are made
8
+ later, in resolution.py, where all files are visible at once.
9
+
10
+ Modelled after the C# ingestor's raw_model (Java and C# are structural siblings), pared to
11
+ Java's constructs: no properties/events/delegates/structs; a class has a single `superclass`
12
+ plus a separate `interfaces` list (so EXTENDS vs IMPLEMENTS needs no naming heuristic, unlike
13
+ C#'s mixed base_list). line_start/line_end are 1-based inclusive, matching the C/Python
14
+ ingestors; 0 means not captured."""
15
+
16
+ from __future__ import annotations
17
+
18
+ from dataclasses import dataclass, field
19
+
20
+
21
+ @dataclass
22
+ class RawAnnotation:
23
+ name: str
24
+ arguments: list[str] = field(default_factory=list)
25
+
26
+
27
+ @dataclass
28
+ class RawParameter:
29
+ name: str
30
+ type: str # type as written, e.g. "Store", "List<String>", "int"
31
+ position: int
32
+ is_varargs: bool = False # `String... args`
33
+ is_final: bool = False
34
+
35
+
36
+ @dataclass
37
+ class RawCall:
38
+ name: str # the callee's simple name (method_invocation name, or the created type)
39
+ receiver: str | None = None
40
+ """The receiver's own simple name when it's a bare identifier or `this` ("store" for
41
+ `store.put()`, "this" for `this.save()`, None for a bare `foo()` or a receiver too complex
42
+ to name -- a field_access or method chain). resolution.py uses it to prefer resolving
43
+ against a field's declared type over a same-name coincidence."""
44
+ is_new: bool = False # `new Widget()` -> resolves against a constructor
45
+
46
+
47
+ @dataclass
48
+ class RawMethod:
49
+ name: str
50
+ kind: str # "ORDINARY" | "CONSTRUCTOR"
51
+ accessibility: str # "public" | "private" | "protected" | "package"
52
+ modifiers: list[str] = field(default_factory=list) # static/final/abstract/synchronized/...
53
+ return_type: str | None = None # None for a constructor
54
+ parameters: list[RawParameter] = field(default_factory=list)
55
+ throws: list[str] = field(default_factory=list)
56
+ annotations: list[RawAnnotation] = field(default_factory=list)
57
+ calls: list[RawCall] = field(default_factory=list)
58
+ source: str = ""
59
+ doc: str = "" # shared `doc` property: the leading comment above the declaration, cleaned
60
+ line_start: int = 0
61
+ line_end: int = 0
62
+
63
+
64
+ @dataclass
65
+ class RawField:
66
+ name: str
67
+ type: str
68
+ accessibility: str = "package"
69
+ modifiers: list[str] = field(default_factory=list) # static/final/volatile/transient
70
+ annotations: list[RawAnnotation] = field(default_factory=list)
71
+ line_start: int = 0
72
+ line_end: int = 0
73
+
74
+
75
+ @dataclass
76
+ class RawEnumMember:
77
+ name: str
78
+ arguments: list[str] = field(default_factory=list)
79
+
80
+
81
+ @dataclass
82
+ class RawType:
83
+ kind: str # "Class" | "Interface" | "Enum" | "Record"
84
+ name: str
85
+ package: str # "" for the default package
86
+ accessibility: str = "package"
87
+ modifiers: list[str] = field(default_factory=list)
88
+ type_parameters: list[str] = field(default_factory=list)
89
+ superclass: str | None = None # class only -- single base (simple name)
90
+ interfaces: list[str] = field(default_factory=list) # implemented (class/enum/record) or extended (interface)
91
+ annotations: list[RawAnnotation] = field(default_factory=list)
92
+ methods: list[RawMethod] = field(default_factory=list)
93
+ fields: list[RawField] = field(default_factory=list)
94
+ enum_members: list[RawEnumMember] = field(default_factory=list)
95
+ record_components: list[RawParameter] = field(default_factory=list) # Record only
96
+ nested_types: list["RawType"] = field(default_factory=list)
97
+ source: str = ""
98
+ doc: str = "" # shared `doc` property: the leading comment above the declaration, cleaned
99
+ line_start: int = 0
100
+ line_end: int = 0
101
+
102
+
103
+ @dataclass
104
+ class RawImport:
105
+ name: str # dotted, e.g. "java.util.List" or "com.acme.other" (wildcard drops the .*)
106
+ is_static: bool = False
107
+ is_wildcard: bool = False
108
+
109
+
110
+ @dataclass
111
+ class RawFile:
112
+ path: str
113
+ package: str = ""
114
+ imports: list[RawImport] = field(default_factory=list)
115
+ types: list[RawType] = field(default_factory=list)