java_converter

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 23, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package java_converter lowers Java to Godzilla's gIR by analyzing compiled JVM bytecode. It runs an embedded single-file Java helper (JavaDump.java) via the system `java` launcher — which compiles .java sources in-process (JDK compiler API) and reads .class files with the standard java.lang.classfile API — to get a JSON dump of every method's bytecode, then simulates the operand stack to recover SSA-style values that the language-neutral taint engine understands (see lower.go).

Input may be a single .java/.class file or a directory (walked for both). Self-contained (JDK-only-API) sources compile standalone; sources needing a classpath are best scanned as compiled .class/.jar. A directory carrying a Maven (pom.xml) or Gradle (build.gradle[.kts]) build is compiled with its own build tool first — so third-party dependencies (e.g. a Spring app's spring-web / spring-jdbc) are on the classpath — and the resulting bytecode is analyzed (see resolveInputs). Requires a JDK 24+ `java` on PATH (for the java.lang.classfile API), mirroring how the Python frontend needs `python3`.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsJavaFile

func IsJavaFile(path string) bool

IsJavaFile reports whether path is an input this frontend lowers: a .java source file or a compiled .class file. Exported so internal/scan's language detection and dispatch share ONE predicate with the frontend.

func Usable

func Usable() (int, bool)

Usable reports whether the `java` on PATH is one ConvertFile will accept, and the major version it found (0 when the probe could not determine one).

It is the SAME predicate ConvertFile enforces, exported so a test can skip on what would otherwise fail. Guarding on mere presence of `java` disagrees: an old JDK passes the guard and then fails the conversion, which reads as a broken frontend rather than a missing toolchain.

Types

type Converter

type Converter struct {
	// contains filtered or unexported fields
}

Converter lowers Java source/bytecode into gIR.

func NewConverter

func NewConverter() *Converter

func (*Converter) ConvertFile

func (c *Converter) ConvertFile(path string) (*ir.Program, error)

func (*Converter) ConvertInventory

func (c *Converter) ConvertInventory(inv *walkignore.Inventory) (*ir.Program, error)

ConvertInventory lowers the Java under a pre-walked scan root (see walkignore.Inventory). The JavaDump helper still receives the root directory — its unit of work is a compilation, not a file list — but the .java source index that anchors findings to real paths is derived from the inventory instead of a fresh walk.

func (*Converter) Skipped

func (c *Converter) Skipped() int

Skipped reports how many .java files under the scan root produced no gIR.

This frontend compiles a whole directory as ONE unit, so a collision between independent projects that happen to share class names takes out every file but one — and the survivor still reports a clean conversion. Without this the scan says java=ok having lowered a single file out of fifty, which is exactly the "analyzed and clean" vs "never analyzed" confusion LangCoverage exists to prevent. internal/scan picks it up through the Skipped() duck type that every per-file frontend already satisfies.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL