@@ -795,24 +795,51 @@ private void visitAliasDeclaration(AstNode aliasDeclNode) {
795795 }
796796 }
797797
798- private void visitEnumSpecifier (AstNode enumSpecifierNode ) {
799- var enumIdNode = enumSpecifierNode .getFirstDescendant (GenericTokenType .IDENTIFIER );
798+ private static List <Token > getTypedefInlineComment (AstNode typedef ) {
799+ var commentTokens = new ArrayList <Token >();
800+ var node = typedef .getFirstAncestor (CxxGrammarImpl .declaration );
801+ node = node .getNextAstNode ();
802+
803+ // search for first child with a comment
804+ while (node != null ) {
805+ for (var trivia : node .getToken ().getTrivia ()) {
806+ if (trivia .isComment ()) {
807+ commentTokens .add (trivia .getToken ());
808+ return commentTokens ;
809+ }
810+ }
811+ node = node .getFirstChild ();
812+ }
800813
801- String enumId = (enumIdNode == null ) ? UNNAMED_ENUM_ID : enumIdNode .getTokenValue ();
814+ return commentTokens ;
815+ }
802816
817+ private void visitEnumSpecifier (AstNode enumSpecifierNode ) {
803818 if (!isPublicApiMember (enumSpecifierNode )) {
804- // not in public API
805- return ;
819+ return ; // not in public API
806820 }
807821
808- // deal with typedef enum: documentation is on typedef node
809- AstNode docNode = getTypedefNode ( enumSpecifierNode ) ;
822+ var docNode = getTypedefNode ( enumSpecifierNode );
823+ AstNode idNode ;
810824 if (docNode == null ) {
811- docNode = enumSpecifierNode ;
825+ // enum ...
826+ idNode = enumSpecifierNode .getFirstDescendant (CxxGrammarImpl .enumHeadName );
827+ if (idNode != null ) {
828+ visitPublicApi (enumSpecifierNode , idNode .getTokenValue (), getBlockDocumentation (enumSpecifierNode ));
829+ }
830+ } else {
831+ // typedef enum ...
832+ var declaration = enumSpecifierNode .getFirstAncestor (CxxGrammarImpl .declaration );
833+ idNode = declaration .getFirstDescendant (CxxGrammarImpl .declaratorId );
834+ if (idNode != null ) {
835+ List <Token > comments = getBlockDocumentation (docNode );
836+ if (comments .isEmpty ()) { // documentation may be inlined
837+ comments = getTypedefInlineComment (docNode );
838+ }
839+ visitPublicApi (enumSpecifierNode , idNode .getTokenValue (), comments );
840+ }
812841 }
813842
814- visitPublicApi (enumSpecifierNode , enumId , getBlockDocumentation (docNode ));
815-
816843 // deal with enumeration values
817844 AstNode enumeratorList = enumSpecifierNode .getFirstDescendant (CxxGrammarImpl .enumeratorList );
818845
0 commit comments