java

package
v0.0.0-...-e6b68ed Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package java implement the logic for converting given java source to go source

Index

Constants

View Source
const (
	PUBLIC modifiers = 1 << iota
	PRIVATE
	PROTECTED
	STATIC
	FINAL
	ABSTRACT
)

Modifier bit flags

Variables

This section is empty.

Functions

func Assert

func Assert(msg string, condition bool)

Assert checks a condition and exits with an error message if false

func FatalError

func FatalError(ctx *MigrationContext, node *tree_sitter.Node, msg string, parentName string)

FatalError reports a fatal error and exits (in strict mode) or panics (in non-strict mode) This is useful for errors during type parsing or other operations where graceful recovery is desired

func HasModifier

func HasModifier(ctx *MigrationContext, methodNode *tree_sitter.Node, modifier string) bool

HasModifier checks if a node has a specific modifier

func IsArrayOrSliceType

func IsArrayOrSliceType(ty gosrc.Type) bool

IsArrayOrSliceType checks if a type is an array or slice

func IterateChildren

func IterateChildren(node *tree_sitter.Node, fn func(child *tree_sitter.Node))

IterateChildren iterates over all children of a node and calls fn for each

func IterateChildrenWhile

func IterateChildrenWhile(node *tree_sitter.Node, fn func(child *tree_sitter.Node) bool)

IterateChildrenWhile iterates over all children of a node while fn returns true

func MigrateTree

func MigrateTree(ctx *MigrationContext, tree *tree_sitter.Tree)

MigrateTree migrates a Java tree-sitter tree to Go source

func ParseJava

func ParseJava(source []byte) *tree_sitter.Tree

ParseJava parses Java source code and returns a tree-sitter tree

func ParseModifiers

func ParseModifiers(source string) modifiers

ParseModifiers parses modifier string into a modifiers bitmask

func TryGetChildByFieldName

func TryGetChildByFieldName(node *tree_sitter.Node, fieldName string) *tree_sitter.Node

TryGetChildByFieldName attempts to find a child node by field name

func TryParseType

func TryParseType(ctx *MigrationContext, node *tree_sitter.Node) (gosrc.Type, bool)

TryParseType attempts to parse a tree-sitter node into a Go type

func UnhandledChild

func UnhandledChild(ctx *MigrationContext, node *tree_sitter.Node, parentName string)

UnhandledChild reports an unhandled child node and exits (in strict mode) or panics (in non-strict mode)

Types

type EnumConstant

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

type FunctionData

type FunctionData struct {
	Name          string
	ArgumentTypes []gosrc.Type
}

type MigrationContext

type MigrationContext struct {
	Source                   gosrc.GoSource
	JavaSource               []byte
	SourceFilePath           string // Path to the source Java file
	InReturn                 bool
	AbstractClasses          map[string]bool
	InDefaultMethod          bool
	DefaultMethodSelf        string
	EnumConstants            map[string]string // Maps enum constant name to prefixed name (e.g., "ACTIVE" -> "Status_ACTIVE")
	Constructors             map[gosrc.Type][]FunctionData
	Methods                  map[string][]FunctionData       // Maps method name to method signatures
	MethodMetadataCache      map[uintptr]methodMetadata      // Cache of parsed method signatures by node ID
	ConstructorMetadataCache map[uintptr]constructorMetadata // Cache of parsed constructor signatures by node ID
	StrictMode               bool                            // If true, treat migration errors as fatal
	Errors                   []MigrationError                // Collected migration errors
	TypeMappings             map[string]string
}

MigrationContext holds state during Java to Go migration

func NewMigrationContext

func NewMigrationContext(javaSource []byte, sourceFilePath string, strictMode bool, typeMappings map[string]string) *MigrationContext

TODO: make it possibl to map the std out and std error from outside so we can control this for things like tests NewMigrationContext creates and initializes a new MigrationContext

type MigrationError

type MigrationError struct {
	Location   string // e.g., "class Foo.method bar"
	JavaSource string // The Java code that failed
	SExpr      string // The S-expression
	Message    string // Error message
	NodeKind   string // Type of node (for debugging)
}

MigrationError represents an error that occurred during migration

type MigrationPanic

type MigrationPanic struct {
	Message    string
	JavaSource string
	SExpr      string
	NodeKind   string
	ParentName string
}

MigrationPanic represents a panic during migration with structured error information

Jump to

Keyboard shortcuts

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