<commit_before>/*
 * Copyright 2013 GWT project.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package com.google.gwt.resources.gss;

import com.google.common.css.compiler.ast.CssNode;
import com.google.common.css.compiler.ast.CssRootNode;
import com.google.common.css.compiler.ast.CssTree;
import com.google.common.css.compiler.ast.CssValueNode;
import com.google.common.css.compiler.passes.CompactPrinter;
import com.google.gwt.core.ext.Generator;
import com.google.gwt.resources.gss.ast.CssJavaExpressionNode;

public class CssPrinter extends CompactPrinter {

  private StringBuilder masterStringBuilder;

  public CssPrinter(CssTree tree) {
    super(tree);
  }

  public CssPrinter(CssNode node) {
    super(node);
  }

  @Override
  public boolean enterTree(CssRootNode root) {
    masterStringBuilder.append("(\"");
    return super.enterTree(root);
  }

  @Override
  public String getCompactPrintedString() {
    return masterStringBuilder.toString();
  }

  @Override
  public void leaveTree(CssRootNode root) {
    String remaining = Generator.escape(sb.toString());
    masterStringBuilder.append(remaining).append("\")");
    super.leaveTree(root);
  }

  @Override
  public void runPass() {
    masterStringBuilder = new StringBuilder();
    super.runPass();
  }

  @Override
  protected void appendValueNode(CssValueNode node) {
    if (node instanceof CssJavaExpressionNode) {
      CssJavaExpressionNode javaExpressionNode = (CssJavaExpressionNode) node;
      concat("String.valueOf(" + javaExpressionNode.getValue() + ")");
    } else {
      super.appendValueNode(node);
    }
  }

  private void concat(String stringToAppend) {
    // read, escape and reset the internal StringBuilder
    String before = Generator.escape(sb.toString());
    sb = new StringBuilder();<commit_msg>use a string variable to keep the generated css<commit_after>/*
 * Copyright 2013 GWT project.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package com.google.gwt.resources.gss;

import com.google.common.css.compiler.ast.CssNode;
import com.google.common.css.compiler.ast.CssRootNode;
import com.google.common.css.compiler.ast.CssTree;
import com.google.common.css.compiler.ast.CssValueNode;
import com.google.common.css.compiler.passes.CompactPrinter;
import com.google.gwt.core.ext.Generator;
import com.google.gwt.resources.gss.ast.CssJavaExpressionNode;

public class CssPrinter extends CompactPrinter {

  private StringBuilder masterStringBuilder;
  private String css;

  public CssPrinter(CssTree tree) {
    super(tree);
  }

  public CssPrinter(CssNode node) {
    super(node);
  }

  @Override
  public boolean enterTree(CssRootNode root) {
    masterStringBuilder.append("(\"");
    return super.enterTree(root);
  }

  @Override
  public String getCompactPrintedString() {
    return css;
  }

  @Override
  public void leaveTree(CssRootNode root) {
    String remaining = Generator.escape(sb.toString());
    masterStringBuilder.append(remaining).append("\")");
    super.leaveTree(root);
  }

  @Override
  public void runPass() {
    masterStringBuilder = new StringBuilder();

    super.runPass();

    css = masterStringBuilder.toString();
  }

  @Override
  protected void appendValueNode(CssValueNode node) {
    if (node instanceof CssJavaExpressionNode) {
      CssJavaExpressionNode javaExpressionNode = (CssJavaExpressionNode) node;
      concat("String.valueOf(" + javaExpressionNode.getValue() + ")");
    } else {
      super.appendValueNode(node);
    }
  }

  private void concat(String stringToAppend) {
    // read, escape and reset the internal StringBuilder
    String before = Generator.escape(sb.toString());
    sb = new StringBuilder();
{'fraction_non_alphanumeric': 0.10061689002339928, 'fraction_numerical': 0.0034035311635822164, 'mean_word_length': 4.083243243243243, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2140092', 'n_tokens_mistral': 1373, 'n_tokens_neox': 1340, 'n_words': 374}