Docs / languages / java · Edit on GitHub

Java

Tier 1 plugin for Java source including JPMS modules, annotations, generics, lambdas, and qualified names.

Implementation

Plugin cratecrates/rgctl-lang-java (JavaPlugin)
Grammartree-sitter-java
Extensions.java
Discoverrgctl discover . -l java -e target,data --with-cfg
CFG / taintEnabled; Kantra rules with --with-kantra

Tree-sitter node kinds: method_declaration, class_declaration, interface_declaration, enum_declaration, import_declaration.

What is extracted

Nodes

  • Function — methods and constructors; is_lambda, generic/throws properties
  • Class, Interface, Enum
  • Module — JPMS module-info.java
  • Import — import declarations

Edges

EdgeMeaning
CALLSMethod and constructor calls
INSTANTIATESnew expressions
ANNOTATED_WITHAnnotations on types and members
REFERENCESField and class literal references
DEPENDSONJPMS module dependencies (Module → target)
EXTENDS / IMPLEMENTSClass hierarchy

Verification

GQL fixturetests/fixtures/java/langfeatures
Command fixturergctl-tests/ecommerce-java
Example corpusexample/metasfresh-4.9.8b (discover --full)
Smoke scriptrgctl-tests/gql-verification-smoke/verify-extraction-gql-java.sh
RGCTL=target/release/rgctl ./rgctl-tests/gql-verification-smoke/verify-extraction-gql-java.sh

GQL verification queries

Langfeatures probes (tests/fixtures/java/langfeatures)

ProbeGQL
JF-01 instantiates (String)MATCH (a:Function)-[:INSTANTIATES]->(b) WHERE a.name = 'instantiates' RETURN a,b
JF-02 annotated with (NonNull)MATCH (a:Function)-[:ANNOTATED_WITH]->(b) WHERE a.name = 'typeUse' RETURN a,b
JF-03 references (field/class literal)MATCH (a:Function)-[:REFERENCES]->(b) WHERE a.name = 'fieldAndClassLiteral' RETURN a,b
JF-04 module depends on (JPMS)MATCH (m:Module)-[:DEPENDSON]->(t) RETURN m,t
JF-05 lambda (is_lambda)MATCH (f:Function) WHERE f.is_lambda = 'true' RETURN f LIMIT 20
JF-06 generic/throws propertiesMATCH (f:Function) WHERE f.name = 'genericThrows' RETURN f
JF-07 class FQN (qualified_name)MATCH (n:Class) WHERE n.qualified_name = 'demo.LangFeatures' RETURN n
JF-07 FQN LIKE filterMATCH (n:Class) WHERE n.qualified_name LIKE 'demo.*' RETURN n

Example smoke (example/metasfresh-4.9.8b)

ProbeGQL
Class (scale)MATCH (n:Class) RETURN n LIMIT 10000
CALLS (scale)MATCH (a)-[:CALLS]->(b) RETURN a,b LIMIT 10000
INSTANTIATES (scale)MATCH (a)-[:INSTANTIATES]->(b) RETURN a,b LIMIT 10000

Related