java

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	JavaTypeClassKind                        = "org.openrewrite.java.tree.JavaType$Class"
	JavaTypeShallowClassKind                 = "org.openrewrite.java.tree.JavaType$ShallowClass"
	JavaTypeParameterizedKind                = "org.openrewrite.java.tree.JavaType$Parameterized"
	JavaTypeGenericTypeVariableKind          = "org.openrewrite.java.tree.JavaType$GenericTypeVariable"
	JavaTypeArrayKind                        = "org.openrewrite.java.tree.JavaType$Array"
	JavaTypePrimitiveKind                    = "org.openrewrite.java.tree.JavaType$Primitive"
	JavaTypeMethodKind                       = "org.openrewrite.java.tree.JavaType$Method"
	JavaTypeVariableKind                     = "org.openrewrite.java.tree.JavaType$Variable"
	JavaTypeAnnotationKind                   = "org.openrewrite.java.tree.JavaType$Annotation"
	JavaTypeAnnotationSingleElementValueKind = "org.openrewrite.java.tree.JavaType$Annotation$SingleElementValue"
	JavaTypeAnnotationArrayElementValueKind  = "org.openrewrite.java.tree.JavaType$Annotation$ArrayElementValue"
	JavaTypeMultiCatchKind                   = "org.openrewrite.java.tree.JavaType$MultiCatch"
	JavaTypeIntersectionKind                 = "org.openrewrite.java.tree.JavaType$Intersection"
	JavaTypeUnknownKind                      = "org.openrewrite.java.tree.JavaType$Unknown"
)

Java class name constants for RPC deserialization.

Variables

View Source
var EmptySpace = Space{}

EmptySpace is the zero-value Space with no whitespace or comments.

View Source
var SingleSpace = Space{Whitespace: " "}

SingleSpace is a Space containing exactly one space character.

View Source
var UnknownType = &JavaTypeUnknown{}

UnknownType is the singleton instance of JavaTypeUnknown.

Functions

func CollectSearchResultIDs

func CollectSearchResultIDs(t Tree) []uuid.UUID

CollectSearchResultIDs walks the given tree and returns the IDs of every SearchResult and SearchResultMarker found in any node's Markers. The returned slice has stable insertion order; duplicates are dropped.

Implementation: reflection-based descent. Every LST node has a `Markers Markers` field, plus zero or more child fields that are themselves trees (or wrappers like RightPadded / LeftPadded / Container holding trees). A visitor-based walker would be cleaner but would require every concrete node type to opt in; reflection lets BatchVisit collect search markers without touching the 60+ node definitions.

func FindMarker

func FindMarker[T any](markers Markers) *T

FindMarker returns a pointer to the first marker of type T, or nil if not found.

func HasMarker

func HasMarker[T any](markers Markers) bool

HasMarker reports whether a marker of type T exists in the markers collection.

func TypeSignature

func TypeSignature(t JavaType) string

TypeSignature computes a string signature for a JavaType, used for list identity tracking in the RPC protocol. Mirrors DefaultJavaTypeSignatureBuilder in Java.

func UnwrapRightPadded

func UnwrapRightPadded[T any](padded []RightPadded[T]) []T

UnwrapRightPadded extracts the elements from a slice of RightPadded wrappers.

Types

type Annotation

type Annotation struct {
	ID             uuid.UUID
	Prefix         Space
	Markers        Markers
	AnnotationType Expression             // NameTree — Identifier or FieldAccess
	Arguments      *Container[Expression] // nullable; tags always have one Literal
}

Annotation represents annotation metadata attached to a declaration. Mirrors org.openrewrite.java.tree.J.Annotation.

Java has first-class `@Annotation(args)` syntax. Go has no `@`, but has two analogous concepts that this type models uniformly:

  1. Struct field tags. Each `key:"value"` pair in a struct field tag becomes one Annotation on the field's VariableDeclarations: AnnotationType = Identifier{Name: key}, Arguments = [Literal{Value: value}]. The printer renders the run of struct-tag annotations on a VariableDeclarations whose parent is a StructType as a single backtick-wrapped tag.

  2. Source directives like `//go:noinline`, `//go:generate`, `//lint:ignore`. Each directive becomes one Annotation on the enclosing MethodDeclaration / TypeDecl / VariableDeclarations: AnnotationType = Identifier{Name: "go:noinline"}, Arguments = [Literal(args)] when the directive carries text after the keyword, else nil.

In both cases, AnnotationType is an Expression (typically Identifier; FieldAccess for qualified directives like `lint:ignore`).

Recipes use AnnotationService to inspect / match / mutate, mirroring Java's AnnotationService surface.

func (*Annotation) GetID

func (n *Annotation) GetID() uuid.UUID

func (*Annotation) GetMarkers

func (n *Annotation) GetMarkers() Markers

func (*Annotation) GetPrefix

func (n *Annotation) GetPrefix() Space

func (*Annotation) IsExpression

func (*Annotation) IsExpression()

func (*Annotation) IsJ

func (*Annotation) IsJ()

func (*Annotation) IsTree

func (*Annotation) IsTree()

func (*Annotation) WithAnnotationType

func (n *Annotation) WithAnnotationType(annotationType Expression) *Annotation

func (*Annotation) WithArguments

func (n *Annotation) WithArguments(arguments *Container[Expression]) *Annotation

func (*Annotation) WithID

func (n *Annotation) WithID(id uuid.UUID) J

func (*Annotation) WithMarkers

func (n *Annotation) WithMarkers(markers Markers) *Annotation

func (*Annotation) WithPrefix

func (n *Annotation) WithPrefix(prefix Space) *Annotation

type ArrayAccess

type ArrayAccess struct {
	ID        uuid.UUID
	Prefix    Space
	Markers   Markers
	Indexed   Expression
	Dimension *ArrayDimension
	Type      JavaType // the result type (nullable)
}

ArrayAccess represents an index expression like `a[i]` or `m[key]`.

func (*ArrayAccess) GetID

func (n *ArrayAccess) GetID() uuid.UUID

func (*ArrayAccess) GetMarkers

func (n *ArrayAccess) GetMarkers() Markers

func (*ArrayAccess) GetPrefix

func (n *ArrayAccess) GetPrefix() Space

func (*ArrayAccess) IsExpression

func (*ArrayAccess) IsExpression()

func (*ArrayAccess) IsJ

func (*ArrayAccess) IsJ()

func (*ArrayAccess) IsTree

func (*ArrayAccess) IsTree()

func (*ArrayAccess) WithID

func (n *ArrayAccess) WithID(id uuid.UUID) J

func (*ArrayAccess) WithMarkers

func (n *ArrayAccess) WithMarkers(markers Markers) *ArrayAccess

func (*ArrayAccess) WithPrefix

func (n *ArrayAccess) WithPrefix(prefix Space) *ArrayAccess

type ArrayDimension

type ArrayDimension struct {
	ID      uuid.UUID
	Prefix  Space
	Markers Markers
	Index   RightPadded[Expression] // Element = index expr, After = space before `]`
}

ArrayDimension represents the `[index]` part of an array access.

func (*ArrayDimension) GetID

func (n *ArrayDimension) GetID() uuid.UUID

func (*ArrayDimension) GetMarkers

func (n *ArrayDimension) GetMarkers() Markers

func (*ArrayDimension) GetPrefix

func (n *ArrayDimension) GetPrefix() Space

func (*ArrayDimension) IsJ

func (*ArrayDimension) IsJ()

func (*ArrayDimension) IsTree

func (*ArrayDimension) IsTree()

func (*ArrayDimension) WithID

func (n *ArrayDimension) WithID(id uuid.UUID) J

func (*ArrayDimension) WithMarkers

func (n *ArrayDimension) WithMarkers(markers Markers) *ArrayDimension

func (*ArrayDimension) WithPrefix

func (n *ArrayDimension) WithPrefix(prefix Space) *ArrayDimension

type ArrayType

type ArrayType struct {
	ID          uuid.UUID
	Prefix      Space
	Markers     Markers
	Dimension   LeftPadded[Space] // Before = space before `[`, Element = space inside brackets before `]`; for `[N]T`, the length expr is stored separately
	Length      Expression        // nil for slices (`[]T`), non-nil for arrays (`[N]T`)
	ElementType Expression        // the element type
	Type        JavaType          // the array type (nullable)
}

ArrayType represents an array or slice type like `[]T`, `[N]T`.

func (*ArrayType) GetID

func (n *ArrayType) GetID() uuid.UUID

func (*ArrayType) GetMarkers

func (n *ArrayType) GetMarkers() Markers

func (*ArrayType) GetPrefix

func (n *ArrayType) GetPrefix() Space

func (*ArrayType) IsExpression

func (*ArrayType) IsExpression()

func (*ArrayType) IsJ

func (*ArrayType) IsJ()

func (*ArrayType) IsTree

func (*ArrayType) IsTree()

func (*ArrayType) WithID

func (n *ArrayType) WithID(id uuid.UUID) J

func (*ArrayType) WithMarkers

func (n *ArrayType) WithMarkers(markers Markers) *ArrayType

func (*ArrayType) WithPrefix

func (n *ArrayType) WithPrefix(prefix Space) *ArrayType

type AssignOp

type AssignOp int

AssignOp distinguishes := from = in assignment contexts.

const (
	AssignOpEquals AssignOp = iota + 1 // =
	AssignOpDefine                     // :=
)

func ParseAssignOp

func ParseAssignOp(s string) AssignOp

ParseAssignOp converts a string to an AssignOp. Accepts both the Go enum names emitted by AssignOp.String() ("Equals", "Define") and the Java-side source-symbol spellings ("=", ":=").

func (AssignOp) String

func (op AssignOp) String() string

String returns a string representation of AssignOp for RPC serialization.

type Assignment

type Assignment struct {
	ID       uuid.UUID
	Prefix   Space
	Markers  Markers
	Variable Expression
	Value    LeftPadded[Expression]
	Type     JavaType // the result type (nullable)
}

Assignment represents an assignment statement like `x = expr`.

func (*Assignment) GetID

func (n *Assignment) GetID() uuid.UUID

func (*Assignment) GetMarkers

func (n *Assignment) GetMarkers() Markers

func (*Assignment) GetPrefix

func (n *Assignment) GetPrefix() Space

func (*Assignment) IsExpression

func (*Assignment) IsExpression()

func (*Assignment) IsJ

func (*Assignment) IsJ()

func (*Assignment) IsStatement

func (*Assignment) IsStatement()

func (*Assignment) IsTree

func (*Assignment) IsTree()

func (*Assignment) WithID

func (n *Assignment) WithID(id uuid.UUID) J

func (*Assignment) WithMarkers

func (n *Assignment) WithMarkers(markers Markers) *Assignment

func (*Assignment) WithPrefix

func (n *Assignment) WithPrefix(prefix Space) *Assignment

func (*Assignment) WithVariable

func (n *Assignment) WithVariable(variable Expression) *Assignment

type AssignmentOperation

type AssignmentOperation struct {
	ID         uuid.UUID
	Prefix     Space
	Markers    Markers
	Variable   Expression
	Operator   LeftPadded[AssignmentOperator]
	Assignment Expression
	Type       JavaType // the result type (nullable)
}

AssignmentOperation represents a compound assignment like `x += expr`.

func (*AssignmentOperation) GetID

func (n *AssignmentOperation) GetID() uuid.UUID

func (*AssignmentOperation) GetMarkers

func (n *AssignmentOperation) GetMarkers() Markers

func (*AssignmentOperation) GetPrefix

func (n *AssignmentOperation) GetPrefix() Space

func (*AssignmentOperation) IsExpression

func (*AssignmentOperation) IsExpression()

func (*AssignmentOperation) IsJ

func (*AssignmentOperation) IsJ()

func (*AssignmentOperation) IsStatement

func (*AssignmentOperation) IsStatement()

func (*AssignmentOperation) IsTree

func (*AssignmentOperation) IsTree()

func (*AssignmentOperation) WithID

func (n *AssignmentOperation) WithID(id uuid.UUID) J

func (*AssignmentOperation) WithMarkers

func (n *AssignmentOperation) WithMarkers(markers Markers) *AssignmentOperation

func (*AssignmentOperation) WithPrefix

func (n *AssignmentOperation) WithPrefix(prefix Space) *AssignmentOperation

func (*AssignmentOperation) WithVariable

func (n *AssignmentOperation) WithVariable(variable Expression) *AssignmentOperation

type AssignmentOperator

type AssignmentOperator int
const (
	AddAssign    AssignmentOperator = iota + 1 // +=
	SubAssign                                  // -=
	MulAssign                                  // *=
	DivAssign                                  // /=
	ModAssign                                  // %=
	AndAssign                                  // &=
	OrAssign                                   // |=
	XorAssign                                  // ^=
	ShlAssign                                  // <<=
	ShrAssign                                  // >>=
	AndNotAssign                               // &^= (Go-specific)
)

func ParseAssignmentOperator

func ParseAssignmentOperator(s string) AssignmentOperator

ParseAssignmentOperator converts a Java enum name to an AssignmentOperator.

func (AssignmentOperator) String

func (op AssignmentOperator) String() string

String returns the Java enum name for this AssignmentOperator.

type Binary

type Binary struct {
	ID       uuid.UUID
	Prefix   Space
	Markers  Markers
	Left     Expression
	Operator LeftPadded[BinaryOperator]
	Right    Expression
	Type     JavaType // the result type (nullable)
}

Binary represents a binary expression like `a + b`.

func (*Binary) GetID

func (n *Binary) GetID() uuid.UUID

func (*Binary) GetMarkers

func (n *Binary) GetMarkers() Markers

func (*Binary) GetPrefix

func (n *Binary) GetPrefix() Space

func (*Binary) IsExpression

func (*Binary) IsExpression()

func (*Binary) IsJ

func (*Binary) IsJ()

func (*Binary) IsTree

func (*Binary) IsTree()

func (*Binary) WithID

func (n *Binary) WithID(id uuid.UUID) J

func (*Binary) WithLeft

func (n *Binary) WithLeft(left Expression) *Binary

func (*Binary) WithMarkers

func (n *Binary) WithMarkers(markers Markers) *Binary

func (*Binary) WithPrefix

func (n *Binary) WithPrefix(prefix Space) *Binary

func (*Binary) WithRight

func (n *Binary) WithRight(right Expression) *Binary

type BinaryOperator

type BinaryOperator int

BinaryOperator represents the operator in a binary expression.

const (
	Add BinaryOperator = iota + 1
	Subtract
	Multiply
	Divide
	Modulo
	And
	Or
	BitwiseAnd
	BitwiseOr
	BitwiseXor
	LeftShift
	RightShift
	Equal
	NotEqual
	LessThan
	LessThanOrEqual
	GreaterThan
	GreaterThanOrEqual
	LogicalAnd
	LogicalOr
	AndNot // Go-specific: &^
)

func ParseBinaryOperator

func ParseBinaryOperator(s string) BinaryOperator

ParseBinaryOperator converts a Java enum name to a BinaryOperator.

func (BinaryOperator) String

func (op BinaryOperator) String() string

String returns the Java enum name for this BinaryOperator.

type Block

type Block struct {
	ID         uuid.UUID
	Prefix     Space
	Markers    Markers
	Statements []RightPadded[Statement]
	End        Space // whitespace before the closing brace
}

Block represents a brace-delimited block of statements.

func (*Block) GetID

func (n *Block) GetID() uuid.UUID

func (*Block) GetMarkers

func (n *Block) GetMarkers() Markers

func (*Block) GetPrefix

func (n *Block) GetPrefix() Space

func (*Block) IsJ

func (*Block) IsJ()

func (*Block) IsStatement

func (*Block) IsStatement()

func (*Block) IsTree

func (*Block) IsTree()

func (*Block) WithEnd

func (n *Block) WithEnd(end Space) *Block

func (*Block) WithID

func (n *Block) WithID(id uuid.UUID) J

func (*Block) WithMarkers

func (n *Block) WithMarkers(markers Markers) *Block

func (*Block) WithPrefix

func (n *Block) WithPrefix(prefix Space) *Block

func (*Block) WithStatements

func (n *Block) WithStatements(statements []RightPadded[Statement]) *Block

type Break

type Break struct {
	ID      uuid.UUID
	Prefix  Space
	Markers Markers
	Label   *Identifier // nil if no label
}

Break represents a break statement with optional label.

func (*Break) GetID

func (n *Break) GetID() uuid.UUID

func (*Break) GetMarkers

func (n *Break) GetMarkers() Markers

func (*Break) GetPrefix

func (n *Break) GetPrefix() Space

func (*Break) IsJ

func (*Break) IsJ()

func (*Break) IsStatement

func (*Break) IsStatement()

func (*Break) IsTree

func (*Break) IsTree()

func (*Break) WithID

func (n *Break) WithID(id uuid.UUID) J

func (*Break) WithMarkers

func (n *Break) WithMarkers(markers Markers) *Break

func (*Break) WithPrefix

func (n *Break) WithPrefix(prefix Space) *Break

type Case

type Case struct {
	ID          uuid.UUID
	Prefix      Space
	Markers     Markers
	Expressions Container[Expression]    // empty for default case
	Body        []RightPadded[Statement] // statements after the colon
}

Case represents a case or default clause in a switch statement.

func (*Case) GetID

func (n *Case) GetID() uuid.UUID

func (*Case) GetMarkers

func (n *Case) GetMarkers() Markers

func (*Case) GetPrefix

func (n *Case) GetPrefix() Space

func (*Case) IsJ

func (*Case) IsJ()

func (*Case) IsStatement

func (*Case) IsStatement()

func (*Case) IsTree

func (*Case) IsTree()

func (*Case) WithID

func (n *Case) WithID(id uuid.UUID) J

func (*Case) WithMarkers

func (n *Case) WithMarkers(markers Markers) *Case

func (*Case) WithPrefix

func (n *Case) WithPrefix(prefix Space) *Case

type Comment

type Comment struct {
	Kind      CommentKind
	Text      string
	Suffix    string // whitespace after the comment, before the next token
	Multiline bool
	Markers   Markers
}

Comment represents a comment in source code.

type CommentKind

type CommentKind int
const (
	LineComment CommentKind = iota
	BlockComment
)

type Container

type Container[T any] struct {
	Before   Space
	Elements []RightPadded[T]
	Markers  Markers
}

Container wraps a list of elements with surrounding whitespace, representing constructs like parenthesized argument lists or bracketed type parameters.

type Continue

type Continue struct {
	ID      uuid.UUID
	Prefix  Space
	Markers Markers
	Label   *Identifier // nil if no label
}

Continue represents a continue statement with optional label.

func (*Continue) GetID

func (n *Continue) GetID() uuid.UUID

func (*Continue) GetMarkers

func (n *Continue) GetMarkers() Markers

func (*Continue) GetPrefix

func (n *Continue) GetPrefix() Space

func (*Continue) IsJ

func (*Continue) IsJ()

func (*Continue) IsStatement

func (*Continue) IsStatement()

func (*Continue) IsTree

func (*Continue) IsTree()

func (*Continue) WithID

func (n *Continue) WithID(id uuid.UUID) J

func (*Continue) WithMarkers

func (n *Continue) WithMarkers(markers Markers) *Continue

func (*Continue) WithPrefix

func (n *Continue) WithPrefix(prefix Space) *Continue

type ControlParentheses

type ControlParentheses struct {
	ID      uuid.UUID
	Prefix  Space
	Markers Markers
	Tree    RightPadded[Expression] // Element = inner, After = space before `)`
}

ControlParentheses wraps an expression in parentheses for control flow.

func (*ControlParentheses) GetID

func (n *ControlParentheses) GetID() uuid.UUID

func (*ControlParentheses) GetMarkers

func (n *ControlParentheses) GetMarkers() Markers

func (*ControlParentheses) GetPrefix

func (n *ControlParentheses) GetPrefix() Space

func (*ControlParentheses) IsExpression

func (*ControlParentheses) IsExpression()

func (*ControlParentheses) IsJ

func (*ControlParentheses) IsJ()

func (*ControlParentheses) IsTree

func (*ControlParentheses) IsTree()

func (*ControlParentheses) WithID

func (n *ControlParentheses) WithID(id uuid.UUID) J

func (*ControlParentheses) WithMarkers

func (n *ControlParentheses) WithMarkers(markers Markers) *ControlParentheses

func (*ControlParentheses) WithPrefix

func (n *ControlParentheses) WithPrefix(prefix Space) *ControlParentheses

type Else

type Else struct {
	ID      uuid.UUID
	Prefix  Space
	Markers Markers
	Body    RightPadded[Statement]
}

Else represents an else clause of an if statement. This matches Java's J.If.Else for RPC wire format compatibility.

func (*Else) GetID

func (n *Else) GetID() uuid.UUID

func (*Else) GetMarkers

func (n *Else) GetMarkers() Markers

func (*Else) GetPrefix

func (n *Else) GetPrefix() Space

func (*Else) IsJ

func (*Else) IsJ()

func (*Else) IsTree

func (*Else) IsTree()

func (*Else) WithID

func (n *Else) WithID(id uuid.UUID) J

func (*Else) WithMarkers

func (n *Else) WithMarkers(markers Markers) *Else

func (*Else) WithPrefix

func (n *Else) WithPrefix(prefix Space) *Else

type Empty

type Empty struct {
	ID      uuid.UUID
	Prefix  Space
	Markers Markers
}

Empty represents an empty statement or expression placeholder.

func (*Empty) GetID

func (n *Empty) GetID() uuid.UUID

func (*Empty) GetMarkers

func (n *Empty) GetMarkers() Markers

func (*Empty) GetPrefix

func (n *Empty) GetPrefix() Space

func (*Empty) IsExpression

func (*Empty) IsExpression()

func (*Empty) IsJ

func (*Empty) IsJ()

func (*Empty) IsStatement

func (*Empty) IsStatement()

func (*Empty) IsTree

func (*Empty) IsTree()

func (*Empty) WithID

func (n *Empty) WithID(id uuid.UUID) J

func (*Empty) WithPrefix

func (n *Empty) WithPrefix(prefix Space) *Empty

type Expression

type Expression interface {
	J
	IsExpression()
}

Expression is a J node that evaluates to a value.

type FieldAccess

type FieldAccess struct {
	ID      uuid.UUID
	Prefix  Space
	Markers Markers
	Target  Expression
	Name    LeftPadded[*Identifier]
	Type    JavaType // the result type (nullable)
}

FieldAccess represents a field or method access like `obj.Field`.

func (*FieldAccess) GetID

func (n *FieldAccess) GetID() uuid.UUID

func (*FieldAccess) GetMarkers

func (n *FieldAccess) GetMarkers() Markers

func (*FieldAccess) GetPrefix

func (n *FieldAccess) GetPrefix() Space

func (*FieldAccess) IsExpression

func (*FieldAccess) IsExpression()

func (*FieldAccess) IsJ

func (*FieldAccess) IsJ()

func (*FieldAccess) IsTree

func (*FieldAccess) IsTree()

func (*FieldAccess) WithID

func (n *FieldAccess) WithID(id uuid.UUID) J

func (*FieldAccess) WithMarkers

func (n *FieldAccess) WithMarkers(markers Markers) *FieldAccess

func (*FieldAccess) WithPrefix

func (n *FieldAccess) WithPrefix(prefix Space) *FieldAccess

func (*FieldAccess) WithTarget

func (n *FieldAccess) WithTarget(target Expression) *FieldAccess

type ForControl

type ForControl struct {
	ID        uuid.UUID
	Prefix    Space
	Markers   Markers
	Init      *RightPadded[Statement]  // nil for condition-only or infinite loops
	Condition *RightPadded[Expression] // nil for infinite loops
	Update    *RightPadded[Statement]  // nil when no update clause
}

ForControl holds the init, condition, and update of a for loop. When Init is non-nil, this is a 3-clause loop with semicolons; Init.After and Condition.After capture whitespace around semicolons. When Init is nil and Condition is non-nil, it's a condition-only loop (no semicolons). When both are nil, it's an infinite loop.

func (*ForControl) GetID

func (n *ForControl) GetID() uuid.UUID

func (*ForControl) GetMarkers

func (n *ForControl) GetMarkers() Markers

func (*ForControl) GetPrefix

func (n *ForControl) GetPrefix() Space

func (*ForControl) IsJ

func (*ForControl) IsJ()

func (*ForControl) IsTree

func (*ForControl) IsTree()

func (*ForControl) WithID

func (n *ForControl) WithID(id uuid.UUID) J

func (*ForControl) WithMarkers

func (n *ForControl) WithMarkers(markers Markers) *ForControl

func (*ForControl) WithPrefix

func (n *ForControl) WithPrefix(prefix Space) *ForControl

type ForEachControl

type ForEachControl struct {
	ID       uuid.UUID
	Prefix   Space
	Markers  Markers
	Key      *RightPadded[Expression] // nil for `for range expr`; After = space after key (including comma)
	Value    *RightPadded[Expression] // nil when no value; After = space before operator
	Operator LeftPadded[AssignOp]     // `:=` or `=`; Before = space before operator. Unused when Key is nil
	Iterable Expression               // expression after "range" keyword
}

ForEachControl holds the variable and iterable of a for-range loop. The "range" keyword is implicit (always present).

Structure: `for` [key] [`,` value] [`:=`|`=`] `range` iterable

  • Key and Value may be nil (e.g., `for range expr {}`)
  • When Key is non-nil, Operator contains `:=` or `=`

func (*ForEachControl) GetID

func (n *ForEachControl) GetID() uuid.UUID

func (*ForEachControl) GetMarkers

func (n *ForEachControl) GetMarkers() Markers

func (*ForEachControl) GetPrefix

func (n *ForEachControl) GetPrefix() Space

func (*ForEachControl) IsJ

func (*ForEachControl) IsJ()

func (*ForEachControl) IsTree

func (*ForEachControl) IsTree()

func (*ForEachControl) WithID

func (n *ForEachControl) WithID(id uuid.UUID) J

func (*ForEachControl) WithMarkers

func (n *ForEachControl) WithMarkers(markers Markers) *ForEachControl

func (*ForEachControl) WithPrefix

func (n *ForEachControl) WithPrefix(prefix Space) *ForEachControl

type ForEachLoop

type ForEachLoop struct {
	ID      uuid.UUID
	Prefix  Space
	Markers Markers
	Control ForEachControl
	Body    *Block
}

ForEachLoop represents a for-range loop: `for k, v := range expr { body }`

func (*ForEachLoop) GetID

func (n *ForEachLoop) GetID() uuid.UUID

func (*ForEachLoop) GetMarkers

func (n *ForEachLoop) GetMarkers() Markers

func (*ForEachLoop) GetPrefix

func (n *ForEachLoop) GetPrefix() Space

func (*ForEachLoop) IsJ

func (*ForEachLoop) IsJ()

func (*ForEachLoop) IsStatement

func (*ForEachLoop) IsStatement()

func (*ForEachLoop) IsTree

func (*ForEachLoop) IsTree()

func (*ForEachLoop) WithBody

func (n *ForEachLoop) WithBody(body *Block) *ForEachLoop

func (*ForEachLoop) WithID

func (n *ForEachLoop) WithID(id uuid.UUID) J

func (*ForEachLoop) WithMarkers

func (n *ForEachLoop) WithMarkers(markers Markers) *ForEachLoop

func (*ForEachLoop) WithPrefix

func (n *ForEachLoop) WithPrefix(prefix Space) *ForEachLoop

type ForLoop

type ForLoop struct {
	ID      uuid.UUID
	Prefix  Space
	Markers Markers
	Control ForControl
	Body    *Block
}

ForLoop represents a classic for loop: `for init; cond; update { body }` Also covers condition-only `for cond {}` and infinite `for {}`.

func (*ForLoop) GetID

func (n *ForLoop) GetID() uuid.UUID

func (*ForLoop) GetMarkers

func (n *ForLoop) GetMarkers() Markers

func (*ForLoop) GetPrefix

func (n *ForLoop) GetPrefix() Space

func (*ForLoop) IsJ

func (*ForLoop) IsJ()

func (*ForLoop) IsStatement

func (*ForLoop) IsStatement()

func (*ForLoop) IsTree

func (*ForLoop) IsTree()

func (*ForLoop) WithBody

func (n *ForLoop) WithBody(body *Block) *ForLoop

func (*ForLoop) WithID

func (n *ForLoop) WithID(id uuid.UUID) J

func (*ForLoop) WithMarkers

func (n *ForLoop) WithMarkers(markers Markers) *ForLoop

func (*ForLoop) WithPrefix

func (n *ForLoop) WithPrefix(prefix Space) *ForLoop

type FullyQualified

type FullyQualified interface {
	JavaType
	GetFullyQualifiedName() string
}

FullyQualified is a JavaType with a fully qualified name.

type GenericMarker

type GenericMarker struct {
	Ident    uuid.UUID
	JavaType string // Original Java class name for round-trip fidelity
	Data     map[string]any
}

GenericMarker is a marker type for Java-side markers that the Go side doesn't have a native type for (e.g., RecipesThatMadeChanges, SearchResult). It preserves the marker data as opaque fields during RPC round-trips.

func (GenericMarker) ID

func (m GenericMarker) ID() uuid.UUID

type GoProject

type GoProject struct {
	Ident       uuid.UUID
	ProjectName string
}

GoProject identifies the Go project (logical grouping of go.mod + .go files) a source belongs to. Mirrors org.openrewrite.golang.marker.GoProject on the Java side.

func NewGoProject

func NewGoProject(projectName string) GoProject

NewGoProject creates a GoProject marker with a new UUID.

func (GoProject) ID

func (m GoProject) ID() uuid.UUID

type Identifier

type Identifier struct {
	ID          uuid.UUID
	Prefix      Space
	Markers     Markers
	Annotations []Tree // Java annotations on this identifier (empty in Go, received from Java)
	Name        string
	Type        JavaType          // the type of this identifier (nullable)
	FieldType   *JavaTypeVariable // the variable type when this identifier refers to a field (nullable)
}

Identifier represents a name reference in source code.

func (*Identifier) GetID

func (n *Identifier) GetID() uuid.UUID

func (*Identifier) GetMarkers

func (n *Identifier) GetMarkers() Markers

func (*Identifier) GetPrefix

func (n *Identifier) GetPrefix() Space

func (*Identifier) IsExpression

func (*Identifier) IsExpression()

func (*Identifier) IsJ

func (*Identifier) IsJ()

func (*Identifier) IsTree

func (*Identifier) IsTree()

func (*Identifier) WithFieldType

func (n *Identifier) WithFieldType(ft *JavaTypeVariable) *Identifier

func (*Identifier) WithID

func (n *Identifier) WithID(id uuid.UUID) J

func (*Identifier) WithMarkers

func (n *Identifier) WithMarkers(markers Markers) *Identifier

func (*Identifier) WithName

func (n *Identifier) WithName(name string) *Identifier

func (*Identifier) WithPrefix

func (n *Identifier) WithPrefix(prefix Space) *Identifier

func (*Identifier) WithType

func (n *Identifier) WithType(t JavaType) *Identifier

type If

type If struct {
	ID          uuid.UUID
	Prefix      Space
	Markers     Markers
	Init        *RightPadded[Statement] // nil if no init; After = space before `;`
	Condition   Expression
	ConditionCP *ControlParentheses // cached ControlParentheses from RPC round-trip
	Then        *Block
	ElsePart    *RightPadded[J] // nil if no else clause
}

If represents an if statement. In Go, if can have an init statement: `if init; cond { }`.

func (*If) GetID

func (n *If) GetID() uuid.UUID

func (*If) GetMarkers

func (n *If) GetMarkers() Markers

func (*If) GetPrefix

func (n *If) GetPrefix() Space

func (*If) IsJ

func (*If) IsJ()

func (*If) IsStatement

func (*If) IsStatement()

func (*If) IsTree

func (*If) IsTree()

func (*If) WithCondition

func (n *If) WithCondition(condition Expression) *If

func (*If) WithID

func (n *If) WithID(id uuid.UUID) J

func (*If) WithMarkers

func (n *If) WithMarkers(markers Markers) *If

func (*If) WithPrefix

func (n *If) WithPrefix(prefix Space) *If

func (*If) WithThen

func (n *If) WithThen(then *Block) *If

