Java Javascript Mozilla Library trace(Object object)

Here you can find the source of trace(Object object)

Description

trace

License

Apache License

Declaration

public static void trace(Object object) 

Method Source Code


//package com.java2s;
//  Licensed under the Apache License, Version 2.0 (the "License");

import org.mozilla.javascript.NativeArray;
import org.mozilla.javascript.NativeObject;

public class Main {
    public static void trace(Object object) {
        trace(object, "");
    }//from  w  w w .  ja  v a 2s .  c  om

    private static void trace(Object object, String spacing) {
        if (object instanceof NativeArray) {
            NativeArray arr = (NativeArray) object;
            for (Object o : arr) {
                trace(o, spacing + "  ");
            }
            return;
        }

        if (object instanceof NativeObject) {
            NativeObject nativeObj = (NativeObject) object;
            System.out.println(spacing + "Class: " + nativeObj.getClassName());
            for (Object key : nativeObj.keySet()) {
                System.out.println(spacing + "[Key: " + key + "]");
                trace(nativeObj.get(key), spacing + "  ");
            }
            return;
        }

        if (isJavaPrimitive(object)) {
            System.out.println(spacing + object);
        } else {
            // System.out.println(spacing + ToStringBuilder.reflectionToString(object));
        }
    }

    private static boolean isJavaPrimitive(Object object) {
        return object instanceof String || object instanceof Integer || object instanceof Float
                || object instanceof Double || object instanceof Boolean || object instanceof Long
                || object instanceof Byte || object instanceof Character;
    }
}

Related

  1. toJavaBoolean(final Scriptable options, final String key)
  2. toJavaInt(final Object fromScript)
  3. toList(AstNode... nodes)
  4. toRegExp(String source, String optionsString)
  5. toString(Object val)
  6. traceHelper(Function function, Object... args)
  7. unwrap(Object obj)
  8. unwrapNativeArray(final NativeArray na)
  9. wrapJavaObj(Object javaObj, Scriptable scope)