@ VisibleForTesting static Context parse ( String text ) { Queue < String > parts = Lists . newLinkedList ( Arrays . asList ( text . split ( " " ) ) ) ; Context . Builder builder = HTML_PCDATA . toBuilder ( ) ; builder . withState ( HtmlContext . valueOf ( parts . remove ( ) ) ) ; if ( ! parts . isEmpty ( ) ) { try { builder . withElType ( ElementType . valueOf ( parts . element ( ) ) ) ; parts . remove ( ) ; } catch ( IllegalArgumentException ex ) { // OK } } if ( ! parts . isEmpty ( ) ) { try { builder . withAttrType ( AttributeType . valueOf ( parts . element ( ) ) ) ; parts . remove ( ) ; } catch ( IllegalArgumentException ex ) { // OK } } if ( ! parts . isEmpty ( ) ) { try { builder . withDelimType ( AttributeEndDelimiter . valueOf ( parts . element ( ) ) ) ; parts . remove ( ) ; } catch ( IllegalArgumentException ex ) { // OK } } if ( ! parts . isEmpty ( ) ) { try { builder . withSlashType ( JsFollowingSlash . valueOf ( parts . element ( ) ) ) ; parts . remove ( ) ; } catch ( IllegalArgumentException ex ) { // OK } } if ( ! parts . isEmpty ( ) ) { try { builder . withUriPart ( UriPart . valueOf ( parts . element ( ) ) ) ; parts . remove ( ) ; } catch ( IllegalArgumentException ex ) { // OK } } if ( ! parts . isEmpty ( ) ) { try { builder . withUriType ( UriType . valueOf ( parts . element ( ) ) ) ; parts . remove ( ) ; } catch ( IllegalArgumentException ex ) { // OK } } if ( ! parts . isEmpty ( ) ) { String part = parts . element ( ) ; String prefix = "templateNestDepth=" ; if ( part . startsWith ( prefix ) ) { try { builder . withTemplateNestDepth ( Integer . parseInt ( part . substring ( prefix . length ( ) ) ) ) ; parts . remove ( ) ; } catch ( NumberFormatException ex ) { // OK } } } if ( ! parts . isEmpty ( ) ) { String part = parts . element ( ) ; String prefix = "jsTemplateLiteralNestDepth=" ; if ( part . startsWith ( prefix ) ) { try { builder . withJsTemplateLiteralNestDepth ( Integer . parseInt ( part . substring ( prefix . length ( ) ) ) ) ; parts . remove ( ) ; } catch ( NumberFormatException ex ) { // OK } } } if ( ! parts . isEmpty ( ) ) { throw new IllegalArgumentException ( "Unable to parse context \"" + text + "\". Unparsed portion: " + parts ) ; } Context result = builder . build ( ) ; return result ; }
Parses a condensed string version of a context for use in tests .