analysisutil

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package analysisutil contains functions common for `analyzer` and `internal/checkers` packages. In addition, it is intended to "lighten" these packages.

If the function is common to several packages, or it makes sense to test it separately without "polluting" the target package with tests of private functionality, then you can put function in this package.

It's important to avoid dependency on `golang.org/x/tools/go/analysis` in the helpers API. This makes the API "narrower" and also allows you to test functions without some "abstraction leaks".

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Imports

func Imports(file *ast.File, pkgs ...string) bool

Imports tells if the file imports at least one of the packages. If no packages provided then function returns false.

func IsObj

func IsObj(typesInfo *types.Info, expr ast.Expr, expected types.Object) bool

IsObj returns true if expression is identifier which notes to given types.Object. Useful in combination with types.Universe objects.

func IsPkg

func IsPkg(pkg *types.Package, name, path string) bool

IsPkg checks that package has corresponding objName and path. Supports vendored packages.

func NodeBytes

func NodeBytes(fset *token.FileSet, node ast.Node) []byte

NodeBytes works as NodeString but returns a byte slice. Return nil if node AST is invalid.

func NodeString

func NodeString(fset *token.FileSet, node ast.Node) string

NodeString is a more powerful analogue of types.ExprString. Return empty string if node AST is invalid.

func ObjectOf

func ObjectOf(pkg *types.Package, objPkg, objName string) types.Object

ObjectOf works in context of Golang package and returns types.Object for the given object's package and name. The search is based on the provided package and its dependencies (imports). Returns nil if the object is not found.

Types

This section is empty.

Jump to

Keyboard shortcuts

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