Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ The goal is to make the flow of a codebase visible instead of jumping between fi
| JavaScript | `.js`, `.jsx`, `.mjs`, `.cjs` |
| C | `.c`, `.h` (unless the folder also holds C++ files) |
| C++ | `.cc`, `.cpp`, `.cxx`, `.hpp`, `.hh`, `.hxx`, plus `.h` when the folder also holds C++ files |
| Java | `.java` |

More languages can be added without touching the frontend - see [Backend](#backend) below.

Expand Down
10 changes: 9 additions & 1 deletion backend/languages/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,19 @@
from .base import SKIP_DIRS, LanguagePlugin
from .c import CLanguage
from .cpp import CppLanguage
from .java import JavaLanguage
from .python import PythonLanguage
from .rust import RustLanguage
from .typescript import TypeScriptLanguage

LANGUAGES: list[LanguagePlugin] = [PythonLanguage(), RustLanguage(), TypeScriptLanguage(), CLanguage(), CppLanguage()]
LANGUAGES: list[LanguagePlugin] = [
PythonLanguage(),
RustLanguage(),
TypeScriptLanguage(),
CLanguage(),
CppLanguage(),
JavaLanguage(),
]

# Each extension's unconditional owner; a plugin's `conditional_extensions` are not in here (see analyzer.py).
EXTENSION_TO_LANGUAGE: dict[str, LanguagePlugin] = {ext: lang for lang in LANGUAGES for ext in lang.extensions}
Expand Down
605 changes: 605 additions & 0 deletions backend/languages/java.py

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ tree-sitter-rust>=0.23
tree-sitter-typescript>=0.23
tree-sitter-c>=0.23
tree-sitter-cpp>=0.23
tree-sitter-java>=0.23
2 changes: 2 additions & 0 deletions frontend/src/components/FunctionNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "prismjs/components/prism-python";
import "prismjs/components/prism-rust";
import "prismjs/components/prism-c";
import "prismjs/components/prism-cpp";
import "prismjs/components/prism-java";
import "prismjs/components/prism-typescript";
import "prismjs/components/prism-jsx";
import "prismjs/components/prism-tsx";
Expand Down Expand Up @@ -96,6 +97,7 @@ function FunctionNodeInner({ data, selected }: NodeProps<FunctionNodeType>) {
<div className="fn-title">
<div className="fn-name">
{fn.isAsync && <span className="async-badge">ASYNC</span>}
{fn.className?.includes(".") && <span className="nested-badge">NESTED</span>}
{fn.qualname}
</div>
<Signature fn={fn} />
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/GraphCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ export function GraphCanvas() {
<div className="empty-state">
<div className="glyph">⬡</div>
<div className="title">Function Viewer</div>
<div className="sub">Load a Python, Rust, TypeScript, JavaScript, C or C++ file or folder from the sidebar to draw its call graph.</div>
<div className="sub">Load a Python, Rust, TypeScript, JavaScript, C, C++ or Java file or folder from the sidebar to draw its call graph.</div>
</div>
)}
<ReactFlow
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export function Sidebar() {
/>
{error && <div className="error-box">{error}</div>}
{!graph && !error && (
<div className="hint">Pick a Python, Rust, TypeScript, JavaScript, C or C++ file or a folder from your computer, every function inside is analyzed and its calls to other loaded functions become wires.</div>
<div className="hint">Pick a Python, Rust, TypeScript, JavaScript, C, C++ or Java file or a folder from your computer, every function inside is analyzed and its calls to other loaded functions become wires.</div>
)}
</div>

Expand Down
13 changes: 13 additions & 0 deletions frontend/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
--hdr-text-dim: #8497ad;
--hdr-accent: #35c9dd;
--lock: #f0b849;
--nested: #9d7bd8;
}

:root,
Expand Down Expand Up @@ -837,6 +838,18 @@ body {
letter-spacing: 0.08em;
}

.fn-header .fn-name .nested-badge {
font-size: 9px;
font-weight: 600;
color: var(--nested);
border: 1px solid var(--nested);
border-radius: 3px;
padding: 1px 4px;
margin-right: 6px;
vertical-align: 2px;
letter-spacing: 0.08em;
}

.fn-header .fn-sig {
font-size: 11px;
color: color-mix(in srgb, var(--hdr-text) 80%, var(--cat));
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export const LANGUAGES: LanguageDef[] = [
prism: "jsx",
unannotatedReturn: null,
},
// A Java declaration always states its return type, so there is no "unannotated" case to show as None.
{ id: "java", label: "Java", extensions: [".java"], color: "#b07219", mono: "JV", unannotatedReturn: null },
];

/** Flat extension list, also used as the file picker's `accept` attribute. */
Expand Down
11 changes: 11 additions & 0 deletions sample_java_project/com/example/model/Color.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.example.model;

public enum Color {
RED,
GREEN,
BLUE;

public String label() {
return name().toLowerCase();
}
}
31 changes: 31 additions & 0 deletions sample_java_project/com/example/model/Foo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.example.model;

import com.example.service.EnglishGreeter;

/** A small record-holder with a couple of overloaded entry points. */
public class Foo {
private final int id;

public Foo(int id) {
this.id = id;
this.describe();
}

private void describe() {
System.out.println("Foo #" + id);
}

public static void process(int amount) {
System.out.println("processing amount " + amount);
}

public static void process(String label) {
System.out.println("processing " + label);
}

/** Greets the current user through a class in another package. */
public String greetUser() {
EnglishGreeter greeter = new EnglishGreeter();
return greeter.shout();
}
}
20 changes: 20 additions & 0 deletions sample_java_project/com/example/model/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.example.model;

import java.util.List;

/** Wires the other classes in this package together, same-package, no imports needed for them. */
public class Main {
public void run() {
Foo foo = new Foo(1);
Color color = Color.RED;
System.out.println(color.label());

Point point = new Point(2, 3);
System.out.println(point.sum());

List<Foo> foos = List.of(new Foo(2), new Foo(3));
foos.forEach(f -> foo.greetUser());

Foo.process(42);
}
}
7 changes: 7 additions & 0 deletions sample_java_project/com/example/model/Point.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.model;

public record Point(int x, int y) {
public int sum() {
return x + y;
}
}
23 changes: 23 additions & 0 deletions sample_java_project/com/example/service/EnglishGreeter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.example.service;

public class EnglishGreeter implements Greeter {
public EnglishGreeter() {
System.out.println("ready to greet");
}

@Override
public String name() {
return "the English greeter";
}

public String shout() {
Formatter formatter = new Formatter();
return formatter.upper(this.name());
}

static class Formatter {
String upper(String text) {
return text.toUpperCase();
}
}
}
9 changes: 9 additions & 0 deletions sample_java_project/com/example/service/Greeter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.example.service;

public interface Greeter {
default String greet() {
return "Hello from " + name();
}

String name();
}
Loading