printer

package
v0.0.15 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GoCommentWrapper

func GoCommentWrapper(output string) string

GoCommentWrapper wraps marker output in Go block comment syntax: /*~~(output)~~>*/

func Print

func Print(t java.Tree) string

Print renders the given tree to a string.

func PrintGoMod added in v0.0.9

func PrintGoMod(gm *golang.GoMod) string

PrintGoMod renders a GoMod LST back to source. Because every byte of whitespace and every comment is preserved on the tree, an unmodified GoMod prints to exactly the bytes it was parsed from.

func PrintGoModWithMarkers added in v0.0.10

func PrintGoModWithMarkers(gm *golang.GoMod, mp MarkerPrinter) string

PrintGoModWithMarkers renders a GoMod LST to source, printing cross-cutting markers (SearchResult, Markup) via the given MarkerPrinter. With a nil-free marker printer that emits nothing for a node, the output is byte-identical to PrintGoMod — so search recipes can be tested with the same /*~~>*/ convention used for .go sources.

func PrintWithMarkers

func PrintWithMarkers(t java.Tree, mp MarkerPrinter) string

PrintWithMarkers renders the given tree to a string, printing cross-cutting markers (SearchResult, Markup) using the given MarkerPrinter.

Types

type CommentWrapper

type CommentWrapper func(output string) string

CommentWrapper wraps marker output in a language-appropriate comment syntax.

type GoPrinter

type GoPrinter struct {
	visitor.GoVisitor
}

GoPrinter prints an OpenRewrite LST back to Go source code.

func NewGoPrinter

func NewGoPrinter() *GoPrinter

func (*GoPrinter) VisitAnnotation

func (p *GoPrinter) VisitAnnotation(ann *java.Annotation, param any) java.J

VisitAnnotation prints an Annotation in struct-tag form (`key:"value"`) — including its leading whitespace via Prefix. Backtick wrapping is the VariableDeclarations printer's job for struct-field context; this method only emits the annotation's own substring.

func (*GoPrinter) VisitArrayAccess

func (p *GoPrinter) VisitArrayAccess(aa *java.ArrayAccess, param any) java.J

func (*GoPrinter) VisitArrayDimension

func (p *GoPrinter) VisitArrayDimension(ad *java.ArrayDimension, param any) java.J

func (*GoPrinter) VisitArrayType

func (p *GoPrinter) VisitArrayType(at *java.ArrayType, param any) java.J

func (*GoPrinter) VisitAssignment

func (p *GoPrinter) VisitAssignment(assign *java.Assignment, param any) java.J

func (*GoPrinter) VisitAssignmentOperation

func (p *GoPrinter) VisitAssignmentOperation(ao *java.AssignmentOperation, param any) java.J

func (*GoPrinter) VisitBinary

func (p *GoPrinter) VisitBinary(bin *java.Binary, param any) java.J

func (*GoPrinter) VisitBlock

func (p *GoPrinter) VisitBlock(block *java.Block, param any) java.J

func (*GoPrinter) VisitBreak

func (p *GoPrinter) VisitBreak(b *java.Break, param any) java.J

func (*GoPrinter) VisitCase

func (p *GoPrinter) VisitCase(c *java.Case, param any) java.J

func (*GoPrinter) VisitChannel

func (p *GoPrinter) VisitChannel(ch *golang.Channel, param any) java.J

func (*GoPrinter) VisitCommClause

func (p *GoPrinter) VisitCommClause(cc *golang.CommClause, param any) java.J

func (*GoPrinter) VisitCompilationUnit

func (p *GoPrinter) VisitCompilationUnit(cu *golang.CompilationUnit, param any) java.J

func (*GoPrinter) VisitComposite

func (p *GoPrinter) VisitComposite(c *golang.Composite, param any) java.J

func (*GoPrinter) VisitContinue

func (p *GoPrinter) VisitContinue(c *java.Continue, param any) java.J

func (*GoPrinter) VisitControlParentheses

func (p *GoPrinter) VisitControlParentheses(cp *java.ControlParentheses, param any) java.J

func (*GoPrinter) VisitDeclarationBlock added in v0.0.12

func (p *GoPrinter) VisitDeclarationBlock(db *golang.DeclarationBlock, param any) java.J

func (*GoPrinter) VisitDefer

func (p *GoPrinter) VisitDefer(d *golang.Defer, param any) java.J

func (*GoPrinter) VisitEmpty

func (p *GoPrinter) VisitEmpty(empty *java.Empty, param any) java.J

func (*GoPrinter) VisitFallthrough

func (p *GoPrinter) VisitFallthrough(f *golang.Fallthrough, param any) java.J

func (*GoPrinter) VisitFieldAccess

func (p *GoPrinter) VisitFieldAccess(fa *java.FieldAccess, param any) java.J

func (*GoPrinter) VisitForControl

func (p *GoPrinter) VisitForControl(control *java.ForControl, param any) java.J

func (*GoPrinter) VisitForEachControl

