private SoyValue applyDirective(
      SoyPrintDirective directive, SoyValue value, List<SoyValue> args, SoyNode node) {

    // Get directive.
    if (!(directive instanceof SoyJavaPrintDirective)) {
      throw RenderException.createWithSource(
          "Failed to find Soy print directive with name '"
              + directive
              + "'"
              + " (tag "
              + node.toSourceString()
              + ")",
          node);
    }

    // TODO: Add a pass to check num args at compile time.
    if (!directive.getValidArgsSizes().contains(args.size())) {
      throw RenderException.createWithSource(
          "Print directive '"
              + directive
              + "' used with the wrong number of arguments (tag "
              + node.toSourceString()
              + ").",
          node);
    }

    try {
      return ((SoyJavaPrintDirective) directive).applyForJava(value, args);
    } catch (RuntimeException e) {
      throw RenderException.createWithSource(
          String.format(
              "Failed in applying directive '%s' in tag \"%s\" due to exception: %s",
              directive, node.toSourceString(), e.getMessage()),
          e,
          node);
    }
  }
private SoyValue applyDirective ( SoyPrintDirective directive , SoyValue value , List < SoyValue > args , SoyNode node ) { if ( ! ( directive instanceof SoyJavaPrintDirective ) ) { throw RenderException . createWithSource ( "Failed to find Soy print directive with name '" + directive + "'" + " (tag " + node . toSourceString ( ) + ")" , node ) ; } if ( ! directive . getValidArgsSizes ( ) . contains ( args . size ( ) ) ) { throw RenderException . createWithSource ( "Print directive '" + directive + "' used with the wrong number of arguments (tag " + node . toSourceString ( ) + ")." , node ) ; } try { return ( ( SoyJavaPrintDirective ) directive ) . applyForJava ( value , args ) ; } catch ( RuntimeException e ) { throw RenderException . createWithSource ( String . format ( "Failed in applying directive '%s' in tag \"%s\" due to exception: %s" , directive , node . toSourceString ( ) , e . getMessage ( ) ) , e , node ) ; } }
Protected helper to apply a print directive.

@param directive The directive to apply
@param value The value to apply the directive on.
@param args The arguments to the directive.
@param node The node with the escaping. Only used for error reporting.
@return The result of applying the directive with the given arguments to the given value.