type Import

type Import struct {
	ID      uuid.UUID
	Prefix  Space
	Markers Markers
	Alias   *LeftPadded[*Identifier] // nil if no alias
	Qualid  Expression               // typically *Literal for Go imports
}

Import represents a single import declaration.

func (*Import) GetID

func (n *Import) GetID() uuid.UUID

func (*Import) GetMarkers

func (n *Import) GetMarkers() Markers

func (*Import) GetPrefix

func (n *Import) GetPrefix() Space

func (*Import) IsJ

func (*Import) IsJ()

func (*Import) IsTree

func (*Import) IsTree()

func (*Import) WithID

func (n *Import) WithID(id uuid.UUID) J

func (*Import) WithMarkers

func (n *Import) WithMarkers(markers Markers) *Import

func (*Import) WithPrefix

func (n *Import) WithPrefix(prefix Space) *Import

type J

type J interface {
	Tree
	IsJ()
	GetID() uuid.UUID
	WithID(uuid.UUID) J
	GetPrefix() Space
	GetMarkers() Markers
}

J is the interface for all Java-like AST nodes that carry a prefix space. Mirrors org.openrewrite.java.tree.J — `getId`, `getPrefix`, `getMarkers` are polymorphic accessors so RPC senders, receivers, and other framework code can read the cross-cutting fields without per-type switches.

Concrete impls live in j_methods.go (keep in sync with the J types in j.go and go.go).

Mutation: the J interface exposes only the common ID wither. For prefix/markers, use the typed `WithPrefix(Space) *T` / `WithMarkers(Markers) *T` per-type methods — they return a *new* instance so the visitor framework's change-detection (pointer identity) works correctly. Framework code that needs to invoke those polymorphically (e.g. the RPC receiver's PreVisit) goes through reflection — see the `withPrefixViaReflection` helper in pkg/rpc.

In-place mutation of Prefix / Markers / ID is never safe because it would silently bypass RecipeScheduler's "did this recipe change the tree?" check.

type JavaType

type JavaType interface {
	// contains filtered or unexported methods
}

JavaType is the interface for all Java type representations used for type attribution.

type JavaTypeAnnotation

type JavaTypeAnnotation struct {
	Type   FullyQualified
	Values []JavaTypeAnnotationElementValue
}

JavaTypeAnnotation represents an annotation type reference.

type JavaTypeAnnotationArrayElementValue

type JavaTypeAnnotationArrayElementValue struct {
	Element         JavaType
	ConstantValues  []any
	ReferenceValues []JavaType
}

JavaTypeAnnotationArrayElementValue is an array of annotation element values.

func (*JavaTypeAnnotationArrayElementValue) GetElement

type JavaTypeAnnotationElementValue

type JavaTypeAnnotationElementValue interface {
	GetElement() JavaType
	// contains filtered or unexported methods
}

JavaTypeAnnotationElementValue is the interface for annotation element values. One of *JavaTypeAnnotationSingleElementValue or *JavaTypeAnnotationArrayElementValue.

type JavaTypeAnnotationSingleElementValue

type JavaTypeAnnotationSingleElementValue struct {
	Element        JavaType
	ConstantValue  any
	ReferenceValue JavaType
}

JavaTypeAnnotationSingleElementValue is a single annotation element value (one constant or one reference). Java parser puts class literals and enum constants in ReferenceValue; only String/Number/Boolean/Character live in ConstantValue.

func (*JavaTypeAnnotationSingleElementValue) GetElement

type JavaTypeArray

type JavaTypeArray struct {
	ElemType    JavaType
	Annotations []FullyQualified
}

JavaTypeArray represents an array type.

type JavaTypeClass

type JavaTypeClass struct {
	FlagsBitMap        int64
	Kind               string
	FullyQualifiedName string
	TypeParameters     []JavaType
	Supertype          FullyQualified
	OwningClass        FullyQualified
	Annotations        []FullyQualified
	Interfaces         []FullyQualified
	Members            []*JavaTypeVariable
	Methods            []*JavaTypeMethod
}

JavaTypeClass represents a class, interface, enum, or annotation type.

func (*JavaTypeClass) GetFullyQualifiedName

func (c *JavaTypeClass) GetFullyQualifiedName() string

type JavaTypeGenericTypeVariable

type JavaTypeGenericTypeVariable struct {
	Name     string
	Variance string
	Bounds   []JavaType
}

JavaTypeGenericTypeVariable represents a generic type variable like T extends Comparable.

type JavaTypeIntersection

type JavaTypeIntersection struct {
	Bounds []JavaType
}

JavaTypeIntersection represents an intersection type (e.g., Serializable & Comparable).

type JavaTypeMethod

type JavaTypeMethod struct {
	DeclaringType           FullyQualified
	Name                    string
	FlagsBitMap             int64
	ReturnType              JavaType
	ParameterNames          []string
	ParameterTypes          []JavaType
	ThrownExceptions        []JavaType
	Annotations             []FullyQualified
	DefaultValue            []string
	DeclaredFormalTypeNames []string
}

JavaTypeMethod represents a method type signature.

type JavaTypeMultiCatch

type JavaTypeMultiCatch struct {
	ThrowableTypes []JavaType
}

JavaTypeMultiCatch represents a multi-catch type (e.g., IOException | SQLException).

type JavaTypeParameterized

type JavaTypeParameterized struct {
	Type           FullyQualified
	TypeParameters []JavaType
}

JavaTypeParameterized represents a parameterized type like List<String>.

func (*JavaTypeParameterized) GetFullyQualifiedName

func (p *JavaTypeParameterized) GetFullyQualifiedName() string

type JavaTypePrimitive

type JavaTypePrimitive struct {
	Keyword string
}

JavaTypePrimitive represents a primitive type like int, boolean, etc.

type JavaTypeShallowClass

type JavaTypeShallowClass struct {
	JavaTypeClass
}

JavaTypeShallowClass mirrors Java's JavaType.ShallowClass — a Class instance that carries minimal metadata (kind, FQN, owning class) and otherwise behaves identically to JavaTypeClass. The wire format preserves the distinction; on the Go side the embedded JavaTypeClass supplies all fields and accessors.

type JavaTypeUnknown

type JavaTypeUnknown struct{}

JavaTypeUnknown represents an unknown or unresolved type.

type JavaTypeVariable

type JavaTypeVariable struct {
	Name        string
	Owner       JavaType
	Type        JavaType
	Annotations []FullyQualified
}

JavaTypeVariable represents a variable type.

type Label

type Label struct {
	ID        uuid.UUID
	Prefix    Space
	Markers   Markers
	Name      RightPadded[*Identifier] // After = space before ':'
	Statement Statement
}

Label represents a labeled statement: `label: stmt`.

func (*Label) GetID

func (n *Label) GetID() uuid.UUID

func (*Label) GetMarkers

func (n *Label) GetMarkers() Markers

func (*Label) GetPrefix

func (n *Label) GetPrefix() Space

func (*Label) IsJ

func (*Label) IsJ()

func (*Label) IsStatement

func (*Label) IsStatement()

func (*Label) IsTree

func (*Label) IsTree()

func (*Label) WithID

func (n *Label) WithID(id uuid.UUID) J

func (*Label) WithMarkers

func (n *Label) WithMarkers(markers Markers) *Label

func (*Label) WithPrefix

func (n *Label) WithPrefix(prefix Space) *Label

type LeftPadded

type LeftPadded[T any] struct {
	Before  Space
	Element T
	Markers Markers
}

LeftPadded wraps an element with preceding whitespace/comments. Used for operators and delimiters where whitespace appears before the element (e.g., the space before an operator in a binary expression).

type Literal

type Literal struct {
	ID      uuid.UUID
	Prefix  Space
	Markers Markers
	Kind    LiteralKind
	Value   any
	Source  string   // the original source text of the literal
	Type    JavaType // the type of this literal (nullable)
}

Literal represents a literal value (string, number, boolean, etc.).

func (*Literal) GetID

func (n *Literal) GetID() uuid.UUID

func (*Literal) GetMarkers

func (n *Literal) GetMarkers() Markers

func (*Literal) GetPrefix

func (n *Literal) GetPrefix() Space

func (*Literal) IsExpression

func (*Literal) IsExpression()

