<commit_before>/*
 * Copyright 2011, The gwtquery team.
 *
 * 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.query.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.query.client.js.JsUtils;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.Widget;

/**
 * Extend this class to implement functions callbacks.
 */
public abstract class Function {

  private com.google.gwt.dom.client.Element element = null;
  private Event event = null;
  private int index = -1;
  protected Object[] arguments = new Object[0];
  
  /**
   * Utility method to get a string representation with the content
   * of the arguments array. It recursively visits arrays and inspect
   * object to print an appropriate representation of them.
   * 
   * It is very useful to debug arguments passed in nested promises. 
   * 
   * It is protected so as it can be used in Inner functions.
   * 
   * Output example:
   * <pre>
   * [0](com.google.gwt.query.client.plugins.QueuePlugin) <div>a1</div><div>a2</div>
   * [1](com.google.gwt.query.client.plugins.QueuePlugin) <div>a1</div><div>a2</div>
   * [2](java.lang.String) Foo
   * [3](JSO) {"bar":"foo"}
   * </pre>
   */
  protected String dumpArguments() {
    return dumpArguments(arguments, "\n");
  }
  
  private String dumpArguments(Object[] arguments, String sep) {
    String ret = "";
    for (int i = 0, l = arguments.length; i < l; i++ ) {
      ret += "[" + i + "]";
      Object o = arguments[i];
      if (o == null) {
        ret += " null";
      } else if (o.getClass().isArray()) {
        ret += dumpArguments((Object[])o, sep + "   ");
      } else if (o instanceof JavaScriptObject) {
        JavaScriptObject jso = (JavaScriptObject)o;
        if (JsUtils.isElement(jso)) {
          ret += "(Element) " + jso.toString();
        } else {
          ret += "(JSO) " + jso.<Properties>cast().toJsonString();
        }
      } else {
        ret += "(" + o.getClass().getName() + ") " + o;
      }
      if (i < l-1) ret += sep;
    }
    return ret;
  }<commit_msg>cosmetic and formal change of string sum by string builder. I believe it does not improves anything in compiled mode though.<commit_after>/*
 * Copyright 2011, The gwtquery team.
 *
 * 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.query.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.query.client.js.JsUtils;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.Widget;

/**
 * Extend this class to implement functions callbacks.
 */
public abstract class Function {

  private com.google.gwt.dom.client.Element element = null;
  private Event event = null;
  private int index = -1;
  protected Object[] arguments = new Object[0];
  
  /**
   * Utility method to get a string representation with the content
   * of the arguments array. It recursively visits arrays and inspect
   * object to print an appropriate representation of them.
   * 
   * It is very useful to debug arguments passed in nested promises. 
   * 
   * It is protected so as it can be used in Inner functions.
   * 
   * Output example:
   * <pre>
   * [0](com.google.gwt.query.client.plugins.QueuePlugin) <div>a1</div><div>a2</div>
   * [1](com.google.gwt.query.client.plugins.QueuePlugin) <div>a1</div><div>a2</div>
   * [2](java.lang.String) Foo
   * [3](JSO) {"bar":"foo"}
   * </pre>
   */
  protected String dumpArguments() {
    return dumpArguments(arguments, "\n");
  }
  
  private String dumpArguments(Object[] arguments, String sep) {
    StringBuilder b = new StringBuilder();
    for (int i = 0, l = arguments.length; i < l; i++ ) {
      b.append("[").append(i).append("]");
      Object o = arguments[i];
      if (o == null) {
        b.append(" null");
      } else if (o.getClass().isArray()) {
        b.append(dumpArguments((Object[])o, sep + "   "));
      } else if (o instanceof JavaScriptObject) {
        JavaScriptObject jso = (JavaScriptObject)o;
        if (JsUtils.isElement(jso)) {
          b.append("(Element) ").append(jso.toString());
        } else {
          b.append("(JSO) ").append(jso.<Properties>cast().toJsonString());
        }
      } else {
        b.append("(").append(o.getClass().getName()).append(") ").append(o);
      }
      if (i < l-1) b.append(sep);
    }
    return b.toString();
  }
{'fraction_non_alphanumeric': 0.13318737456668492, 'fraction_numerical': 0.007297938332421091, 'mean_word_length': 3.016117216117216, 'pattern_counts': {'":': 2, '<': 29, '<?xml version=': 0, '>': 25, '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': '6036457', 'n_tokens_mistral': 1672, 'n_tokens_neox': 1644, 'n_words': 524}