func TypeErrorEndPos(fset *token.FileSet, src []byte, start token.Pos) token.Pos { … } func ZeroValue(f *ast.File, pkg *types.Package, typ types.Type) ast.Expr { … } // IsZeroValue checks whether the given expression is a 'zero value' (as determined by output of // analysisinternal.ZeroValue) func IsZeroValue(expr ast.Expr) bool { … } // TypeExpr returns syntax for the specified type. References to // named types from packages other than pkg are qualified by an appropriate // package name, as defined by the import environment of file. func TypeExpr(f *ast.File, pkg *types.Package, typ types.Type) ast.Expr { … } // StmtToInsertVarBefore returns the ast.Stmt before which we can safely insert a new variable. // Some examples: // // Basic Example: // z := 1 // y := z + x // If x is undeclared, then this function would return `y := z + x`, so that we // can insert `x := ` on the line before `y := z + x`. // // If stmt example: // if z == 1 { // } else if z == y {} // If y is undeclared, then this function would return `if z == 1 {`, because we cannot // insert a statement between an if and an else if statement. As a result, we need to find // the top of the if chain to insert `y := ` before. func StmtToInsertVarBefore(path []ast.Node) ast.Stmt { … } // baseIfStmt walks up the if/else-if chain until we get to // the top of the current if chain. func baseIfStmt(path []ast.Node, index int) ast.Stmt { … } // WalkASTWithParent walks the AST rooted at n. The semantics are // similar to ast.Inspect except it does not call f(nil). func WalkASTWithParent(n ast.Node, f func(n ast.Node, parent ast.Node) bool) { … } // MatchingIdents finds the names of all identifiers in 'node' that match any of the given types. // 'pos' represents the position at which the identifiers may be inserted. 'pos' must be within // the scope of each of identifier we select. Otherwise, we will insert a variable at 'pos' that // is unrecognized. func MatchingIdents(typs []types.Type, node ast.Node, pos token.Pos, info *types.Info, pkg *types.Package) map[types.Type][]string { … } func equivalentTypes(want, got types.Type) bool { … } // MakeReadFile returns a simple implementation of the Pass.ReadFile function. func MakeReadFile(pass *analysis.Pass) func(filename string) ([]byte, error) { … } // CheckReadable enforces the access policy defined by the ReadFile field of [analysis.Pass]. func CheckReadable(pass *analysis.Pass, filename string) error { … } // TODO(adonovan): use go1.21 slices.Contains. func slicesContains[S ~[]E, E comparable](slice S, x E) bool { … } // AddImport checks whether this file already imports pkgpath and // that import is in scope at pos. If so, it returns the name under // which it was imported and a zero edit. Otherwise, it adds a new // import of pkgpath, using a name derived from the preferred name, // and returns the chosen name along with the edit for the new import. // // It does not mutate its arguments. func AddImport(info *types.Info, file *ast.File, pos token.Pos, pkgpath, preferredName string) (name string, newImport []analysis.TextEdit) { … } // importedPkgName returns the PkgName object declared by an ImportSpec. // TODO(adonovan): use go1.22's Info.PkgNameOf. func importedPkgName(info *types.Info, imp *ast.ImportSpec) (*types.PkgName, bool) { … }