go: github.com/shurcooL/go/analysis Index | Examples | Files

package analysis

import "github.com/shurcooL/go/analysis"

Package analysis provides a routine that determines if a file is generated or handcrafted.

Deprecated: Use github.com/shurcooL/go/generated package instead. This implementation was done ad-hoc before a standard was proposed.

Index

Examples

Package Files

generated_detection.go

func IsFileGenerated Uses

func IsFileGenerated(rootDir, name string) (bool, error)

IsFileGenerated returns true if the specified file is generated, or false if it's handcrafted. rootDir is the filepath of root directory, but name is a '/'-separated path to file.

It considers vendored files as "generated", in the sense that they are not the canonical version of a file. This behavior would ideally be factored out into a higher level utility, since it has nothing to do with generated comments.

Deprecated: Use generated.ParseFile instead, which is more well defined because it implements a specification.

Code:

cwd, err := os.Getwd()
if err != nil {
    panic(err)
}

fmt.Println(analysis.IsFileGenerated(cwd, "testdata/generated_0.go.txt"))
fmt.Println(analysis.IsFileGenerated(cwd, "testdata/handcrafted_0.go.txt"))
fmt.Println(analysis.IsFileGenerated(cwd, "testdata/handcrafted_1.go.txt"))
fmt.Println(analysis.IsFileGenerated(cwd, "vendor/github.com/shurcooL/go/analysis/file.go"))
fmt.Println(analysis.IsFileGenerated(cwd, "subpkg/vendor/math/math.go"))

Output:

true <nil>
false <nil>
false <nil>
true <nil>
true <nil>

Package analysis imports 5 packages (graph) and is imported by 2 packages. Updated 2017-03-21. Refresh now. Tools for package owners.