printer

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 18, 2026 License: Apache-2.0 Imports: 4 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 tree.Tree) string

Print renders the given tree to a string.

func PrintWithMarkers

func PrintWithMarkers(t tree.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 *tree.Annotation, param any) tree.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 *tree.ArrayAccess, param any) tree.J

func (*GoPrinter) VisitArrayDimension

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

func (*GoPrinter) VisitArrayType

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

func (*GoPrinter) VisitAssignment

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

func (*GoPrinter) VisitAssignmentOperation

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

func (*GoPrinter) VisitBinary

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

func (*GoPrinter) VisitBlock

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

func (*GoPrinter) VisitBreak

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

func (*GoPrinter) VisitCase

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

func (*GoPrinter) VisitChannel

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

func (*GoPrinter) VisitCommClause

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

func (*GoPrinter) VisitCompilationUnit

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

func (*GoPrinter) VisitComposite

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

func (*GoPrinter) VisitContinue

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

func (*GoPrinter) VisitControlParentheses

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

func (*GoPrinter) VisitDefer

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

func (*GoPrinter) VisitEmpty

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

func (*GoPrinter) VisitFallthrough

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

func (*GoPrinter) VisitFieldAccess

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

func (*GoPrinter) VisitForControl

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

func (*GoPrinter) VisitForEachControl

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

func (*GoPrinter) VisitForEachLoop

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

func (*GoPrinter) VisitForLoop

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

func (*GoPrinter) VisitFuncType

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

func (*GoPrinter) VisitGoStmt

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

func (*GoPrinter) VisitGoto

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

func (*GoPrinter) VisitIdentifier

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

func (*GoPrinter) VisitIf

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

func (*GoPrinter) VisitImport

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

func (*GoPrinter) VisitIndexList

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

func (*GoPrinter) VisitInterfaceType

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

func (*GoPrinter) VisitKeyValue

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

func (*GoPrinter) VisitLabel

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

func (*GoPrinter) VisitLiteral

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

func (*GoPrinter) VisitMapType

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

func (*GoPrinter) VisitMethodDeclaration

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

func (*GoPrinter) VisitMethodInvocation

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

func (*GoPrinter) VisitMultiAssignment

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

func (*GoPrinter) VisitParameterizedType

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

func (*GoPrinter) VisitParentheses

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

func (*GoPrinter) VisitPointerType

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

func (*GoPrinter) VisitReturn

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

func (*GoPrinter) VisitSend

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

func (*GoPrinter) VisitSlice

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

func (*GoPrinter) VisitStatementExpression

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

func (*GoPrinter) VisitStructType

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

func (*GoPrinter) VisitSwitch

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

func (*GoPrinter) VisitTypeCast

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

func (*GoPrinter) VisitTypeDecl

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

func (*GoPrinter) VisitTypeList

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

func (*GoPrinter) VisitUnary

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

func (*GoPrinter) VisitVariableDeclarations

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

func (*GoPrinter) VisitVariableDeclarator

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

type MarkerPrinter

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

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

	// AfterSyntax returns text to emit after a node's syntax.
	AfterSyntax(marker tree.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 tree.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 tree.Markers)

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

func (*PrintOutputCapture) BeforeSyntax

func (p *PrintOutputCapture) BeforeSyntax(markers tree.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