func (p *GoPrinter) VisitForEachControl(control *java.ForEachControl, param any) java.J

func (*GoPrinter) VisitForEachLoop

func (p *GoPrinter) VisitForEachLoop(forEach *java.ForEachLoop, param any) java.J

func (*GoPrinter) VisitForLoop

func (p *GoPrinter) VisitForLoop(forLoop *java.ForLoop, param any) java.J

func (*GoPrinter) VisitFuncType

func (p *GoPrinter) VisitFuncType(ft *golang.FuncType, param any) java.J

func (*GoPrinter) VisitGoArrayType added in v0.0.13

func (p *GoPrinter) VisitGoArrayType(at *golang.ArrayType, param any) java.J

func (*GoPrinter) VisitGoAssignmentOperation added in v0.0.6

func (p *GoPrinter) VisitGoAssignmentOperation(ao *golang.AssignmentOperation, param any) java.J

func (*GoPrinter) VisitGoBinary added in v0.0.6

func (p *GoPrinter) VisitGoBinary(binary *golang.Binary, param any) java.J

func (*GoPrinter) VisitGoMethodDeclaration added in v0.0.12

func (p *GoPrinter) VisitGoMethodDeclaration(md *golang.MethodDeclaration, param any) java.J

VisitGoMethodDeclaration prints a method declaration with a receiver. The wrapper owns the prefix and the receiver, but both are emitted by the inner declaration's VisitMethodDeclaration (which sources them via the cursor), keeping the receiver correctly positioned between `func` and the name and the prefix after any leading `//go:` directives. So this just visits the inner.

func (*GoPrinter) VisitGoReturn added in v0.0.11

func (p *GoPrinter) VisitGoReturn(ret *golang.Return, param any) java.J

func (*GoPrinter) VisitGoStmt

func (p *GoPrinter) VisitGoStmt(g *golang.GoStmt, param any) java.J

func (*GoPrinter) VisitGoUnary added in v0.0.6

func (p *GoPrinter) VisitGoUnary(unary *golang.Unary, param any) java.J

func (*GoPrinter) VisitGoVariadic added in v0.0.6

func (p *GoPrinter) VisitGoVariadic(v *golang.Variadic, param any) java.J

func (*GoPrinter) VisitGoto

func (p *GoPrinter) VisitGoto(g *golang.Goto, param any) java.J

func (*GoPrinter) VisitIdentifier

func (p *GoPrinter) VisitIdentifier(ident *java.Identifier, param any) java.J

func (*GoPrinter) VisitIf

func (p *GoPrinter) VisitIf(ifStmt *java.If, param any) java.J

func (*GoPrinter) VisitImport

func (p *GoPrinter) VisitImport(imp *java.Import, param any) java.J

func (*GoPrinter) VisitIndexList

func (p *GoPrinter) VisitIndexList(il *golang.IndexList, param any) java.J

func (*GoPrinter) VisitInterfaceType

func (p *GoPrinter) VisitInterfaceType(it *golang.InterfaceType, param any) java.J

func (*GoPrinter) VisitKeyValue

func (p *GoPrinter) VisitKeyValue(kv *golang.KeyValue, param any) java.J

func (*GoPrinter) VisitLabel

func (p *GoPrinter) VisitLabel(l *java.Label, param any) java.J

func (*GoPrinter) VisitLiteral

func (p *GoPrinter) VisitLiteral(lit *java.Literal, param any) java.J

func (*GoPrinter) VisitMapType

func (p *GoPrinter) VisitMapType(mt *golang.MapType, param any) java.J

func (*GoPrinter) VisitMethodDeclaration

func (p *GoPrinter) VisitMethodDeclaration(md *java.MethodDeclaration, param any) java.J

func (*GoPrinter) VisitMethodInvocation

func (p *GoPrinter) VisitMethodInvocation(mi *java.MethodInvocation, param any) java.J

func (*GoPrinter) VisitMultiAssignment

func (p *GoPrinter) VisitMultiAssignment(ma *golang.MultiAssignment, param any) java.J

func (*GoPrinter) VisitParameterizedType

func (p *GoPrinter) VisitParameterizedType(pt *java.ParameterizedType, param any) java.J

func (*GoPrinter) VisitParentheses

func (p *GoPrinter) VisitParentheses(paren *java.Parentheses, param any) java.J

func (*GoPrinter) VisitPointerType

func (p *GoPrinter) VisitPointerType(pt *golang.PointerType, param any) java.J

func (*GoPrinter) VisitReturn

func (p *GoPrinter) VisitReturn(ret *java.Return, param any) java.J

func (*GoPrinter) VisitSend

func (p *GoPrinter) VisitSend(s *golang.Send, param any) java.J

func (*GoPrinter) VisitSlice

func (p *GoPrinter) VisitSlice(s *golang.Slice, param any) java.J

func (*GoPrinter) VisitStatementExpression

func (p *GoPrinter) VisitStatementExpression(se *golang.StatementExpression, param any) java.J

