Quickstart
CLDK loads a project and returns a typed analysis object. The object holds the classes and methods. If you ask for it, the object also holds the call graph. A code LLM or a tool can query this structure directly.
This guide has three steps: install CLDK, get a sample project, and run an analysis. The result is a typed model of Apache Commons CLI and a networkx call graph.
-
Install CLDK.
Terminal window pip install cldkThe Java backend ships with the package and provides its own JVM. To build the call graph, the backend compiles the project with Maven, so
mvnand a JDK must be on yourPATH. For the full prerequisites, see Installing CLDK. -
Get a sample project.
This guide analyzes Apache Commons CLI. Download a release. Unzip the file. Note the location of the directory.
Terminal window wget https://github.com/apache/commons-cli/archive/refs/tags/rel/commons-cli-1.7.0.zip -O commons-cli.zipunzip commons-cli.zipexport JAVA_APP_PATH=$(pwd)/commons-cli-rel-commons-cli-1.7.0 -
Run your first analysis.
Build an
analysisobject for Java. Point it at the project. Print the class count and the call graph. Call graphs, callers, and callees needanalysis_level=AnalysisLevel.call_graph. The default level builds only the symbol table.first_analysis.py import osfrom cldk import CLDKfrom cldk.analysis import AnalysisLevelanalysis = CLDK.java(project_path=os.environ["JAVA_APP_PATH"],analysis_level=AnalysisLevel.call_graph, # required for the call graph)print(len(analysis.get_classes()), "classes")print(analysis.get_call_graph()) # -> networkx.DiGraph (edges caller -> callee)# 23 classes# DiGraph with 312 nodes and 488 edgesanalysisis now a typed model of the project that you can query.get_call_graph()returns anetworkx.DiGraph. You can use standard graph operations for caller and callee queries.
How it works
Section titled “How it works”flowchart LR
A[Project on disk] --> B["CLDK.java(project_path=...)"]
B --> C[Typed analysis object]
C --> D[get_classes]
C --> E[get_call_graph]
C --> F[get_callers / get_method]
One call converts a directory of source files into a typed analysis object. Then get_method(qualified_class_name, qualified_method_name) returns a JCallable. Its code field holds the source of the method. get_callers and get_callees walk the graph. The concepts guide covers the object model. The cheat sheet lists the available methods.
Next steps
Section titled “Next steps”The same calls run behind any tool that needs program facts. To understand what the backends build under these calls, read the guides in order.