Skip to content

Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.

fix(java): register generated record accessors by qualified name only

Martin Vogel729ce339bd13
diff --git a/internal/cbm/cbm.h b/internal/cbm/cbm.h
index ade41fea5..ef5fad51f 100644
--- a/internal/cbm/cbm.h
+++ b/internal/cbm/cbm.h
@@ -298,9 +298,10 @@ typedef struct {
* are bound to the owning result's source identity before cross-file use. */
uint32_t test_name_start_byte, test_name_end_byte;
uint32_t test_body_start_byte, test_body_end_byte;
- /* Documents only: facts a document definition adds to its node's
- * properties, as a NULL-terminated key, value, key, value, ... list (an
- * ADR's id, status, date, deciders, title). Keys are fixed literals; the
+ /* Facts a definition adds to its node's properties, as a NULL-terminated
+ * key, value, key, value, ... list: a document's (an ADR's id, status,
+ * date, deciders, title), or CBM_PROP_GENERATED on a member the compiler
+ * writes and the source never spells. Keys are fixed literals; the
* values are escaped where the properties are written. Tail field:
* zero-init stays valid. */
const char **extra_props;
@@ -315,6 +316,13 @@ typedef struct {
const char *variant_key;
} CBMDefinition;
+/* extra_props key of a generated member, one the compiler writes and the
+ * source never spells: a Java record's implicit accessor carries
+ * `generated: record`. The node keeps the property, and the pipeline registers
+ * such a definition by qualified name only, so no short-name guess can land on
+ * it (pipeline.h cbm_def_props_generated). */
+#define CBM_PROP_GENERATED "generated"
+
/* Argument captured from a call expression */
typedef struct {
const char *expr; // raw expression text ("payload.info", "MY_URL", "'hello'")
diff --git a/internal/cbm/extract_defs.c b/internal/cbm/extract_defs.c
index 2525f0a15..65829e9b8 100644
--- a/internal/cbm/extract_defs.c
+++ b/internal/cbm/extract_defs.c
@@ -9668,6 +9668,16 @@ static void extract_record_accessors(CBMExtractCtx *ctx, TSNode node, const char
const char *type = cbm_node_text(a, ctype, ctx->source);
adef.return_type = spread && type ? cbm_arena_sprintf(a, "%s[]", type) : type;
}
+ /* The compiler writes this member and the source never spells it: its
+ * node says so, and the pipeline registers it by qualified name only,
+ * so no short-name guess can land on it. */
+ const char **kv = (const char **)cbm_arena_alloc(a, CBM_SZ_3 * sizeof(char *));
+ if (kv) {
+ kv[0] = CBM_PROP_GENERATED;
+ kv[SKIP_ONE] = "record";
+ kv[PAIR_LEN] = NULL;
+ }
+ adef.extra_props = kv;
cbm_defs_push(&ctx->result->defs, a, adef);
}
}
diff --git a/src/pipeline/pass_definitions.c b/src/pipeline/pass_definitions.c
index ed60d3f9a..45bb5d3a7 100644
--- a/src/pipeline/pass_definitions.c
+++ b/src/pipeline/pass_definitions.c
@@ -509,10 +509,15 @@ static void process_def(cbm_pipeline_ctx_t *ctx, const CBMDefinition *def, const
* (helpers.c): callables + type-like containers (INHERITS/IMPLEMENTS/method/
* field resolution), Variable/Field (READS/WRITES resolution), and Table/View
* (SQL FROM/JOIN lineage). pass_parallel.c and pipeline_incremental.c seed
- * through the same predicate, so the three registries cannot diverge. */
+ * through the same predicate, so the three registries cannot diverge.
+ * A generated member is registered by qualified name only, at all three. */
if (node_id > 0 && cbm_label_is_registry_symbol(def->label)) {
- cbm_registry_add_lang_in_module(ctx->registry, def->name, def->qualified_name, def->label,
- lang, module_prefix_len);
+ if (cbm_def_props_generated(def->extra_props)) {
+ cbm_registry_add_qn_only(ctx->registry, def->qualified_name, def->label);
+ } else {
+ cbm_registry_add_lang_in_module(ctx->registry, def->name, def->qualified_name,
+ def->label, lang, module_prefix_len);
+ }
}
char *file_qn = cbm_pipeline_fqn_compute(ctx->project_name, rel, "__file__");
const cbm_gbuf_node_t *file_node = cbm_gbuf_find_by_qn(ctx->gbuf, file_qn);
diff --git a/src/pipeline/pass_parallel.c b/src/pipeline/pass_parallel.c
index 23f4934ce..dd04e3ad9 100644
--- a/src/pipeline/pass_parallel.c
+++ b/src/pipeline/pass_parallel.c
@@ -1811,10 +1811,15 @@ static int register_and_link_def(cbm_pipeline_ctx_t *ctx, const CBMDefinition *d
return 0;
}
/* Registry membership is defined ONCE by cbm_label_is_registry_symbol
- * (helpers.c) — see pass_definitions.c for the per-label rationale. */
+ * (helpers.c) — see pass_definitions.c for the per-label rationale, and
+ * for the generated member registered by qualified name only. */
if (cbm_label_is_registry_symbol(def->label)) {
- cbm_registry_add_lang_in_module(ctx->registry, def->name, def->qualified_name, def->label,
- lang, module_prefix_len);
+ if (cbm_def_props_generated(def->extra_props)) {
+ cbm_registry_add_qn_only(ctx->registry, def->qualified_name, def->label);
+ } else {
+ cbm_registry_add_lang_in_module(ctx->registry, def->name, def->qualified_name,
+ def->label, lang, module_prefix_len);
+ }
(*reg_entries)++;
}
char marked[CBM_SZ_4K];
diff --git a/src/pipeline/pipeline.h b/src/pipeline/pipeline.h
index fca310004..b564b4575 100644
--- a/src/pipeline/pipeline.h
+++ b/src/pipeline/pipeline.h
@@ -277,6 +277,24 @@ void cbm_registry_add_lang_in_module(cbm_registry_t *r, const char *name,
const char *qualified_name, const char *label,
CBMLanguage lang, size_t module_prefix_len);
+/* Register a symbol for exact (qualified-name) lookups only: it is never
+ * offered to the short-name strategies (unique_name, suffix_match,
+ * field_type_hint, fuzzy). For a generated member (cbm_def_props_generated),
+ * which the source never spells, so only a type-aware resolver that knows its
+ * owner may bind it. The three graph registration sites route such a symbol
+ * here instead of cbm_registry_add_lang_in_module. */
+void cbm_registry_add_qn_only(cbm_registry_t *r, const char *qualified_name, const char *label);
+
+/* True when a definition's extra_props (key, value, ..., NULL) carry the
+ * generated-member key (cbm.h CBM_PROP_GENERATED), e.g. a Java record's
+ * implicit accessor. Pure; unit-tested in test_registry.c. */
+bool cbm_def_props_generated(const char *const *extra_props);
+
+/* The stored-node twin of cbm_def_props_generated, for the incremental
+ * registry seed: true when a node's properties JSON carries that key as a
+ * string property. Pure; unit-tested in test_registry.c. */
+bool cbm_node_props_generated(const char *properties_json);
+
/* True when code in `caller` can call a symbol defined in `target` by bare
* name: same language, same interop family (JS/TS + script hosts, C/C++/CUDA/
* ObjC, JVM, .NET, ...; the table lives in registry.c), or Swift with the C
diff --git a/src/pipeline/pipeline_delta.c b/src/pipeline/pipeline_delta.c
index 895cded93..ca1dbab46 100644
--- a/src/pipeline/pipeline_delta.c
+++ b/src/pipeline/pipeline_delta.c
@@ -590,6 +590,39 @@ static char *delta_owner_props(const char *project, const char *name, const char
return out;
}
+/* `props` (a JSON object) with a generated member's mark (cbm.h
+ * CBM_PROP_GENERATED) added, or NULL when `generated` is NULL/empty
+ * (CBM_MEM_CLASS_OTHER; the caller frees). */
+static char *delta_generated_props(const char *props, const char *generated) {
+ if (!generated || !generated[0]) {
+ return NULL;
+ }
+ size_t pl = props ? strlen(props) : 0;
+ bool has_members = pl > PAIR_LEN && props[0] == '{' && props[pl - SKIP_ONE] == '}';
+ size_t cap = pl + PAIR_LEN * strlen(generated) + CBM_SZ_32;
+ char *out = (char *)cbm_alloc(CBM_MEM_CLASS_OTHER, cap);
+ if (!out) {
+ return NULL;
+ }
+ size_t k = 0;
+ if (has_members) {
+ memcpy(out, props, pl - SKIP_ONE);
+ k = pl - SKIP_ONE;
+ out[k++] = ',';
+ } else {
+ out[k++] = '{';
+ }
+ k += (size_t)snprintf(out + k, cap - k, "\"%s\":\"", CBM_PROP_GENERATED);
+ for (const char *p = generated; *p && k + CBM_SZ_3 < cap; p++) {
+ if (*p == '"' || *p == '\\') {
+ out[k++] = '\\';
+ }
+ out[k++] = *p;
+ }
+ snprintf(out + k, cap - k, "\"}");
+ return out;
+}
+
int64_t cbm_delta_preseed(cbm_store_t *store, const char *project, cbm_gbuf_t *gbuf) {
sqlite3 *db = cbm_store_get_db(store);
if (!db) {
@@ -634,7 +667,12 @@ int64_t cbm_delta_preseed(cbm_store_t *store, const char *project, cbm_gbuf_t *g
* goes by -- a Go method's QN has no receiver, a class-body variable's QN
* no class. A document naming `Order.Reset` binds such a node through
* its owner (doc_links_pdf.c), so a re-resolved document needs it too.
- * Only where owner + name differs from the QN (delta_owner_props). */
+ * Only where owner + name differs from the QN (delta_owner_props).
+ *
+ * And a generated member's mark (a Java record's implicit accessor, a
+ * Method node): the registry seed reads it to register the member by
+ * qualified name only, as the full build does (cbm_node_props_generated);
+ * without it the proxy came back into the short-name index. */
sqlite3_stmt *stmt = NULL;
if (sqlite3_prepare_v2(
db,
@@ -646,7 +684,10 @@ int64_t cbm_delta_preseed(cbm_store_t *store, const char *project, cbm_gbuf_t *g
" start_line, end_line,"
" CASE WHEN label IN ('Method','Variable')"
" AND instr(properties, '\"parent_class\"') > 0"
- " THEN json_extract(properties, '$.parent_class') END"
+ " THEN json_extract(properties, '$.parent_class') END,"
+ " CASE WHEN label = 'Method'"
+ " AND instr(properties, '\"" CBM_PROP_GENERATED "\"') > 0"
+ " THEN json_extract(properties, '$." CBM_PROP_GENERATED "') END"
" FROM nodes"
" WHERE project = ?1 AND label NOT IN"
" ('Macro','Comment','Section','Branch','Commit','Tag')"
@@ -670,13 +711,16 @@ int64_t cbm_delta_preseed(cbm_store_t *store, const char *project, cbm_gbuf_t *g
int start_line = sqlite3_column_int(stmt, 6);
int end_line = sqlite3_column_int(stmt, 7);
const char *parent = (const char *)sqlite3_column_text(stmt, 8);
+ const char *generated = (const char *)sqlite3_column_text(stmt, 9);
char *owner_props =
parent ? delta_owner_props(project, name, qn, parent, client_props) : NULL;
+ const char *props = owner_props ? owner_props : (client_props ? client_props : "{}");
+ char *generated_props = delta_generated_props(props, generated);
/* Pin the gbuf id to the database id: proxies ARE their rows. */
cbm_gbuf_set_next_id(gbuf, id);
- int64_t got =
- cbm_gbuf_upsert_node(gbuf, label, name, qn, fp ? fp : "", start_line, end_line,
- owner_props ? owner_props : (client_props ? client_props : "{}"));
+ int64_t got = cbm_gbuf_upsert_node(gbuf, label, name, qn, fp ? fp : "", start_line,
+ end_line, generated_props ? generated_props : props);
+ cbm_free(CBM_MEM_CLASS_OTHER, generated_props);
cbm_free(CBM_MEM_CLASS_OTHER, owner_props);
if (got != id) {
/* A QN collision inside the preseed set would silently split
diff --git a/src/pipeline/pipeline_incremental.c b/src/pipeline/pipeline_incremental.c
index 6e6740573..3d44cc696 100644
--- a/src/pipeline/pipeline_incremental.c
+++ b/src/pipeline/pipeline_incremental.c
@@ -1348,6 +1348,12 @@ static void registry_visitor(const cbm_gbuf_node_t *node, void *userdata) {
if (!incr_label_is_registry_symbol(node->label)) {
return;
}
+ /* A generated member stays out of the short-name index here as in the
+ * full index (pass_definitions.c); its node carries the mark. */
+ if (cbm_node_props_generated(node->properties_json)) {
+ cbm_registry_add_qn_only(seed->registry, node->qualified_name, node->label);
+ return;
+ }
CBMLanguage lang = cbm_registry_synthetic_path_language(node->file_path);
if (lang == CBM_LANG_COUNT && seed->lang_by_path && node->file_path) {
void *v = cbm_ht_get(seed->lang_by_path, node->file_path);
diff --git a/src/pipeline/registry.c b/src/pipeline/registry.c
index 209691ea2..51beb1eaf 100644
--- a/src/pipeline/registry.c
+++ b/src/pipeline/registry.c
@@ -1406,6 +1406,32 @@ void cbm_registry_add_lang_in_module(cbm_registry_t *r, const char *name,
}
}
+/* A generated member (a Java record's implicit accessor) is a definition the
+ * source never spells: no call names it except through its owner's type. The
+ * exact map holds it for the LSP targets and the import/same-module lookups,
+ * as it holds a Python function's locals; the by-name index does not, so no
+ * unique_name / suffix_match / field_type_hint / fuzzy guess can land on it. */
+void cbm_registry_add_qn_only(cbm_registry_t *r, const char *qualified_name, const char *label) {
+ if (!r || !qualified_name || !label) {
+ return;
+ }
+ (void)registry_add_exact(r, qualified_name, label);
+}
+
+bool cbm_def_props_generated(const char *const *extra_props) {
+ for (const char *const *kv = extra_props; kv && kv[0] && kv[SKIP_ONE]; kv += PAIR_LEN) {
+ if (strcmp(kv[0], CBM_PROP_GENERATED) == 0) {
+ return true;
+ }
+ }
+ return false;
+}
+
+bool cbm_node_props_generated(const char *properties_json) {
+ /* The key as the definition passes write it: "generated":"<value>". */
+ return properties_json && strstr(properties_json, "\"" CBM_PROP_GENERATED "\":\"") != NULL;
+}
+
/* ── Lookup ──────────────────────────────────────────────────────── */
bool cbm_registry_exists(const cbm_registry_t *r, const char *qn) {
diff --git a/tests/test_pipeline.c b/tests/test_pipeline.c
index bd76775f3..6dbbdad39 100644
--- a/tests/test_pipeline.c
+++ b/tests/test_pipeline.c
@@ -17366,6 +17366,239 @@ TEST(pipeline_python_nested_def_local_after_incremental_issue1548) {
PASS();
}
+/* A Java record's implicit accessors are GENERATED members (#2295): Method
+ * nodes marked `generated: record`, registered by qualified name only, as a
+ * Python function's locals are. The type-aware resolver binds `p.y()` on a
+ * Point to Point.y; no short-name guess may land on a member the source never
+ * spells. `far` calls y() on a type outside the project, so the project-wide
+ * name registry is its only route to Point.y. `data` calls x(), whose other
+ * spelling is Spring's private field: neither the accessor (a name guess) nor
+ * the field (a Java call never names data) is its target. The record's
+ * hand-written z() and norm() are source members: no `generated` mark. */
+static const char jgen_point_java[] =
+ "package com.example;\n"
+ "public record Point(double x, double y, double z) {\n"
+ " public double z() { return z; }\n"
+ " public double norm() { return Math.sqrt(x * x + y * y + z * z); }\n"
+ "}\n";
+static const char jgen_spring_java[] = "package com.example;\n"
+ "public final class Spring {\n"
+ " private double x;\n"
+ " public void put(double v) { this.x = v; }\n"
+ "}\n";
+static const char jgen_caller_java[] = "package com.example;\n"
+ "import org.external.Vector;\n"
+ "public final class Caller {\n"
+ " public double near(Point p) { return p.y(); }\n"
+ " public double far(Vector v) { return v.y(); }\n"
+ " public double data(Vector v) { return v.x(); }\n"
+ "}\n";
+
+/* The id of the one `label` node called `name` in `file_path`; 0 when there is
+ * none or more than one. `generated` (optional) receives whether its
+ * properties carry the `generated: record` mark. */
+static int64_t jgen_node(cbm_store_t *s, const char *project, const char *name, const char *label,
+ const char *file_path, bool *generated) {
+ cbm_node_t *nodes = NULL;
+ int count = 0;
+ int64_t id = 0;
+ int hits = 0;
+ bool marked = false;
+ if (cbm_store_find_nodes_by_name(s, project, name, &nodes, &count) != CBM_STORE_OK) {
+ return 0;
+ }
+ for (int i = 0; i < count; i++) {
+ if (nodes[i].label && strcmp(nodes[i].label, label) == 0 && nodes[i].file_path &&
+ strcmp(nodes[i].file_path, file_path) == 0) {
+ hits++;
+ id = nodes[i].id;
+ marked = nodes[i].properties_json &&
+ strstr(nodes[i].properties_json, "\"generated\":\"record\"") != NULL;
+ }
+ }
+ cbm_store_free_nodes(nodes, count);
+ if (generated) {
+ *generated = marked;
+ }
+ return hits == 1 ? id : 0;
+}
+
+/* CALLS edges out of `source_id` into `target_id`, or (target_id 0) into any
+ * node called `target_name`. */
+static int jgen_calls(cbm_store_t *s, int64_t source_id, int64_t target_id,
+ const char *target_name) {
+ cbm_edge_t *edges = NULL;
+ int ec = 0;
+ int n = 0;
+ if (cbm_store_find_edges_by_source_type(s, source_id, "CALLS", &edges, &ec) != CBM_STORE_OK) {
+ return -1;
+ }
+ for (int i = 0; i < ec; i++) {
+ if (target_id) {
+ n += edges[i].target_id == target_id;
+ continue;
+ }
+ cbm_node_t t = {0};
+ if (cbm_store_find_node_by_id(s, edges[i].target_id, &t) == CBM_STORE_OK && t.name &&
+ strcmp(t.name, target_name) == 0) {
+ n++;
+ }
+ cbm_node_free_fields(&t);
+ }
+ if (edges) {
+ cbm_store_free_edges(edges, ec);
+ }
+ return n;
+}
+
+/* One fact of jgen_check: reported, counted, and the check goes on, so a run
+ * shows every fact that does not hold. */
+#define JGEN_EXPECT(cond) \
+ do { \
+ if (!(cond)) { \
+ printf(" FAIL %s:%d: %s\n", __FILE__, __LINE__, #cond); \
+ failed++; \
+ } \
+ } while (0)
+
+/* Every fact the fixture pins, on one indexed store; the number that fail. */
+static int jgen_check(cbm_store_t *s, const char *project) {
+ int failed = 0;
+ bool gen_x = false;
+ bool gen_y = false;
+ bool gen_z = true;
+ bool gen_norm = true;
+ int64_t acc_x = jgen_node(s, project, "x", "Method", "Point.java", &gen_x);
+ int64_t acc_y = jgen_node(s, project, "y", "Method", "Point.java", &gen_y);
+ int64_t own_z = jgen_node(s, project, "z", "Method", "Point.java", &gen_z);
+ int64_t norm = jgen_node(s, project, "norm", "Method", "Point.java", &gen_norm);
+ int64_t near = jgen_node(s, project, "near", "Method", "Caller.java", NULL);
+ int64_t far = jgen_node(s, project, "far", "Method", "Caller.java", NULL);
+ int64_t data = jgen_node(s, project, "data", "Method", "Caller.java", NULL);
+ JGEN_EXPECT(acc_x > 0 && acc_y > 0 && own_z > 0 && norm > 0);
+ JGEN_EXPECT(near > 0 && far > 0 && data > 0);
+ /* The compiler's members are marked; the hand-written ones are not. */
+ JGEN_EXPECT(gen_x);
+ JGEN_EXPECT(gen_y);
+ JGEN_EXPECT(!gen_z);
+ JGEN_EXPECT(!gen_norm);
+ /* Bound by qualified name through the receiver's type ... */
+ JGEN_EXPECT(jgen_calls(s, near, acc_y, NULL) == 1);
+ /* ... and never by a short-name guess. */
+ JGEN_EXPECT(jgen_calls(s, far, acc_y, NULL) == 0);
+ JGEN_EXPECT(jgen_calls(s, far, 0, "y") == 0);
+ /* Neither the accessor nor Spring's field `x`. */
+ JGEN_EXPECT(jgen_calls(s, data, 0, "x") == 0);
+ return failed;
+}
+#undef JGEN_EXPECT
+
+static int jgen_write_fixture(const char *tmp) {
+ write_temp_file(tmp, "Point.java", jgen_point_java);
+ write_temp_file(tmp, "Spring.java", jgen_spring_java);
+ write_temp_file(tmp, "Caller.java", jgen_caller_java);
+ return 0;
+}
+
+TEST(pipeline_java_record_accessors_generated_qn_only) {
+ char tmp[256];
+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_java_gen_XXXXXX");
+ if (!cbm_mkdtemp(tmp)) {
+ FAIL("tmpdir");
+ }
+ jgen_write_fixture(tmp);
+ char db_path[512];
+ snprintf(db_path, sizeof(db_path), "%s/java_gen.db", tmp);
+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);
+ ASSERT_NOT_NULL(p);
+ ASSERT_EQ(cbm_pipeline_run(p), 0);
+ cbm_store_t *s = cbm_store_open_path(db_path);
+ ASSERT_NOT_NULL(s);
+ int rc = jgen_check(s, cbm_pipeline_project_name(p));
+ cbm_store_close(s);
+ cbm_pipeline_free(p);
+ th_rmtree(tmp);
+ ASSERT_EQ(rc, 0);
+ PASS();
+}
+
+/* The same fixture through pass_parallel.c: >= 50 files and CBM_WORKERS=4. */
+TEST(pipeline_java_record_accessors_generated_qn_only_parallel) {
+ char tmp[256];
+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_java_gen_par_XXXXXX");
+ if (!cbm_mkdtemp(tmp)) {
+ FAIL("tmpdir");
+ }
+ jgen_write_fixture(tmp);
+ for (int i = 0; i < 52; i++) {
+ char name[64];
+ char body[128];
+ snprintf(name, sizeof(name), "Filler%d.java", i);
+ snprintf(body, sizeof(body),
+ "package com.example;\nclass Filler%d { int f() { return %d; } }\n", i, i);
+ write_temp_file(tmp, name, body);
+ }
+ char *old_workers = getenv("CBM_WORKERS");
+ char *saved = old_workers ? strdup(old_workers) : NULL;
+ cbm_setenv("CBM_WORKERS", "4", 1);
+ char db_path[512];
+ snprintf(db_path, sizeof(db_path), "%s/java_gen_par.db", tmp);
+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);
+ int run = p ? cbm_pipeline_run(p) : -1;
+ if (saved) {
+ cbm_setenv("CBM_WORKERS", saved, 1);
+ free(saved);
+ } else {
+ cbm_unsetenv("CBM_WORKERS");
+ }
+ ASSERT_NOT_NULL(p);
+ ASSERT_EQ(run, 0);
+ cbm_store_t *s = cbm_store_open_path(db_path);
+ ASSERT_NOT_NULL(s);
+ int rc = jgen_check(s, cbm_pipeline_project_name(p));
+ cbm_store_close(s);
+ cbm_pipeline_free(p);
+ th_rmtree(tmp);
+ ASSERT_EQ(rc, 0);
+ PASS();
+}
+
+/* An incremental re-index seeds its registry from the stored graph: the
+ * untouched Point.java's accessors come back from their nodes, and must stay
+ * out of the short-name index exactly as in the full index while the touched
+ * Caller.java is re-resolved. */
+TEST(pipeline_java_record_accessors_generated_qn_only_after_incremental) {
+ char tmp[256];
+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_java_gen_incr_XXXXXX");
+ if (!cbm_mkdtemp(tmp)) {
+ FAIL("tmpdir");
+ }
+ jgen_write_fixture(tmp);
+ char db_path[512];
+ snprintf(db_path, sizeof(db_path), "%s/java_gen_incr.db", tmp);
+ cbm_pipeline_t *p1 = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);
+ ASSERT_NOT_NULL(p1);
+ ASSERT_EQ(cbm_pipeline_run(p1), 0);
+ cbm_pipeline_free(p1);
+
+ char caller_path[512];
+ snprintf(caller_path, sizeof(caller_path), "%s/Caller.java", tmp);
+ ASSERT_EQ(th_append_file(caller_path, "\n// touched: re-resolve Caller.java incrementally\n"),
+ 0);
+
+ cbm_pipeline_t *p2 = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);
+ ASSERT_NOT_NULL(p2);
+ ASSERT_EQ(cbm_pipeline_run(p2), 0);
+ cbm_store_t *s = cbm_store_open_path(db_path);
+ ASSERT_NOT_NULL(s);
+ int rc = jgen_check(s, cbm_pipeline_project_name(p2));
+ cbm_store_close(s);
+ cbm_pipeline_free(p2);
+ th_rmtree(tmp);
+ ASSERT_EQ(rc, 0);
+ PASS();
+}
+
/* As pyn_edge, and the edge's properties also contain `fragment`. */
static bool pyn_edge_with(cbm_store_t *s, const char *project, const char *src_rel,
const char *tgt_rel, const char *type, const char *fragment) {
@@ -27777,6 +28010,9 @@ SUITE(pipeline) {
RUN_TEST(pipeline_python_import_never_binds_a_local_def_issue1548);
RUN_TEST(pipeline_python_nested_defs_parallel_issue1548);
RUN_TEST(pipeline_python_nested_def_local_after_incremental_issue1548);
+ RUN_TEST(pipeline_java_record_accessors_generated_qn_only);
+ RUN_TEST(pipeline_java_record_accessors_generated_qn_only_parallel);
+ RUN_TEST(pipeline_java_record_accessors_generated_qn_only_after_incremental);
RUN_TEST(pipeline_python_local_def_shadows_module_def_issue1548);
RUN_TEST(pipeline_python_local_def_shadows_module_def_parallel_issue1548);
RUN_TEST(pipeline_python_super_follows_c3_mro);
diff --git a/tests/test_registry.c b/tests/test_registry.c
index d7e062bfc..7eb012679 100644
--- a/tests/test_registry.c
+++ b/tests/test_registry.c
@@ -1436,6 +1436,51 @@ TEST(java_call_never_binds_data_member) {
PASS();
}
+TEST(generated_member_registers_by_qn_only) {
+ /* A generated member (a Java record's implicit accessor) is found by its
+ * qualified name, never by a short-name guess. The same member registered
+ * the ordinary way is exactly what the guess binds. */
+ cbm_registry_t *r = cbm_registry_new();
+ cbm_registry_add_qn_only(r, "proj.geo.Point.Point.y", "Method");
+ ASSERT_TRUE(cbm_registry_exists(r, "proj.geo.Point.Point.y"));
+ ASSERT_STR_EQ(cbm_registry_label_of(r, "proj.geo.Point.Point.y"), "Method");
+ const char **qns = NULL;
+ int n = -1;
+ ASSERT_EQ(cbm_registry_find_by_name(r, "y", &qns, &n), 0);
+ ASSERT_EQ(n, 0);
+ cbm_resolution_t res = cbm_registry_resolve(r, "v.y", "proj.app.Caller", NULL, NULL, 0);
+ ASSERT_NULL(res.qualified_name);
+ cbm_registry_add(r, "x", "proj.geo.Point.Point.x", "Method");
+ res = cbm_registry_resolve(r, "v.x", "proj.app.Caller", NULL, NULL, 0);
+ ASSERT_STR_EQ(res.qualified_name, "proj.geo.Point.Point.x");
+ /* Degenerate input registers nothing. */
+ cbm_registry_add_qn_only(r, NULL, "Method");
+ cbm_registry_add_qn_only(r, "proj.geo.Point.Point.z", NULL);
+ cbm_registry_add_qn_only(NULL, "proj.geo.Point.Point.z", "Method");
+ ASSERT_EQ(cbm_registry_size(r), 2);
+ cbm_registry_free(r);
+ PASS();
+}
+
+TEST(generated_member_mark_on_defs_and_nodes) {
+ static const char *const record[] = {"generated", "record", NULL};
+ static const char *const later[] = {"source", "openapi", "generated", "lombok", NULL};
+ static const char *const doc[] = {"id", "ADR-7", "status", "accepted", NULL};
+ static const char *const keyless[] = {"generated", NULL};
+ ASSERT_TRUE(cbm_def_props_generated(record));
+ ASSERT_TRUE(cbm_def_props_generated(later));
+ ASSERT_FALSE(cbm_def_props_generated(doc));
+ ASSERT_FALSE(cbm_def_props_generated(keyless)); /* a key without a value is no fact */
+ ASSERT_FALSE(cbm_def_props_generated(NULL));
+ ASSERT_TRUE(
+ cbm_node_props_generated("{\"parent_class\":\"p.Point\",\"generated\":\"record\"}"));
+ ASSERT_FALSE(cbm_node_props_generated("{\"parent_class\":\"p.Point\"}"));
+ /* The word inside a value is not the key. */
+ ASSERT_FALSE(cbm_node_props_generated("{\"docstring\":\"code generated by protoc\"}"));
+ ASSERT_FALSE(cbm_node_props_generated(NULL));
+ PASS();
+}
+
TEST(dynamic_suppress_drops_weak_method_matches) {
/* #592/#606/#1276: a member call whose receiver the LSP could not type, that
* landed via a WEAK short-name strategy, is generic-resolver noise → drop.
@@ -2298,6 +2343,8 @@ SUITE(registry) {
RUN_TEST(c_member_access_binds_by_owner_only);
RUN_TEST(c_member_rule_covers_c_files_and_every_dot_h);
RUN_TEST(java_call_never_binds_data_member);
+ RUN_TEST(generated_member_registers_by_qn_only);
+ RUN_TEST(generated_member_mark_on_defs_and_nodes);
RUN_TEST(dynamic_suppress_drops_weak_method_matches);
RUN_TEST(dynamic_suppress_keeps_high_confidence_and_non_methods);
RUN_TEST(python_builtin_member_table_matches_builtin_type_methods);