<commit_before>package org.broadinstitute.compositetask;

import java.util.ArrayList;
import java.util.List;

public class WdlSourceCodeFormatter {
  private CompositeTaskColorizer colorizer;

  WdlSourceCodeFormatter(CompositeTaskColorizer colorizer) {
    this.colorizer = colorizer;
  }

  WdlSourceCodeFormatter() {
    this(new NullColorizer());
  }

  public String format(CompositeTask ctask) {
    return format(ctask, 0);
  }

  private String format(CompositeTaskNode node, int indent) {
    StringBuilder builder = new StringBuilder();
    String indent_str = Utility.getIndentString(indent);
    if ( node instanceof CompositeTask ) {
      CompositeTask ctask = (CompositeTask) node;
      builder.append(indent_str + this.colorizer.keyword("composite_task") + " " + ctask.getName() + " {\n");
      for ( CompositeTaskNode sub_node : ctask.getNodes() ) {
        builder.append( indent_str );
        builder.append( format(sub_node, indent + 2) );
      }
      builder.append(indent_str + "}\n");
    } else if ( node instanceof CompositeTaskForLoop ) {
      CompositeTaskForLoop loop = (CompositeTaskForLoop) node;
      builder.append( indent_str + this.colorizer.keyword("for") + " ( " + this.colorizer.variable(variable_to_string(loop.getVariable())) + " : " + this.colorizer.variable(variable_to_string(loop.getCollection())) + " ) {\n" );
      for ( CompositeTaskNode sub_node : loop.getNodes() ) {
        builder.append( indent_str );
        builder.append( format(sub_node, indent + 2) );
      }
      builder.append( indent_str + "}\n" );
    } else if ( node instanceof CompositeTaskStep ) {
      CompositeTaskStep step = (CompositeTaskStep) node;
      CompositeTaskSubTask task = step.getTask();
      String rename = "";
      if ( !step.getName().equals(task.getTaskName()) ) {
        rename = " " + this.colorizer.keyword("as") + " " + step.getName();
      }
      builder.append( "  " + this.colorizer.keyword("step") + " " + this.colorizer.task(task.getTaskName()) + "[version=" + task.getVersion() + "]" + rename + " {\n" );

      if ( step.getInputs().size() > 0 ) {
        List<String> parameters = new ArrayList<String>();
        for ( CompositeTaskStepInput input : step.getInputs() ) {
          parameters.add(input.getParameter() + "=" + this.colorizer.variable(variable_to_string(input.getVariable())));
        }

        builder.append(indent_str  + "  " + this.colorizer.keyword("input") + ": " + Utility.join(parameters, ", ") + ";\n");
      }

      if ( step.getOutputs().size() > 0 ) {<commit_msg>trivial bug fix<commit_after>package org.broadinstitute.compositetask;

import java.util.ArrayList;
import java.util.List;

public class WdlSourceCodeFormatter {
  private CompositeTaskColorizer colorizer;

  WdlSourceCodeFormatter(CompositeTaskColorizer colorizer) {
    this.colorizer = colorizer;
  }

  WdlSourceCodeFormatter() {
    this(new NullColorizer());
  }

  public String format(CompositeTask ctask) {
    return format(ctask, 0);
  }

  private String format(CompositeTaskNode node, int indent) {
    StringBuilder builder = new StringBuilder();
    String indent_str = Utility.getIndentString(indent);
    if ( node instanceof CompositeTask ) {
      CompositeTask ctask = (CompositeTask) node;
      builder.append(indent_str + this.colorizer.keyword("composite_task") + " " + ctask.getName() + " {\n");
      for ( CompositeTaskNode sub_node : ctask.getNodes() ) {
        builder.append( indent_str );
        builder.append( format(sub_node, indent + 2) );
      }
      builder.append(indent_str + "}\n");
    } else if ( node instanceof CompositeTaskForLoop ) {
      CompositeTaskForLoop loop = (CompositeTaskForLoop) node;
      builder.append( indent_str + this.colorizer.keyword("for") + " ( " + this.colorizer.variable(variable_to_string(loop.getVariable())) + " in " + this.colorizer.variable(variable_to_string(loop.getCollection())) + " ) {\n" );
      for ( CompositeTaskNode sub_node : loop.getNodes() ) {
        builder.append( indent_str );
        builder.append( format(sub_node, indent + 2) );
      }
      builder.append( indent_str + "}\n" );
    } else if ( node instanceof CompositeTaskStep ) {
      CompositeTaskStep step = (CompositeTaskStep) node;
      CompositeTaskSubTask task = step.getTask();
      String rename = "";
      if ( !step.getName().equals(task.getTaskName()) ) {
        rename = " " + this.colorizer.keyword("as") + " " + step.getName();
      }
      builder.append( "  " + this.colorizer.keyword("step") + " " + this.colorizer.task(task.getTaskName()) + "[version=" + task.getVersion() + "]" + rename + " {\n" );

      if ( step.getInputs().size() > 0 ) {
        List<String> parameters = new ArrayList<String>();
        for ( CompositeTaskStepInput input : step.getInputs() ) {
          parameters.add(input.getParameter() + "=" + this.colorizer.variable(variable_to_string(input.getVariable())));
        }

        builder.append(indent_str  + "  " + this.colorizer.keyword("input") + ": " + Utility.join(parameters, ", ") + ";\n");
      }

      if ( step.getOutputs().size() > 0 ) {
{'fraction_non_alphanumeric': 0.14553623754639577, 'fraction_numerical': 0.0019535065442469234, 'mean_word_length': 3.402407566638005, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7150339', 'n_tokens_mistral': 1572, 'n_tokens_neox': 1542, 'n_words': 277}