private String generateOptionalSafeTagsArg ( List < ? extends TargetExpr > args ) { String optionalSafeTagsArg = "" ; if ( ! args . isEmpty ( ) ) { // TODO(msamuel): Instead of parsing generated JS, we should have a CheckArgumentsPass that // allows directives and functions to examine their input expressions prior to compilation and // relay the input file and line number to the template author along with an error message. Iterable < String > optionalSafeTagExprs = Iterables . transform ( args , TargetExpr :: getText ) ; // Verify that all exprs are single-quoted valid OptionalSafeTags. for ( String singleQuoted : optionalSafeTagExprs ) { if ( singleQuoted . length ( ) < 2 || singleQuoted . charAt ( 0 ) != ' ' || singleQuoted . charAt ( singleQuoted . length ( ) - 1 ) != ' ' ) { throw new IllegalArgumentException ( String . format ( "The cleanHtml directive expects arguments to be tag name string " + "literals, such as 'span'. Encountered: %s" , singleQuoted ) ) ; } String tagName = singleQuoted . substring ( 1 , singleQuoted . length ( ) - 1 ) ; OptionalSafeTag . fromTagName ( tagName ) ; // throws if invalid } optionalSafeTagsArg = ", [" + ARG_JOINER . join ( optionalSafeTagExprs ) + "]" ; } return optionalSafeTagsArg ; }
Converts a list of TargetExpr s into a list of safe tags as an argument for the supported backends . This will iterate over the expressions ensure they re valid safe tags and convert them into an array of Strings .