Documentation
¶
Overview ¶
Package java implement the logic for converting given java source to go source
Index ¶
- Constants
- func Assert(msg string, condition bool)
- func FatalError(ctx *MigrationContext, node *tree_sitter.Node, msg string, parentName string)
- func HasModifier(ctx *MigrationContext, methodNode *tree_sitter.Node, modifier string) bool
- func IsArrayOrSliceType(ty gosrc.Type) bool
- func IterateChildren(node *tree_sitter.Node, fn func(child *tree_sitter.Node))
- func IterateChildrenWhile(node *tree_sitter.Node, fn func(child *tree_sitter.Node) bool)
- func MigrateTree(ctx *MigrationContext, tree *tree_sitter.Tree)
- func ParseJava(source []byte) *tree_sitter.Tree
- func ParseModifiers(source string) modifiers
- func TryGetChildByFieldName(node *tree_sitter.Node, fieldName string) *tree_sitter.Node
- func TryParseType(ctx *MigrationContext, node *tree_sitter.Node) (gosrc.Type, bool)
- func UnhandledChild(ctx *MigrationContext, node *tree_sitter.Node, parentName string)
- type EnumConstant
- type FunctionData
- type MigrationContext
- type MigrationError
- type MigrationPanic
Constants ¶
const ( PUBLIC modifiers = 1 << iota PRIVATE PROTECTED STATIC FINAL ABSTRACT )
Modifier bit flags
Variables ¶
This section is empty.
Functions ¶
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 ¶
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 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