emicklei / proto

parser for Google ProtocolBuffers definition

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Boolean variable to test if a field is deprecated

oussemabhouri opened this issue · comments

I have the following:

enum Group {
    UNDEFINED_GROUP_TOPIC = 0;
    Field_1 = 1;
    Field2 = 2;
    Field3 = 8 [ deprecated = true ]; 
}

and a function that visits all the fields in Group

func (p *ProtoParser) VisitEnumField(i *proto.EnumField) {
	if strings.Contains(i.Name, "deprecated") {
		// Skip this field
		return
	}
	p.events = append(p.events, i.Name)
}

But this one does not work.
Basically I want p.events to skip the append of deprecated fields

any luck finding a solution? @emicklei

would this work for you ? #136

definitely, thank you very much

@emicklei Is this also applicable for an EnumField??? would be also better if we have it

So for normal Field we were iterating over options and overriding Constant.Source if the of the name of the option is deprecated..
But how can we do that for []Visitee when it is an interface that has only two methods

 `	Accept(v Visitor)
	parent(e Visitee)`

@emicklei Is this also applicable for an EnumField??? would be also better if we have it

So for normal Field we were iterating over options and overriding Constant.Source if the of the name of the option is deprecated.. But how can we do that for []Visitee when it is an interface that has only two methods

 `	Accept(v Visitor)
	parent(e Visitee)`

When visiting an Enum, the visitor is called with VisitEnum.
Each Enum has Elements you can visit.
When visiting an EnumField (as one of the Elements), the visitor is called with VisitEnumField.
With the latest version, you can call the IsDeprecated on the EnumField.

In general, when visiting Elements you can also try type assertion to reveal the actual type of the Element.

I hope this helps.

So how would this approach be applied on:

func (p *ProtoParser) VisitEnum(enum *proto.Enum) {
	if enum.Name == "GroupTopics" {
		for _, e := range enum.Elements[1:] {
			e.Accept(p)
		}
	}
}