Skip to content

Examples

A collection of complete, copy-pasteable invocations. Replace codeanalyzer-2.3.7.jar with your built JAR path (or codeanalyzer if you compiled a native binary).

Parse a project and emit the symbol table. No project build required:

Terminal window
java -jar codeanalyzer-2.3.7.jar \
-i /path/to/commons-cli \
-a 1 \
-o ./output
# -> ./output/analysis.json with symbol_table

Symbol table plus the WALA call graph. The project is built automatically:

Terminal window
java -jar codeanalyzer-2.3.7.jar \
-i /path/to/commons-cli \
-a 2 \
-o ./output \
-v
# -> ./output/analysis.json with symbol_table + call_graph

Single source string (no project, no build)

Section titled “Single source string (no project, no build)”

Analyze a snippet directly; output goes to stdout:

Terminal window
java -jar codeanalyzer-2.3.7.jar \
-s "public class HelloWorld { public static void main(String[] args) {} }" \
-a 1

If the project is already compiled, skip the build step for a faster level-2 run:

Terminal window
java -jar codeanalyzer-2.3.7.jar \
-i /path/to/project \
-a 2 \
--no-build \
-o ./output

Use your own build instead of the auto build:

Terminal window
java -jar codeanalyzer-2.3.7.jar \
-i /path/to/project \
-a 2 \
-b "mvn -q clean package -DskipTests" \
-o ./output

Re-analyze just two files and patch them into an existing analysis.json:

Terminal window
java -jar codeanalyzer-2.3.7.jar \
-i /path/to/project \
-t src/main/java/org/apache/commons/cli/Option.java \
-t src/main/java/org/apache/commons/cli/Options.java \
-o ./output

The named files are tagged is_modified: true in the merged output. See Incremental analysis.

Analyze a submodule while building from the reactor root:

Terminal window
java -jar codeanalyzer-2.3.7.jar \
-i /path/to/project/web-module \
-f /path/to/project/pom.xml \
-a 2 \
-o ./output

Omit -o to stream JSON to stdout and process it inline:

Terminal window
java -jar codeanalyzer-2.3.7.jar -i /path/to/project -a 1 \
| jq '.symbol_table | keys | length'
# prints the number of analyzed source files

If you’d rather not manage the JAR yourself, the CLDK SDK invokes it for you:

from cldk import CLDK
from cldk.analysis import AnalysisLevel
analysis = CLDK(language="java").analysis(
project_path="commons-cli",
analysis_level=AnalysisLevel.call_graph,
)
print(len(analysis.get_classes()), "classes")
print(analysis.get_call_graph()) # -> networkx.DiGraph

See Python SDK integration for details.