From fb40658f9dbbc9ab0c7fd673f81c744fe2bfd10c Mon Sep 17 00:00:00 2001 From: Solly Ross Date: Fri, 12 May 2017 17:38:46 -0400 Subject: [PATCH] [go-to-protobuf] Skip private types and functions Since go-to-protobuf doesn't care about functions or private types (only public types), we can skip them. This helps to clean up the generated IDL: previously, the IDL contained erroneous imports due to matching functions and private types which were not actually converted to protobuf, but which were the same as functions and private types in other packages. --- .../go2idl/go-to-protobuf/protobuf/namer.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/cmd/libs/go2idl/go-to-protobuf/protobuf/namer.go b/cmd/libs/go2idl/go-to-protobuf/protobuf/namer.go index 60060d4edf4..423577a12e9 100644 --- a/cmd/libs/go2idl/go-to-protobuf/protobuf/namer.go +++ b/cmd/libs/go2idl/go-to-protobuf/protobuf/namer.go @@ -157,6 +157,21 @@ func assignGoTypeToProtoPackage(p *protobufPackage, t *types.Type, local, global } } +// isTypeApplicableToProtobuf checks to see if a type is relevant for protobuf processing. +// Currently, it filters out functions and private types. +func isTypeApplicableToProtobuf(t *types.Type) bool { + // skip functions -- we don't care about them for protobuf + if t.Kind == types.Func || (t.Kind == types.DeclarationOf && t.Underlying.Kind == types.Func) { + return false + } + // skip private types + if namer.IsPrivateGoName(t.Name.Name) { + return false + } + + return true +} + func (n *protobufNamer) AssignTypesToPackages(c *generator.Context) error { global := make(typeNameSet) for _, p := range n.packages { @@ -167,6 +182,10 @@ func (n *protobufNamer) AssignTypesToPackages(c *generator.Context) error { if t.Name.Package != p.PackagePath { continue } + if !isTypeApplicableToProtobuf(t) { + // skip types that we don't care about, like functions + continue + } assignGoTypeToProtoPackage(p, t, local, global, optional) } p.FilterTypes = make(map[types.Name]struct{})