goastpkg

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2019 License: BSD-3-Clause Imports: 7 Imported by: 0

README

godoc

goastpkg

Package goastpkg uses golang.org/x/tools/go/packages to load full ASTs for a package and its dependencies, then generates a *go/ast.Package for the requested package (and its dependencies).

This is particularly useful when one wants all Obj references resolved in indentifiers, both within a package (between files) and across packages.

This package is new and somewhat experimental, and currently only resolves one layer of dependencies due to failures encountered when trying to resolve deep dependencies.

usage

This package is designed to have no knobs, so one can get the full AST of a package with one call.

package main

import (
    "context"

    goastpkg "golang.spin-2.net/astpkg"
)

func main() {
    pkg, err := goastpkg.Load(context.Background, "net")
    // Do something interesting with pkg.PkgAST
}

Note: the token.FileSet used for parsing is exposed as the Fset member of all packages.Package structs.

Documentation

Overview

Package goastpkg uses golang.org/x/tools/go/packages to load full ASTs for a package and its dependencies, then generates a *go/ast.Package for the requested package (and its dependencies).

This is particularly useful when one wants all Obj references resolved in indentifiers, both within a package (between files) and across packages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Package

type Package struct {
	Path   string
	PkgAST *ast.Package
	Pkg    *packages.Package
	// CommentMap per file in the package
	PkgCommentMaps map[*ast.File]ast.CommentMap

	// Deps and DepsAST are keyed by import path.
	DepsAST map[string]*ast.Package
	Deps    map[string]*packages.Package
}

Package contains the ast.Package and packages.Package pointers for a package and all its (transitive) dependencies.

func Load

func Load(ctx context.Context, pkgName string) (*Package, error)

Load reads in the requested package, populating a *Package with the AST/types information.

Directories

Path Synopsis
Package importmgr provides the ImportMgr type for tracking a go file's imports when generating code by manipulating the Go AST.
Package importmgr provides the ImportMgr type for tracking a go file's imports when generating code by manipulating the Go AST.

Jump to

Keyboard shortcuts

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