Will try to explain with an example --

// expectedComment
type StructNameA struct {
   NameA string
   AgeA  int
}

// some diff comment
type StructNameB struct {
   NameB string
   AgeB  int
}



Now I want the name of StructNameA struct along with its fields because it 
contains expectedComment at the top.
To check if the comment is expectedComment, I will need that too.
So basically I will need the list of triplet {comment, typeSpec, 
structType}.



On Saturday, June 20, 2020 at 9:17:25 PM UTC+5:30, Amarjeet Anand wrote:
>
> Hi
> How can I find the list of fields of all structs with some particular 
> comment using *ast*(*or maybe other tool available in the lang*)?
>
> Using *ast.Inspect(),* we get different callbacks for diff ast nodes, 
> like:-
>
>    - *ast.Comment :- gives comment
>    - *ast.TypeSpec: gives the name of the struct
>    - *ast.StructType: gives the list of fields of a struct
>    
>
> But my problem is --
>
>    - When type is **ast.Comment*,     I have comments, but I don't have 
>    access to struct name and its fields
>    - When type is **ast.TypeSpec*,     I have struct name but I don't 
>    haves access to it's comments.
>    - When type is **ast.StructType*,   I have access to its fields, but I 
>    don't have access to comment & struct name.
>
>
> My question is how can I merge all these three callbacks to ensure this is 
> the same comments and fields belonging to the same struct?
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/1beb4c7a-918a-42d7-adff-13d4b09597efo%40googlegroups.com.

Reply via email to