func (*Literal) IsJ

func (*Literal) IsJ()

func (*Literal) IsTree

func (*Literal) IsTree()

func (*Literal) WithID

func (n *Literal) WithID(id uuid.UUID) J

func (*Literal) WithMarkers

func (n *Literal) WithMarkers(markers Markers) *Literal

func (*Literal) WithPrefix

func (n *Literal) WithPrefix(prefix Space) *Literal

func (*Literal) WithSource

func (n *Literal) WithSource(source string) *Literal

func (*Literal) WithValue

func (n *Literal) WithValue(value any) *Literal

type LiteralKind

type LiteralKind int
const (
	BoolLiteral LiteralKind = iota
	IntLiteral
	FloatLiteral
	StringLiteral
	CharLiteral
	NilLiteral
)

type Marker

type Marker interface {
	ID() uuid.UUID
}

Marker is metadata attached to an LST node without modifying the tree structure.

type Markers

type Markers struct {
	ID      uuid.UUID
	Entries []Marker
}

Markers holds a collection of Marker instances attached to a tree node.

func AddMarker

func AddMarker(markers Markers, marker Marker) Markers

AddMarker returns a new Markers with the given marker appended.

func FoundSearchResult

func FoundSearchResult(markers Markers, description string) Markers

FoundSearchResult attaches a SearchResult marker to the given Markers.

func MarkupError

func MarkupError(markers Markers, message string) Markers

MarkupError attaches an error-level Markup marker to the given Markers.

func MarkupInfo

func MarkupInfo(markers Markers, message string) Markers

MarkupInfo attaches an info-level Markup marker to the given Markers.

func MarkupWarn

func MarkupWarn(markers Markers, message string) Markers

MarkupWarn attaches a warning-level Markup marker to the given Markers.

func MarkupWarnDetail

func MarkupWarnDetail(markers Markers, message, detail string) Markers

MarkupWarnDetail attaches a warning-level Markup marker with detail to the given Markers.

type Markup

type Markup struct {
	Ident   uuid.UUID
	Level   MarkupLevel
	Message string
	Detail  string
}

Markup is a marker for attaching diagnostic messages to LST nodes. It is rendered as a comment in printed output (e.g., /*~~(message: detail)~~>*/).

func NewMarkup

func NewMarkup(level MarkupLevel, message, detail string) Markup

NewMarkup creates a Markup marker with the given level and message.

func (Markup) ID

func (m Markup) ID() uuid.UUID

type MarkupLevel

type MarkupLevel int

MarkupLevel indicates the severity of a Markup marker.

const (
	MarkupDebugLevel MarkupLevel = iota
	MarkupInfoLevel
	MarkupWarnLevel
	MarkupErrorLevel
)

type MethodDeclaration

type MethodDeclaration struct {
	ID                 uuid.UUID
	Prefix             Space
	Markers            Markers
	LeadingAnnotations []*Annotation         // `//go:noinline` / `//go:nosplit` etc. on funcs
	Receiver           *Container[Statement] // nil for free functions; `(r *Type)` receiver
	Name               *Identifier
	TypeParameters     *TypeParameters      // nil for non-generic functions; `[T any]` declaration-site type params
	Parameters         Container[Statement] // parameter list in parentheses
	ReturnType         Expression           // nil for void functions; single type or *TypeList for multiple
	Body               *Block               // nil for forward declarations
	MethodType         *JavaTypeMethod      // the method type signature (nullable)
}

MethodDeclaration represents a function or method declaration.

func (*MethodDeclaration) GetID

func (n *MethodDeclaration) GetID() uuid.UUID

func (*MethodDeclaration) GetMarkers

func (n *MethodDeclaration) GetMarkers() Markers

func (*MethodDeclaration) GetPrefix

func (n *MethodDeclaration) GetPrefix() Space

func (*MethodDeclaration) IsExpression

func (*MethodDeclaration) IsExpression()

func (*MethodDeclaration) IsJ

func (*MethodDeclaration) IsJ()

func (*MethodDeclaration) IsStatement

func (*MethodDeclaration) IsStatement()

func (*MethodDeclaration) IsTree

func (*MethodDeclaration) IsTree()

func (*MethodDeclaration) WithBody

func (n *MethodDeclaration) WithBody(body *Block) *MethodDeclaration

func (*MethodDeclaration) WithID

func (n *MethodDeclaration) WithID(id uuid.UUID) J

func (*MethodDeclaration) WithLeadingAnnotations

func (n *MethodDeclaration) WithLeadingAnnotations(anns []*Annotation) *MethodDeclaration

func (*MethodDeclaration) WithMarkers

func (n *MethodDeclaration) WithMarkers(markers Markers) *MethodDeclaration

func (*MethodDeclaration) WithName

func (n *MethodDeclaration) WithName(name *Identifier) *MethodDeclaration

func (*MethodDeclaration) WithPrefix

func (n *MethodDeclaration) WithPrefix(prefix Space) *MethodDeclaration

func (*MethodDeclaration) WithTypeParameters added in v0.0.5

func (n *MethodDeclaration) WithTypeParameters(tps *TypeParameters) *MethodDeclaration

type MethodInvocation

type MethodInvocation struct {
	ID         uuid.UUID
	Prefix     Space
	Markers    Markers
	Select     *RightPadded[Expression] // nil for free functions
	Name       *Identifier
	Arguments  Container[Expression]
	MethodType *JavaTypeMethod // the method type being invoked (nullable)
}

MethodInvocation represents a function or method call like `f(args)`.

func (*MethodInvocation) GetID

func (n *MethodInvocation) GetID() uuid.UUID

func (*MethodInvocation) GetMarkers

func (n *MethodInvocation) GetMarkers() Markers

func (*MethodInvocation) GetPrefix

func (n *MethodInvocation) GetPrefix() Space

func (*MethodInvocation) IsExpression

func (*MethodInvocation) IsExpression()

func (*MethodInvocation) IsJ

func (*MethodInvocation) IsJ()

func (*MethodInvocation) IsStatement

func (*MethodInvocation) IsStatement()

func (*MethodInvocation) IsTree

func (*MethodInvocation) IsTree()

func (*MethodInvocation) WithID

func (n *MethodInvocation) WithID(id uuid.UUID) J

func (*MethodInvocation) WithMarkers

func (n *MethodInvocation) WithMarkers(markers Markers) *MethodInvocation

func (*MethodInvocation) WithName

func (n *MethodInvocation) WithName(name *Identifier) *MethodInvocation

func (*MethodInvocation) WithPrefix

func (n *MethodInvocation) WithPrefix(prefix Space) *MethodInvocation

type ParameterizedType

type ParameterizedType struct {
	ID             uuid.UUID
	Prefix         Space
	Markers        Markers
	Clazz          Expression             // the base type being parameterized
	TypeParameters *Container[Expression] // the type arguments (nullable)
	Type           JavaType               // resolved type (nullable)
}

ParameterizedType represents a generic type instantiation like `List[string]`.

func (*ParameterizedType) GetID

func (n *ParameterizedType) GetID() uuid.UUID

func (*ParameterizedType) GetMarkers

func (n *ParameterizedType) GetMarkers() Markers

func (*ParameterizedType) GetPrefix

func (n *ParameterizedType) GetPrefix() Space

func (*ParameterizedType) IsExpression

func (*ParameterizedType) IsExpression()

func (*ParameterizedType) IsJ

func (*ParameterizedType) IsJ()

func (*ParameterizedType) IsTree

func (*ParameterizedType) IsTree()

func (*ParameterizedType) WithID

func (n *ParameterizedType) WithID(id uuid.UUID) J

func (*ParameterizedType) WithMarkers

func (n *ParameterizedType) WithMarkers(markers Markers) *ParameterizedType

func (*ParameterizedType) WithPrefix

func (n *ParameterizedType) WithPrefix(prefix Space) *ParameterizedType

type Parentheses

type Parentheses struct {
	ID      uuid.UUID
	Prefix  Space
	Markers Markers
	Tree    RightPadded[Expression] // Element = inner expr, After = space before `)`
	Type    JavaType                // the result type (nullable)
}

Parentheses wraps an expression in parentheses: `(expr)`.

func (*Parentheses) GetID