func (*GoPrinter) VisitStatementWithInit added in v0.0.13

func (p *GoPrinter) VisitStatementWithInit(s *golang.StatementWithInit, param any) java.J

VisitStatementWithInit prints an if/switch carrying an init clause. The wrapper owns the prefix and the init statement, but both are emitted by the inner statement's VisitIf/VisitSwitch (which source them via the cursor), keeping `<init>;` correctly positioned between the keyword and the condition. So this just visits the inner statement.

func (*GoPrinter) VisitStructType

func (p *GoPrinter) VisitStructType(st *golang.StructType, param any) java.J

func (*GoPrinter) VisitSwitch

func (p *GoPrinter) VisitSwitch(sw *java.Switch, param any) java.J

func (*GoPrinter) VisitTypeCast

func (p *GoPrinter) VisitTypeCast(tc *java.TypeCast, param any) java.J

func (*GoPrinter) VisitTypeDecl

func (p *GoPrinter) VisitTypeDecl(td *golang.TypeDecl, param any) java.J

func (*GoPrinter) VisitTypeList

func (p *GoPrinter) VisitTypeList(tl *golang.TypeList, param any) java.J

func (*GoPrinter) VisitTypeParameter added in v0.0.5

func (p *GoPrinter) VisitTypeParameter(tp *java.TypeParameter, param any) java.J

func (*GoPrinter) VisitTypeParameters added in v0.0.5

func (p *GoPrinter) VisitTypeParameters(tps *java.TypeParameters, param any) java.J

func (*GoPrinter) VisitUnary

func (p *GoPrinter) VisitUnary(unary *java.Unary, param any) java.J

func (*GoPrinter) VisitUnderlyingType added in v0.0.5

func (p *GoPrinter) VisitUnderlyingType(ut *golang.UnderlyingType, param any) java.J

func (*GoPrinter) VisitUnion added in v0.0.5

func (p *GoPrinter) VisitUnion(u *golang.Union, param any) java.J

func (*GoPrinter) VisitVariableDeclarations

func (p *GoPrinter) VisitVariableDeclarations(vd *java.VariableDeclarations, param any) java.J

func (*GoPrinter) VisitVariableDeclarator

func (p *GoPrinter) VisitVariableDeclarator(vd *java.VariableDeclarator, param any) java.J

type MarkerPrinter

type MarkerPrinter interface {
	// BeforePrefix returns text to emit before a node's prefix space.
	BeforePrefix(marker java.Marker, wrapper CommentWrapper) string

	// BeforeSyntax returns text to emit after a node's prefix but before its syntax.
	BeforeSyntax(marker java.Marker, wrapper CommentWrapper) string

	// AfterSyntax returns text to emit after a node's syntax.
	AfterSyntax(marker java.Marker, wrapper CommentWrapper) string
}

MarkerPrinter controls how cross-cutting markers (like SearchResult and Markup) are rendered in printed output. Go-specific markers (ShortVarDecl, GroupedImport, etc.) are handled directly by the printer's visit methods.

var DefaultMarkerPrinter MarkerPrinter = defaultMarkerPrinter{}

DefaultMarkerPrinter prints SearchResult and Markup markers as comments before syntax.

var FencedMarkerPrinter MarkerPrinter = fencedMarkerPrinter{}

FencedMarkerPrinter wraps markers with {{uuid}} delimiters before and after syntax.

var SanitizedMarkerPrinter MarkerPrinter = sanitizedMarkerPrinter{}

SanitizedMarkerPrinter strips all markers from output.

var SearchOnlyMarkerPrinter MarkerPrinter = searchOnlyMarkerPrinter{}

SearchOnlyMarkerPrinter prints only SearchResult markers (ignores Markup).

type PrintOutputCapture

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

PrintOutputCapture accumulates printed source code text.

func NewPrintOutputCapture

func NewPrintOutputCapture() *PrintOutputCapture

NewPrintOutputCapture creates a PrintOutputCapture with no marker printer.

func NewPrintOutputCaptureWithMarkers

func NewPrintOutputCaptureWithMarkers(mp MarkerPrinter) *PrintOutputCapture

NewPrintOutputCaptureWithMarkers creates a PrintOutputCapture with the given MarkerPrinter.

func (*PrintOutputCapture) AfterSyntax

func (p *PrintOutputCapture) AfterSyntax(markers java.Markers)

AfterSyntax emits marker output after a node's syntax.

func (*PrintOutputCapture) Append

func (p *PrintOutputCapture) Append(s string)

func (*PrintOutputCapture) BeforePrefix

func (p *PrintOutputCapture) BeforePrefix(markers java.Markers)

BeforePrefix emits marker output before a node's prefix space.

func (*PrintOutputCapture) BeforeSyntax

func (p *PrintOutputCapture) BeforeSyntax(markers java.Markers)

BeforeSyntax emits marker output after a node's prefix but before its syntax.

func (*PrintOutputCapture) String

func (p *PrintOutputCapture) String() string

Jump to

Keyboard shortcuts

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