Skip to main content

Crate model_lang_java

Crate model_lang_java 

Source
Expand description

Java enricher for Model: HTTP endpoints and GWT RPC calls.

Run it on a ModelBuilder after model-treesitter (and the SCIP link) extracted the Java files: it re-reads the sources, finds the entities the extraction made by the position of their name, and adds facts a query cannot express. The only kind added is http.endpoint, shared with the Python and TypeScript enrichers; no language name enters model-core.

§What it adds

FactWhereShape
HTTP_ENDPOINT entity (http.endpoint, props http.verb, http.path)child of the handler method, named VERB /path, relation http.endpoints from the methodANY for any verb, ? for a path that is not a literal
PROP_ENDPOINTS (http.endpoints)handler methodlist of "VERB /path", as TypeScript’s
PROP_RPC_SERVICE (rpc.service)RemoteService interfacetrue
PROP_RPC_CALLS (rpc.calls)method or constructor calling a servicelist of "a.b.Service#method/arity" (call arity, callback included)
RPC_RELATION (gwt-rpc, RelationKind::Other)caller → implementing methodProvenance::Frontend, one site per call

Endpoints: Spring @RequestMapping and @Get/Post/Put/Delete/PatchMapping (verbs, path arrays, path =/value =), JAX-RS @Path with @GET…; the class-level prefix comes from the type, else from the nearest supertype that has one. A method without a mapping inherits the one of the method it overrides (same name and arity) on a supertype, also one of the build-generated sources (target/generated-sources, build/generated, read for that purpose only, never given entities). Feign and @HttpExchange clients serve nothing.

GWT RPC: a call is RPC-shaped when its receiver is an XAsync field, local or parameter, X.Util.getInstance() or GWT.create(X.class), and X is a project RemoteService (or an unresolved XAsync, resolved by the name of the implementing classes’ supertypes). The relation goes to the method of each implementing class (transitively), matched by name and arity with the callback dropped, then kept.

§Moose / Famix

Famix has no class for these facts. The http.endpoint entities have no FM3 class (the exporter skips them), the other facts are extension properties of existing entities, kept by the JSON model and ignored by model-moose’s export: an http.endpoints prop is not written, and the gwt-rpc relation is reported by the exporter as gwt-rpc (no Famix association); the entities themselves export as before (tests/moose.rs checks it).

§Scope

Files under src/test/ are not read. Entities are found by file and name position, so the model must come from the same sources (tree-sitter, with or without SCIP: lifted entities keep their ranges).

Structs§

JavaStats
What an enrichment found.
Prepared
The Java sources of a project, read and parsed, ready to enrich a model. Parsing needs no builder: a caller can prepare while the model is being built (extraction, SCIP linking), then apply.

Constants§

HTTP_ENDPOINT
Fine kind of the entity made for each endpoint: shared with the Python and TypeScript enrichers.
PROP_ENDPOINTS
Property of a handler method: its endpoints, "GET /articles/{slug}".
PROP_RPC_CALLS
Property of a caller: the RPC calls it makes, "a.b.Service#method/arity".
PROP_RPC_SERVICE
Property of a RemoteService interface: true.
RPC_RELATION
Name of the relation (RelationKind::Other) from a GWT RPC caller to the implementing method.

Functions§

declare_kinds
Defines the kinds this enricher adds (normally defined when first met), see model_treesitter::declare_kinds.
enrich
Enriches b from the Java files under root (the root the model was extracted from). Reads the same files model-treesitter does, minus src/test/, plus the build-generated sources for endpoint inheritance.
enrich_files
enrich over files, the source files under root as model_treesitter::source_files lists them (paths relative to root; those that are not Java are skipped): a caller that has the list saves walking the tree again.
enrich_sources
enrich over in-memory sources (relative path, text). generated are build-generated sources, read for endpoint inheritance only. Files that are not Java or under src/test/ are skipped.
generated_files
.java files under target/generated-sources/** and build/generated/**, as sorted /-separated paths relative to root.
prepare_files
Reads and parses what enrich_files does, without a builder.
prepare_sources
Parses what enrich_sources does, without a builder.
rpc_relation
The GWT RPC relation kind.