question: private void parseMenu ( XmlPullParser parser , AttributeSet attrs , SublimeMenu menu ) throws XmlPullParserException , IOException { MenuState menuState = new MenuState ( menu ) ; int eventType = parser . getEventType ( ) ; String tagName ; boolean lookingForEndOfUnknownTag = false ; String unknownTagName = null ; do { if ( eventType == XmlPullParser . START_TAG ) { tagName = parser . getName ( ) ; if ( tagName . equals ( XML_MENU ) ) { eventType = parser . next ( ) ; break ; } throw new RuntimeException ( "Expecting menu, got " + tagName ) ; } eventType = parser . next ( ) ; } while ( eventType != XmlPullParser . END_DOCUMENT ) ; boolean reachedEndOfMenu = false ; while ( ! reachedEndOfMenu ) { switch ( eventType ) { case XmlPullParser . START_TAG : if ( lookingForEndOfUnknownTag ) { break ; } tagName = parser . getName ( ) ; if ( tagName . equals ( XML_GROUP ) ) { if ( menuState . groupId != MenuState . defaultGroupId ) { throw new RuntimeException ( "A 'Group' item cannot have " + "other 'Group' items as children." ) ; } menuState . readGroup ( attrs ) ; menuState . addGroup ( ) ; } else if ( tagName . equals ( XML_TEXT ) || tagName . equals ( XML_TEXT_WITH_BADGE ) || tagName . equals ( XML_CHECKBOX ) || tagName . equals ( XML_SWITCH ) ) { menuState . readMenuItem ( attrs , tagName ) ; } else if ( tagName . equals ( XML_SEPARATOR ) ) { menuState . readMenuItem ( attrs , tagName ) ; } else if ( tagName . equals ( XML_GROUP_HEADER ) ) { if ( menuState . groupId == MenuState . defaultGroupId ) { throw new RuntimeException ( "'GroupHeader' item should " + "be placed inside a Group element." ) ; } menuState . readMenuItem ( attrs , tagName ) ; } else if ( tagName . equals ( XML_MENU ) ) { throw new RuntimeException ( "Sub-menus are not supported. " + "Similar functionality can be afforded " + "using the 'group' tag." ) ; } else { lookingForEndOfUnknownTag = true ; unknownTagName = tagName ; } break ; case XmlPullParser . END_TAG : tagName = parser . getName ( ) ; if ( lookingForEndOfUnknownTag && tagName . equals ( unknownTagName ) ) { lookingForEndOfUnknownTag = false ; unknownTagName = null ; } else if ( tagName . equals ( XML_GROUP ) ) { if ( menuState . isGroupCollapsible ( ) && menuState . groupHeadersAdded != 1 ) { if ( menuState . groupHeadersAdded < 1 ) { throw new RuntimeException ( "A 'GroupHeader' is required " + "to create a 'collapsible' Group." ) ; } else { throw new RuntimeException ( "A 'collapsible' Group can only " + "have ONE 'GroupHeader'. You have provided: " + menuState . groupHeadersAdded + "." ) ; } } menuState . resetGroup ( ) ; } else if ( tagName . equals ( XML_TEXT ) || tagName . equals ( XML_TEXT_WITH_BADGE ) || tagName . equals ( XML_CHECKBOX ) || tagName . equals ( XML_SWITCH ) || tagName . equals ( XML_GROUP_HEADER ) || tagName . equals ( XML_SEPARATOR ) ) { if ( ! menuState . hasAddedItem ( ) ) { menuState . addItem ( ) ; } } else if ( tagName . equals ( XML_MENU ) ) { reachedEndOfMenu = true ; } break ; case XmlPullParser . END_DOCUMENT : throw new RuntimeException ( "Unexpected end of document" ) ; } eventType = parser . next ( ) ; } }
target:  Called internally to fill the given menu.