Skip to content

Commit 0acb2c9

Browse files
docs: update Java documentation to match actual implementation
Java docs incorrectly referenced codeflash.toml (which doesn't exist) and omitted Java from several pages despite being fully implemented. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent fdf74e2 commit 0acb2c9

7 files changed

Lines changed: 118 additions & 90 deletions

File tree

.claude/rules/architecture.md

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ codeflash/
2121
├── api/ # AI service communication
2222
├── code_utils/ # Code parsing, git utilities
2323
├── models/ # Pydantic models and types
24-
├── languages/ # Multi-language support (Python, JavaScript/TypeScript, Java planned)
24+
├── languages/ # Multi-language support (Python, JavaScript/TypeScript, Java)
2525
│ ├── base.py # LanguageSupport protocol and shared data types
2626
│ ├── registry.py # Language registration and lookup by extension/enum
2727
│ ├── current.py # Current language singleton (set_current_language / current_language_support)
@@ -35,11 +35,29 @@ codeflash/
3535
│ │ ├── test_runner.py # Test subprocess execution for Python
3636
│ │ ├── instrument_codeflash_capture.py # Instrument __init__ with capture decorators
3737
│ │ └── parse_line_profile_test_output.py # Parse line profiler output
38-
│ └── javascript/
39-
│ ├── support.py # JavaScriptSupport (LanguageSupport implementation)
40-
│ ├── function_optimizer.py # JavaScriptFunctionOptimizer subclass
41-
│ ├── optimizer.py # JS project root finding & module preparation
42-
│ └── normalizer.py # JS/TS code normalization for deduplication
38+
│ ├── javascript/
39+
│ │ ├── support.py # JavaScriptSupport (LanguageSupport implementation)
40+
│ │ ├── function_optimizer.py # JavaScriptFunctionOptimizer subclass
41+
│ │ ├── optimizer.py # JS project root finding & module preparation
42+
│ │ └── normalizer.py # JS/TS code normalization for deduplication
43+
│ └── java/
44+
│ ├── support.py # JavaSupport (LanguageSupport implementation)
45+
│ ├── function_optimizer.py # JavaFunctionOptimizer subclass
46+
│ ├── build_tool_strategy.py # Abstract BuildToolStrategy for Maven/Gradle
47+
│ ├── maven_strategy.py # Maven build tool strategy
48+
│ ├── gradle_strategy.py # Gradle build tool strategy
49+
│ ├── build_tools.py # Build tool detection and project info
50+
│ ├── build_config_strategy.py # Config read/write for pom.xml / gradle.properties
51+
│ ├── test_runner.py # Test execution via Maven/Gradle
52+
│ ├── instrumentation.py # Behavior capture and benchmarking instrumentation
53+
│ ├── discovery.py # Function discovery using tree-sitter
54+
│ ├── test_discovery.py # Test discovery for JUnit/TestNG
55+
│ ├── context.py # Code context extraction
56+
│ ├── comparator.py # Test result comparison
57+
│ ├── config.py # Java project detection and config
58+
│ ├── formatter.py # Code formatting and normalization
59+
│ ├── line_profiler.py # JVM bytecode agent-based line profiling
60+
│ └── tracer.py # Two-stage JFR + argument capture tracer
4361
├── setup/ # Config schema, auto-detection, first-run experience
4462
├── picklepatch/ # Serialization/deserialization utilities
4563
├── tracing/ # Function call tracing
@@ -57,7 +75,7 @@ codeflash/
5775
|------|------------|
5876
| CLI arguments & commands | `cli_cmds/cli.py` (parsing), `main.py` (subcommand dispatch) |
5977
| Optimization orchestration | `optimization/optimizer.py``run()` |
60-
| Per-function optimization | `languages/function_optimizer.py` (base), `languages/python/function_optimizer.py`, `languages/javascript/function_optimizer.py` |
78+
| Per-function optimization | `languages/function_optimizer.py` (base), `languages/python/function_optimizer.py`, `languages/javascript/function_optimizer.py`, `languages/java/function_optimizer.py` |
6179
| Function discovery | `discovery/functions_to_optimize.py` |
6280
| Context extraction | `languages/<lang>/context/code_context_extractor.py` |
6381
| Test execution | `languages/<lang>/support.py` (`run_behavioral_tests`, etc.), `verification/pytest_plugin.py` |
@@ -67,7 +85,7 @@ codeflash/
6785

6886
## LanguageSupport Protocol Methods
6987

70-
Core protocol in `languages/base.py`. Each language (`PythonSupport`, `JavaScriptSupport`) implements these.
88+
Core protocol in `languages/base.py`. Each language (`PythonSupport`, `JavaScriptSupport`, `JavaSupport`) implements these.
7189

7290
| Category | Method/Property | Purpose |
7391
|----------|----------------|---------|

docs/claude-code-plugin/usage-guide.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Flags can be combined: `/optimize src/utils.py my_function`
2929
### What happens behind the scenes
3030

3131
1. The skill (defined in `skills/optimize/SKILL.md`) forks context and spawns the **optimizer agent**
32-
2. The agent locates your project config (`pyproject.toml` or `package.json` or `codeflash.toml`)
32+
2. The agent locates your project config (`pyproject.toml`, `package.json`, or `pom.xml`/`gradle.properties`)
3333
3. It verifies the codeflash CLI is installed and the project is configured
3434
4. It runs `codeflash --subagent` as a **background task** with a 10-minute timeout
3535
5. You're notified when optimization completes with results

docs/configuration/java.mdx

Lines changed: 51 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,52 @@
11
---
22
title: "Java Configuration"
3-
description: "Configure Codeflash for Java projects using codeflash.toml"
3+
description: "Configure Codeflash for Java projects"
44
icon: "java"
5-
sidebarTitle: "Java (codeflash.toml)"
5+
sidebarTitle: "Java"
66
keywords:
77
[
88
"configuration",
9-
"codeflash.toml",
109
"java",
1110
"maven",
1211
"gradle",
1312
"junit",
13+
"pom.xml",
14+
"gradle.properties",
1415
]
1516
---
1617

1718
# Java Configuration
1819

19-
Codeflash stores its configuration in `codeflash.toml` under the `[tool.codeflash]` section.
20+
Codeflash stores its configuration inside your existing build file — `pom.xml` properties for Maven projects, or `gradle.properties` for Gradle projects. No separate config file is needed.
2021

21-
## Full Reference
22+
## Maven Configuration
2223

23-
```toml
24-
[tool.codeflash]
25-
# Required
26-
module-root = "src/main/java"
27-
tests-root = "src/test/java"
28-
language = "java"
24+
For Maven projects, Codeflash writes properties under the `<properties>` section of your `pom.xml` with the `codeflash.` prefix:
2925

30-
# Optional
31-
test-framework = "junit5" # "junit5", "junit4", or "testng"
32-
disable-telemetry = false
33-
git-remote = "origin"
34-
ignore-paths = ["src/main/java/generated/"]
26+
```xml
27+
<properties>
28+
<!-- Only non-default overrides are written -->
29+
<codeflash.moduleRoot>src/main/java</codeflash.moduleRoot>
30+
<codeflash.testsRoot>src/test/java</codeflash.testsRoot>
31+
<codeflash.gitRemote>origin</codeflash.gitRemote>
32+
<codeflash.formatterCmds>mvn spotless:apply -DspotlessFiles=$file</codeflash.formatterCmds>
33+
<codeflash.disableTelemetry>false</codeflash.disableTelemetry>
34+
<codeflash.ignorePaths>src/main/java/generated/</codeflash.ignorePaths>
35+
</properties>
3536
```
3637

37-
All file paths are relative to the directory containing `codeflash.toml`.
38+
## Gradle Configuration
39+
40+
For Gradle projects, Codeflash writes settings to `gradle.properties` with the `codeflash.` prefix:
41+
42+
```properties
43+
codeflash.moduleRoot=src/main/java
44+
codeflash.testsRoot=src/test/java
45+
codeflash.gitRemote=origin
46+
```
3847

3948
<Info>
40-
Codeflash auto-detects most settings from your project structure. Running `codeflash init` will set up the correct config — manual configuration is usually not needed.
49+
Codeflash auto-detects most settings from your project structure. Running `codeflash init` will set up the correct config — manual configuration is usually not needed. For standard Maven/Gradle layouts, Codeflash may write no config at all if all defaults are correct.
4150
</Info>
4251

4352
## Auto-Detection
@@ -46,54 +55,42 @@ When you run `codeflash init`, Codeflash inspects your project and auto-detects:
4655

4756
| Setting | Detection logic |
4857
|---------|----------------|
49-
| `module-root` | Looks for `src/main/java` (Maven/Gradle standard layout) |
50-
| `tests-root` | Looks for `src/test/java`, `test/`, `tests/` |
51-
| `language` | Detected from build files (`pom.xml`, `build.gradle`) and `.java` files |
52-
| `test-framework` | Checks build file dependencies for JUnit 5, JUnit 4, or TestNG |
53-
54-
## Required Options
58+
| **Source root** | Looks for `src/main/java` (Maven/Gradle standard layout), falls back to pom.xml `sourceDirectory` |
59+
| **Test root** | Looks for `src/test/java`, `test/`, `tests/` |
60+
| **Build tool** | Detects Maven (`pom.xml`) or Gradle (`build.gradle` / `build.gradle.kts`) |
61+
| **Test framework** | Checks build file dependencies for JUnit 5, JUnit 4, or TestNG |
62+
63+
## Configuration Options
64+
65+
| Property | Description | Default |
66+
|----------|-------------|---------|
67+
| `moduleRoot` | Source directory to optimize | `src/main/java` |
68+
| `testsRoot` | Test directory | `src/test/java` |
69+
| `gitRemote` | Git remote for pull requests | `origin` |
70+
| `formatterCmds` | Code formatter command (`$file` placeholder for file path) | (none) |
71+
| `disableTelemetry` | Disable anonymized telemetry | `false` |
72+
| `ignorePaths` | Paths within source root to skip during optimization | (none) |
5573

56-
- **`module-root`**: The source directory to optimize. Only code under this directory is discovered for optimization. For standard Maven/Gradle projects, this is `src/main/java`.
57-
- **`tests-root`**: The directory where your tests are located. Codeflash discovers existing tests and places generated replay tests here.
58-
- **`language`**: Must be set to `"java"` for Java projects.
59-
60-
## Optional Options
61-
62-
- **`test-framework`**: Test framework. Auto-detected from build dependencies. Supported values: `"junit5"` (default), `"junit4"`, `"testng"`.
63-
- **`disable-telemetry`**: Disable anonymized telemetry. Defaults to `false`.
64-
- **`git-remote`**: Git remote for pull requests. Defaults to `"origin"`.
65-
- **`ignore-paths`**: Paths within `module-root` to skip during optimization.
74+
<Info>
75+
Only non-default values are written to the config. If your project uses the standard `src/main/java` and `src/test/java` layout with the default `origin` remote, Codeflash may not need to write any config properties at all.
76+
</Info>
6677

6778
## Multi-Module Projects
6879

69-
For multi-module Maven/Gradle projects, place `codeflash.toml` at the project root and set `module-root` to the module you want to optimize:
80+
For multi-module Maven/Gradle projects, run `codeflash init` from the module you want to optimize. The config is written to that module's `pom.xml` or `gradle.properties`:
7081

7182
```text
7283
my-project/
7384
|- client/
7485
| |- src/main/java/com/example/client/
7586
| |- src/test/java/com/example/client/
87+
| |- pom.xml <-- run codeflash init here
7688
|- server/
7789
| |- src/main/java/com/example/server/
7890
|- pom.xml
79-
|- codeflash.toml
80-
```
81-
82-
```toml
83-
[tool.codeflash]
84-
module-root = "client/src/main/java"
85-
tests-root = "client/src/test/java"
86-
language = "java"
8791
```
8892

89-
For non-standard layouts (like the Aerospike client where source is under `client/src/`), adjust paths accordingly:
90-
91-
```toml
92-
[tool.codeflash]
93-
module-root = "client/src"
94-
tests-root = "test/src"
95-
language = "java"
96-
```
93+
For non-standard layouts (like the Aerospike client where source is under `client/src/`), `codeflash init` will prompt you to override the detected paths.
9794

9895
## Tracer Options
9996

@@ -124,15 +121,9 @@ my-app/
124121
| |- test/java/com/example/
125122
| |- AppTest.java
126123
|- pom.xml
127-
|- codeflash.toml
128124
```
129125

130-
```toml
131-
[tool.codeflash]
132-
module-root = "src/main/java"
133-
tests-root = "src/test/java"
134-
language = "java"
135-
```
126+
Standard layout — no extra config needed. `codeflash init` detects everything automatically.
136127

137128
### Gradle project
138129

@@ -142,12 +133,7 @@ my-lib/
142133
| |- main/java/com/example/
143134
| |- test/java/com/example/
144135
|- build.gradle
145-
|- codeflash.toml
136+
|- gradle.properties <-- codeflash config written here if overrides needed
146137
```
147138

148-
```toml
149-
[tool.codeflash]
150-
module-root = "src/main/java"
151-
tests-root = "src/test/java"
152-
language = "java"
153-
```
139+
Standard layout — no extra config needed. `codeflash init` detects everything automatically.

docs/getting-started/java-installation.mdx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,29 +58,31 @@ codeflash init
5858
This will:
5959
- Detect your build tool (Maven/Gradle)
6060
- Find your source and test directories
61-
- Update your pom.xml or gradle settings with codeflash java library. The java library instruments your code and verifies correctness.
61+
- Write Codeflash configuration to your `pom.xml` properties (Maven) or `gradle.properties` (Gradle)
6262

6363
</Step>
6464
<Step title="Run your first optimization">
6565

66-
Trace and optimize a Java program:
66+
Optimize a specific function:
6767

6868
```bash
69-
codeflash optimize java -jar target/my-app.jar
69+
codeflash --file src/main/java/com/example/Utils.java --function myMethod
7070
```
7171

72-
Or with Maven:
72+
Or optimize all functions in your project:
7373

7474
```bash
75-
codeflash optimize mvn exec:java -Dexec.mainClass="com.example.Main"
75+
codeflash --all
7676
```
7777

7878
Codeflash will:
79-
1. Profile your program using JFR (Java Flight Recorder)
80-
2. Capture method arguments using a bytecode instrumentation agent
81-
3. Generate JUnit replay tests from the captured data to create a micro-benchmark.
82-
4. Rank functions by performance impact
83-
5. Optimize the most impactful functions
79+
1. Discover optimizable functions in your source code
80+
2. Generate tests and optimization candidates using AI
81+
3. Verify correctness by running tests (JUnit 5, JUnit 4, or TestNG)
82+
4. Benchmark performance improvements
83+
5. Create a pull request with the optimization (if the GitHub App is installed)
84+
85+
For advanced workflow tracing (profiling a running Java program), see [Trace & Optimize](/optimizing-with-codeflash/trace-and-optimize).
8486

8587
</Step>
8688
</Steps>

docs/index.mdx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
title: "Codeflash is an AI performance optimizer for your code"
33
icon: "rocket"
44
sidebarTitle: "Overview"
5-
keywords: ["python", "javascript", "typescript", "performance", "optimization", "AI", "code analysis", "benchmarking"]
5+
keywords: ["python", "javascript", "typescript", "java", "performance", "optimization", "AI", "code analysis", "benchmarking"]
66
---
77

88
Codeflash speeds up your code by figuring out the best way to rewrite it while verifying that the behavior is unchanged, and verifying real speed
9-
gains through performance benchmarking. It supports **Python**, **JavaScript**, and **TypeScript**.
9+
gains through performance benchmarking. It supports **Python**, **JavaScript**, **TypeScript**, and **Java**.
1010

1111
The optimizations Codeflash finds are generally better algorithms, opportunities to remove wasteful compute, better logic, utilizing caching and utilization of more efficient library methods. Codeflash
1212
does not modify the system architecture of your code, but it tries to find the most efficient implementation of your current architecture.
@@ -15,18 +15,21 @@ does not modify the system architecture of your code, but it tries to find the m
1515

1616
Pick your language to install and configure Codeflash:
1717

18-
<CardGroup cols={2}>
18+
<CardGroup cols={3}>
1919
<Card title="Python" icon="python" href="/getting-started/local-installation">
2020
Install via pip, uv, or poetry. Configure in `pyproject.toml`.
2121
</Card>
2222
<Card title="JavaScript / TypeScript" icon="js" href="/getting-started/javascript-installation">
2323
Install via npm, yarn, pnpm, or bun. Configure in `package.json`. Supports Jest, Vitest, and Mocha.
2424
</Card>
25+
<Card title="Java" icon="java" href="/getting-started/java-installation">
26+
Install via uv. Supports Maven and Gradle. JUnit 5, JUnit 4, and TestNG.
27+
</Card>
2528
</CardGroup>
2629

2730
### How to use Codeflash
2831

29-
These commands work for both Python and JS/TS projects:
32+
These commands work for Python, JS/TS, and Java projects:
3033

3134
<CardGroup cols={2}>
3235
<Card title="Optimize a Function" icon="bullseye" href="/optimizing-with-codeflash/one-function">
@@ -56,13 +59,16 @@ These commands work for both Python and JS/TS projects:
5659

5760
### Configuration Reference
5861

59-
<CardGroup cols={2}>
62+
<CardGroup cols={3}>
6063
<Card title="Python Config" icon="python" href="/configuration/python">
6164
`pyproject.toml` reference
6265
</Card>
6366
<Card title="JS / TS Config" icon="js" href="/configuration/javascript">
6467
`package.json` reference — includes monorepo, scattered tests, manual setup
6568
</Card>
69+
<Card title="Java Config" icon="java" href="/configuration/java">
70+
`pom.xml` / `gradle.properties` reference
71+
</Card>
6672
</CardGroup>
6773

6874
### How does Codeflash verify correctness?

docs/optimizing-with-codeflash/codeflash-all.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ keywords: ["codebase optimization", "all functions", "batch optimization", "gith
99
# Optimize your entire codebase
1010

1111
Codeflash can optimize your entire codebase by analyzing all the functions in your project and generating optimized versions of them.
12-
It iterates through all the functions in your codebase and optimizes them one by one. This works for Python, JavaScript, and TypeScript projects.
12+
It iterates through all the functions in your codebase and optimizes them one by one. This works for Python, JavaScript, TypeScript, and Java projects.
1313

1414
To optimize your entire codebase, run the following command in your project directory:
1515

docs/optimizing-with-codeflash/one-function.mdx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ keywords:
1313
"javascript",
1414
"typescript",
1515
"python",
16+
"java",
1617
]
1718
---
1819

@@ -45,6 +46,11 @@ codeflash --file path/to/your/file.js --function functionName
4546
codeflash --file path/to/your/file.ts --function functionName
4647
```
4748
</Tab>
49+
<Tab title="Java">
50+
```bash
51+
codeflash --file src/main/java/com/example/Utils.java --function methodName
52+
```
53+
</Tab>
4854
</Tabs>
4955

5056
If you have installed the GitHub App to your repository, the above command will open a pull request with the optimized function.
@@ -61,6 +67,11 @@ codeflash --file path/to/your/file.py --function function_name --no-pr
6167
codeflash --file path/to/your/file.ts --function functionName --no-pr
6268
```
6369
</Tab>
70+
<Tab title="Java">
71+
```bash
72+
codeflash --file src/main/java/com/example/Utils.java --function methodName --no-pr
73+
```
74+
</Tab>
6475
</Tabs>
6576

6677
### Optimizing class methods
@@ -78,4 +89,9 @@ codeflash --file path/to/your/file.py --function ClassName.method_name
7889
codeflash --file path/to/your/file.ts --function ClassName.methodName
7990
```
8091
</Tab>
92+
<Tab title="Java">
93+
```bash
94+
codeflash --file src/main/java/com/example/Utils.java --function methodName
95+
```
96+
</Tab>
8197
</Tabs>

0 commit comments

Comments
 (0)