func (n *Parentheses) GetID() uuid.UUID

func (*Parentheses) GetMarkers

func (n *Parentheses) GetMarkers() Markers

func (*Parentheses) GetPrefix

func (n *Parentheses) GetPrefix() Space

func (*Parentheses) IsExpression

func (*Parentheses) IsExpression()

func (*Parentheses) IsJ

func (*Parentheses) IsJ()

func (*Parentheses) IsTree

func (*Parentheses) IsTree()

func (*Parentheses) WithID

func (n *Parentheses) WithID(id uuid.UUID) J

func (*Parentheses) WithMarkers

func (n *Parentheses) WithMarkers(markers Markers) *Parentheses

func (*Parentheses) WithPrefix

func (n *Parentheses) WithPrefix(prefix Space) *Parentheses

type ParseError

type ParseError struct {
	Ident            uuid.UUID
	Markers          Markers
	SourcePath       string
	CharsetName      string
	CharsetBomMarked bool
	Text             string
}

ParseError represents a source file that failed to parse. Mirrors org.openrewrite.tree.ParseError on the Java side.

func NewParseError

func NewParseError(sourcePath string, source string, err error) *ParseError

NewParseError creates a ParseError from a source path, source text, and error.

func (*ParseError) IsTree

func (*ParseError) IsTree()

ParseError isn't a J node (no Prefix, no acceptVisitor double- dispatch in the J hierarchy) but it does flow through the same Tree-typed Visit pipeline as a SourceFile alternate, so it satisfies Tree to allow visitor.GoVisitor.Visit to receive it. The visitor framework's switch has no case for ParseError; it falls through to the default arm. RPC senders/receivers special-case it ahead of the dispatch.

type ParseExceptionResult

type ParseExceptionResult struct {
	Ident         uuid.UUID
	ParserType    string
	ExceptionType string
	Message       string
	TreeType      *string // nullable
}

ParseExceptionResult is a marker that captures information about a parse failure. Mirrors org.openrewrite.ParseExceptionResult on the Java side.

func (ParseExceptionResult) ID

type Return

type Return struct {
	ID         uuid.UUID
	Prefix     Space
	Markers    Markers
	Expression Expression // nil for a naked `return`
}

Return represents a return statement. Mirrors Java's J.Return: a single, nullable returned expression. Go return statements with more than one value map to golang.Return instead.

func (*Return) GetID

func (n *Return) GetID() uuid.UUID

func (*Return) GetMarkers

func (n *Return) GetMarkers() Markers

func (*Return) GetPrefix

func (n *Return) GetPrefix() Space

func (*Return) IsJ

func (*Return) IsJ()

func (*Return) IsStatement

func (*Return) IsStatement()

func (*Return) IsTree

func (*Return) IsTree()

func (*Return) WithID

func (n *Return) WithID(id uuid.UUID) J

func (*Return) WithMarkers

func (n *Return) WithMarkers(markers Markers) *Return

func (*Return) WithPrefix

func (n *Return) WithPrefix(prefix Space) *Return

type RightPadded

type RightPadded[T any] struct {
	Element T
	After   Space
	Markers Markers
}

RightPadded wraps an element with trailing whitespace/comments. Used for list elements where whitespace appears after the element (e.g., before a comma or closing delimiter).

type SearchResult

type SearchResult struct {
	Ident       uuid.UUID
	Description string
}

SearchResult is a marker indicating that a search recipe found a match. It is rendered as a comment in printed output (e.g., /*~~(description)~~>*/).

func NewSearchResult

func NewSearchResult(description string) SearchResult

NewSearchResult creates a SearchResult marker with a new UUID.

func (SearchResult) ID

func (s SearchResult) ID() uuid.UUID

type SearchResultMarker

type SearchResultMarker struct {
	Ident       uuid.UUID
	Description string
}

SearchResultMarker represents a SearchResult marker from Java. It implements RpcCodec on the Java side, sending 2 sub-fields (id, description).

func (SearchResultMarker) ID

func (m SearchResultMarker) ID() uuid.UUID

type Semicolon

type Semicolon struct {
	Ident uuid.UUID
}

Semicolon marks a RightPadded element that is followed by an explicit `;` separator in the source — i.e. multiple statements on one line: `_ = 1; _ = 2`. Go inserts implicit semicolons at end-of-line so most files don't need this marker; it's only emitted when the source literally has a `;` between statements that the printer must reproduce.

Mirrors org.openrewrite.java.marker.Semicolon on the Java side.

func NewSemicolon

func NewSemicolon() Semicolon

NewSemicolon creates a Semicolon marker with a fresh UUID.

func (Semicolon) ID

func (m Semicolon) ID() uuid.UUID

type SourceFile

type SourceFile interface {
	J
	IsSourceFile()
}

SourceFile is a J node representing an entire source file.

type Space

type Space struct {
	Comments   []Comment
	Whitespace string
}

Space represents whitespace and comments that appear before a syntax element. This is the fundamental unit of formatting preservation in OpenRewrite.

func ParseSpace

func ParseSpace(raw string) Space

