From 3309b0d8799c3150ace916786bc031462dae3a99 Mon Sep 17 00:00:00 2001 From: Gordon Klaus Date: Mon, 23 Jun 2014 15:13:07 -0700 Subject: [PATCH] go.tools/go/loader: Add Program.FilePath convenience method for getting the full path of a source file. LGTM=gri R=gri, adonovan CC=golang-codereviews https://golang.org/cl/107160049 --- go/loader/loader.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/go/loader/loader.go b/go/loader/loader.go index 2a15359a..37181f26 100644 --- a/go/loader/loader.go +++ b/go/loader/loader.go @@ -460,6 +460,16 @@ func (prog *Program) InitialPackages() []*PackageInfo { return infos } +// FilePath returns the full path to the specified file. It returns the empty +// string if the file does not belong to one of this Program's packages. +// +func (prog *Program) FilePath(file *ast.File) string { + if f := prog.Fset.File(file.Package); f != nil { + return f.Name() + } + return "" +} + // ---------- Implementation ---------- // importer holds the working state of the algorithm.