@@ -56,7 +56,7 @@ ScannedConfigDocsItemHolder findInMemoryConfigurationItems() {
5656             */ 
5757            final  int  sectionLevel  = 2 ;
5858            final  List <ConfigDocItem > configDocItems  = recursivelyFindConfigItems (element , configRootInfo .getName (),
59-                     configRootInfo .getConfigPhase (), false , sectionLevel );
59+                     configRootInfo .getConfigPhase (), false , sectionLevel ,  false );
6060            holder .addConfigRootItems (configRootInfo .getClazz ().getQualifiedName ().toString (), configDocItems );
6161        }
6262
@@ -71,9 +71,10 @@ ScannedConfigDocsItemHolder findInMemoryConfigurationItems() {
7171     * @param configPhase - configuration phase see {@link ConfigPhase} 
7272     * @param withinAMap - indicates if a a key is within a map or is a map configuration key 
7373     * @param sectionLevel - section sectionLevel 
74+      * @param optional - whether a group of config items is optional or not 
7475     */ 
7576    private  List <ConfigDocItem > recursivelyFindConfigItems (Element  element , String  parentName ,
76-             ConfigPhase  configPhase , boolean  withinAMap , int  sectionLevel ) {
77+             ConfigPhase  configPhase , boolean  withinAMap , int  sectionLevel ,  boolean   optional ) {
7778        List <ConfigDocItem > configDocItems  = new  ArrayList <>();
7879        for  (Element  enclosedElement  : element .getEnclosedElements ()) {
7980            if  (!enclosedElement .getKind ().isField ()) {
@@ -162,19 +163,19 @@ private List<ConfigDocItem> recursivelyFindConfigItems(Element element, String p
162163
163164            if  (isConfigGroup ) {
164165                List <ConfigDocItem > groupConfigItems  = recordConfigItemsFromConfigGroup (configPhase , name , configGroup ,
165-                         configSection , withinAMap , sectionLevel );
166+                         configSection , withinAMap , sectionLevel ,  optional );
166167                configDocItems .addAll (groupConfigItems );
167168            } else  {
168169                final  ConfigDocKey  configDocKey  = new  ConfigDocKey ();
169170                configDocKey .setWithinAMap (withinAMap );
170-                 boolean  optional  = false ;
171171                boolean  list  = false ;
172172                if  (!typeMirror .getKind ().isPrimitive ()) {
173173                    DeclaredType  declaredType  = (DeclaredType ) typeMirror ;
174174                    TypeElement  typeElement  = (TypeElement ) declaredType .asElement ();
175175                    Name  qualifiedName  = typeElement .getQualifiedName ();
176-                     optional  = qualifiedName .toString ().startsWith (Optional .class .getName ());
177-                     list  = qualifiedName .contentEquals (List .class .getName ());
176+                     optional  |= qualifiedName .toString ().startsWith (Optional .class .getName ());
177+                     list  = qualifiedName .contentEquals (List .class .getName ())
178+                             || qualifiedName .contentEquals (Set .class .getName ());
178179
179180                    List <? extends  TypeMirror > typeArguments  = declaredType .getTypeArguments ();
180181                    if  (!typeArguments .isEmpty ()) {
@@ -187,7 +188,7 @@ private List<ConfigDocItem> recursivelyFindConfigItems(Element element, String p
187188                                name  += String .format (NAMED_MAP_CONFIG_ITEM_FORMAT , configDocMapKey );
188189                                List <ConfigDocItem > groupConfigItems  = recordConfigItemsFromConfigGroup (configPhase , name ,
189190                                        configGroup ,
190-                                         configSection , true , sectionLevel );
191+                                         configSection , true , sectionLevel ,  optional );
191192                                configDocItems .addAll (groupConfigItems );
192193                                continue ;
193194                            } else  {
@@ -198,13 +199,23 @@ private List<ConfigDocItem> recursivelyFindConfigItems(Element element, String p
198199                        } else  {
199200                            // FIXME: this is for Optional<T> and List<T> 
200201                            TypeMirror  realTypeMirror  = typeArguments .get (0 );
201-                             if  (optional  && (realTypeMirror .toString ().startsWith (List .class .getName ())
202-                                     || realTypeMirror .getKind () == TypeKind .ARRAY )) {
203-                                 list  = true ;
204-                                 DeclaredType  declaredRealType  = (DeclaredType ) typeMirror ;
205-                                 typeArguments  = declaredRealType .getTypeArguments ();
206-                                 if  (!typeArguments .isEmpty ()) {
207-                                     realTypeMirror  = typeArguments .get (0 );
202+                             String  typeInString  = realTypeMirror .toString ();
203+ 
204+                             if  (optional ) {
205+                                 configGroup  = configGroups .get (typeInString );
206+                                 if  (configGroup  != null ) {
207+                                     List <ConfigDocItem > groupConfigItems  = recordConfigItemsFromConfigGroup (configPhase , name ,
208+                                             configGroup , configSection , withinAMap , sectionLevel , true );
209+                                     configDocItems .addAll (groupConfigItems );
210+                                 } else  if  ((typeInString .startsWith (List .class .getName ())
211+                                         || typeInString .startsWith (Set .class .getName ())
212+                                         || realTypeMirror .getKind () == TypeKind .ARRAY )) {
213+                                     list  = true ;
214+                                     DeclaredType  declaredRealType  = (DeclaredType ) typeMirror ;
215+                                     typeArguments  = declaredRealType .getTypeArguments ();
216+                                     if  (!typeArguments .isEmpty ()) {
217+                                         realTypeMirror  = typeArguments .get (0 );
218+                                     }
208219                                }
209220                            }
210221
@@ -244,10 +255,10 @@ private List<ConfigDocItem> recursivelyFindConfigItems(Element element, String p
244255    }
245256
246257    private  List <ConfigDocItem > recordConfigItemsFromConfigGroup (ConfigPhase  configPhase , String  name , Element  configGroup ,
247-             ConfigDocSection  configSection , boolean  withinAMap , int  sectionLevel ) {
258+             ConfigDocSection  configSection , boolean  withinAMap , int  sectionLevel ,  boolean   optional ) {
248259        final  List <ConfigDocItem > configDocItems  = new  ArrayList <>();
249260        final  List <ConfigDocItem > groupConfigItems  = recursivelyFindConfigItems (configGroup , name , configPhase , withinAMap ,
250-                 sectionLevel  + 1 );
261+                 sectionLevel  + 1 ,  optional );
251262        if  (configSection  == null ) {
252263            configDocItems .addAll (groupConfigItems );
253264        } else  {
0 commit comments