ParseSpace parses raw text (between two token positions) into a Space, extracting any line comments (//) and block comments (/* */).

The model follows Java OpenRewrite's convention:

  • Space.Whitespace = whitespace BEFORE the first comment
  • Comment.Suffix = whitespace AFTER each comment

The printer emits: Whitespace + (Comment.Text + Comment.Suffix)* to reconstruct the original text.

func (Space) Indent

func (s Space) Indent() string

Indent returns the indentation of this space, which is the whitespace after the last newline (or all whitespace if no newline is present).

func (Space) IsEmpty

func (s Space) IsEmpty() bool

IsEmpty returns true if this Space has no whitespace and no comments.

type Statement

type Statement interface {
	J
	IsStatement()
}

Statement is a J node that can appear at statement level.

type Switch

type Switch struct {
	ID      uuid.UUID
	Prefix  Space
	Markers Markers
	Init    *RightPadded[Statement]  // optional init statement; After = space after semicolon
	Tag     *RightPadded[Expression] // optional tag expression; After = space before {
	Body    *Block                   // contains Case statements
}

Switch represents a switch statement.

func (*Switch) GetID

func (n *Switch) GetID() uuid.UUID

func (*Switch) GetMarkers

func (n *Switch) GetMarkers() Markers

func (*Switch) GetPrefix

func (n *Switch) GetPrefix() Space

func (*Switch) IsJ

func (*Switch) IsJ()

func (*Switch) IsStatement

func (*Switch) IsStatement()

func (*Switch) IsTree

func (*Switch) IsTree()

func (*Switch) WithBody

func (n *Switch) WithBody(body *Block) *Switch

func (*Switch) WithID

func (n *Switch) WithID(id uuid.UUID) J

func (*Switch) WithMarkers

func (n *Switch) WithMarkers(markers Markers) *Switch

func (*Switch) WithPrefix

func (n *Switch) WithPrefix(prefix Space) *Switch

type Tree

type Tree interface{ IsTree() }

Tree is the root interface for all LST nodes.

type TypeCast

type TypeCast struct {
	ID      uuid.UUID
	Prefix  Space
	Markers Markers
	Clazz   *ControlParentheses // the type in parentheses
	Expr    Expression          // the expression being cast/asserted
	Type    JavaType            // the result type (nullable)
}

TypeCast represents a type assertion or type cast: `x.(T)` in Go.

func (*TypeCast) GetID

func (n *TypeCast) GetID() uuid.UUID

func (*TypeCast) GetMarkers

func (n *TypeCast) GetMarkers() Markers

func (*TypeCast) GetPrefix

func (n *TypeCast) GetPrefix() Space

func (*TypeCast) IsExpression

func (*TypeCast) IsExpression()

func (*TypeCast) IsJ

func (*TypeCast) IsJ()

func (*TypeCast) IsTree

func (*TypeCast) IsTree()

func (*TypeCast) WithID

func (n *TypeCast) WithID(id uuid.UUID) J

func (*TypeCast) WithMarkers

func (n *TypeCast) WithMarkers(markers Markers) *TypeCast

func (*TypeCast) WithPrefix

func (n *TypeCast) WithPrefix(prefix Space) *TypeCast

type TypeParameter added in v0.0.5

type TypeParameter struct {
	ID          uuid.UUID
	Prefix      Space
	Markers     Markers
	Annotations []*Annotation
	Name        Expression
	Bounds      *Container[Expression]
}

TypeParameter represents a single declaration-site type parameter, e.g. Go `T any` (Java `T extends Foo`). The constraint (Go) / bound (Java) lives in Bounds as a single-element container; it is nil when the parameter shares a later sibling's constraint, as in `[T, U any]`. Maps to org.openrewrite.java.tree.J$TypeParameter.

func (*TypeParameter) GetID added in v0.0.5

func (n *TypeParameter) GetID() uuid.UUID

func (*TypeParameter) GetMarkers added in v0.0.5

func (n *TypeParameter) GetMarkers() Markers

func (*TypeParameter) GetPrefix added in v0.0.5

func (n *TypeParameter) GetPrefix() Space

func (*TypeParameter) IsJ added in v0.0.5

func (*TypeParameter) IsJ()

func (*TypeParameter) IsTree added in v0.0.5

func (*TypeParameter) IsTree()

func (*TypeParameter) WithID added in v0.0.5

func (n *TypeParameter) WithID(id uuid.UUID) J

func (*TypeParameter) WithMarkers added in v0.0.5

func (n *TypeParameter) WithMarkers(markers Markers) *TypeParameter

func (*TypeParameter) WithPrefix added in v0.0.5

func (n *TypeParameter) WithPrefix(prefix Space) *TypeParameter

type TypeParameters added in v0.0.5

type TypeParameters struct {
	ID          uuid.UUID
	Prefix      Space
	Markers     Markers
	Annotations []*Annotation
	// Elements are *TypeParameter. Typed as RightPadded[J] so the RPC padding
	// machinery (which reconstructs J-only nodes as RightPadded[J]) round-trips
	// them without bespoke type-switch cases.
	TypeParameters []RightPadded[J]
}

TypeParameters represents a declaration-site type parameter list, e.g. Go `[T any, U comparable]` (Java `<T, U>`). Maps to org.openrewrite.java.tree.J$TypeParameters.

func (*TypeParameters) GetID added in v0.0.5

func (n *TypeParameters) GetID() uuid.UUID

func (*TypeParameters) GetMarkers added in v0.0.5

func (n *TypeParameters) GetMarkers() Markers

func (*TypeParameters) GetPrefix added in v0.0.5

func (n *TypeParameters) GetPrefix() Space

func (*TypeParameters) IsJ added in v0.0.5

func (*TypeParameters) IsJ()

func (*TypeParameters) IsTree added in v0.0.5

func (*TypeParameters) IsTree()

func (*TypeParameters) WithID added in v0.0.5

func (n *TypeParameters) WithID(id uuid.UUID) J

func (*TypeParameters) WithMarkers added in v0.0.5

func (n *TypeParameters) WithMarkers(markers Markers) *TypeParameters

func (*TypeParameters) WithPrefix added in v0.0.5

func (n *TypeParameters) WithPrefix(prefix Space) *TypeParameters

type Unary

type Unary struct {
	ID       uuid.UUID
	Prefix   Space
	Markers  Markers
	Operator LeftPadded[UnaryOperator]
	Operand  Expression
	Type     JavaType // the result type (nullable)
}

Unary represents a unary expression like `-x` or `!y`.

func (*Unary) GetID

func (n *Unary) GetID() uuid.UUID

func (*Unary) GetMarkers

func (n *Unary) GetMarkers() Markers

func (*Unary) GetPrefix

func (n *Unary) GetPrefix() Space

func (*Unary) IsExpression

func (*Unary) IsExpression()

func (*Unary) IsJ

func (*Unary) IsJ()

func (*Unary) IsStatement

func (*Unary) IsStatement()

func (*Unary) IsTree

func (*Unary) IsTree()

func (*Unary) WithID

func (n *Unary) WithID(id uuid.UUID) J

func (*Unary) WithMarkers

func (n *Unary) WithMarkers(markers Markers) *Unary

func (*Unary) WithOperand

func (n *Unary) WithOperand(operand Expression) *Unary

func (*Unary) WithPrefix

func (n *Unary) WithPrefix(prefix Space) *Unary

type UnaryOperator

type UnaryOperator int
const (
	Negate        UnaryOperator = iota + 1 // -
	Not                                    // !
	BitwiseNot                             // ^
	Deref                                  // *
	AddressOf                              // &
	Receive                                // <- (channel receive, Go-specific)
	Positive                               // +
	PostIncrement                          // ++ (postfix)
	PostDecrement                          // -- (postfix)
	Spread                                 // ... (variadic prefix, param declaration)
	SpreadPostfix                          // ... (variadic postfix, call site)
	Tilde                                  // ~ (approximate type constraint, Go-specific)
)

func ParseUnaryOperator

func ParseUnaryOperator(s string) UnaryOperator

ParseUnaryOperator converts a Java enum name to a UnaryOperator.

func (UnaryOperator) String

func (op UnaryOperator) String() string

String returns the Java enum name for this UnaryOperator.

type VariableDeclarations

type VariableDeclarations struct {
	ID                 uuid.UUID
	Prefix             Space
	Markers            Markers
	LeadingAnnotations []*Annotation                      // struct field tags (one per `key:"value"` pair) or `//go:` directives
	TypeExpr           Expression                         // the declared type (nil if inferred)
	Varargs            *Space                             // non-nil for variadic params (`...T`); holds prefix of `...`
	Variables          []RightPadded[*VariableDeclarator] // the declared variables
	Specs              *Container[Statement]              // non-nil for grouped `var ( ... )`; Before = space before `(`
}

VariableDeclarations represents one or more variable declarations. For grouped declarations `var ( ... )` or `const ( ... )`, Specs is non-nil and Variables/TypeExpr are unused.

func (*VariableDeclarations) GetID

func (n *VariableDeclarations) GetID() uuid.UUID

func (*VariableDeclarations) GetMarkers

func (n *VariableDeclarations) GetMarkers() Markers

func (*VariableDeclarations) GetPrefix

func (n *VariableDeclarations) GetPrefix() Space

func (*VariableDeclarations) IsJ

func (*VariableDeclarations) IsJ()

func (*VariableDeclarations) IsStatement

func (*VariableDeclarations) IsStatement()

func (*VariableDeclarations) IsTree

func (*VariableDeclarations) IsTree()

func (*VariableDeclarations) WithID

func (n *VariableDeclarations) WithID(id uuid.UUID) J

func (*VariableDeclarations) WithLeadingAnnotations

func (n *VariableDeclarations) WithLeadingAnnotations(anns []*Annotation) *VariableDeclarations

func (*VariableDeclarations) WithMarkers

func (n *VariableDeclarations) WithMarkers(markers Markers) *VariableDeclarations

func (*VariableDeclarations) WithPrefix

func (n *VariableDeclarations) WithPrefix(prefix Space) *VariableDeclarations

type VariableDeclarator

type VariableDeclarator struct {
	ID          uuid.UUID
	Prefix      Space
	Markers     Markers
	Name        *Identifier
	Initializer *LeftPadded[Expression] // nil if no initializer
}

VariableDeclarator represents a single variable with optional initializer.

func (*VariableDeclarator) GetID

func (n *VariableDeclarator) GetID() uuid.UUID

func (*VariableDeclarator) GetMarkers

func (n *VariableDeclarator) GetMarkers() Markers

func (*VariableDeclarator) GetPrefix

func (n *VariableDeclarator) GetPrefix() Space

func (*VariableDeclarator) IsJ

func (*VariableDeclarator) IsJ()

func (*VariableDeclarator) IsTree

func (*VariableDeclarator) IsTree()

func (*VariableDeclarator) WithID

func (n *VariableDeclarator) WithID(id uuid.UUID) J

func (*VariableDeclarator) WithMarkers

func (n *VariableDeclarator) WithMarkers(markers Markers) *VariableDeclarator

func (*VariableDeclarator) WithName

func (n *VariableDeclarator) WithName(name *Identifier) *VariableDeclarator

func (*VariableDeclarator) WithPrefix

func (n *VariableDeclarator) WithPrefix(prefix Space) *VariableDeclarator

Jump to

Keyboard shortcuts

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