private void toString()

in rhino/src/main/java/org/mozilla/javascript/Node.java [1051:1202]


    private void toString(Map<Node, Integer> printIds, StringBuilder sb) {
        if (Token.printTrees) {
            sb.append(Token.name(type));
            if (this instanceof Name) {
                sb.append(' ');
                sb.append(getString());
                Scope scope = getScope();
                if (scope != null) {
                    sb.append("[scope: ");
                    appendPrintId(scope, printIds, sb);
                    sb.append("]");
                }
            } else if (this instanceof Scope) {
                if (this instanceof ScriptNode) {
                    ScriptNode sof = (ScriptNode) this;
                    if (this instanceof FunctionNode) {
                        FunctionNode fn = (FunctionNode) this;
                        sb.append(' ');
                        sb.append(fn.getName());
                    }
                    sb.append(" [source name: ");
                    sb.append(sof.getSourceName());
                    sb.append("] [raw source length: ");
                    sb.append(sof.getRawSourceEnd() - sof.getRawSourceStart());
                    sb.append("] [base line: ");
                    sb.append(sof.getBaseLineno());
                    sb.append("] [end line: ");
                    sb.append(sof.getEndLineno());
                    sb.append(']');
                }
                if (((Scope) this).getSymbolTable() != null) {
                    sb.append(" [scope ");
                    appendPrintId(this, printIds, sb);
                    sb.append(": ");
                    for (String s : ((Scope) this).getSymbolTable().keySet()) {
                        sb.append(s);
                        sb.append(" ");
                    }
                    sb.append("]");
                }
            } else if (this instanceof Jump) {
                Jump jump = (Jump) this;
                if (type == Token.BREAK || type == Token.CONTINUE) {
                    sb.append(" [label: ");
                    appendPrintId(jump.getJumpStatement(), printIds, sb);
                    sb.append(']');
                } else if (type == Token.TRY) {
                    Node catchNode = jump.target;
                    Node finallyTarget = jump.getFinally();
                    if (catchNode != null) {
                        sb.append(" [catch: ");
                        appendPrintId(catchNode, printIds, sb);
                        sb.append(']');
                    }
                    if (finallyTarget != null) {
                        sb.append(" [finally: ");
                        appendPrintId(finallyTarget, printIds, sb);
                        sb.append(']');
                    }
                } else if (type == Token.LABEL || type == Token.LOOP || type == Token.SWITCH) {
                    sb.append(" [break: ");
                    appendPrintId(jump.target, printIds, sb);
                    sb.append(']');
                    if (type == Token.LOOP) {
                        sb.append(" [continue: ");
                        appendPrintId(jump.getContinue(), printIds, sb);
                        sb.append(']');
                    }
                } else {
                    sb.append(" [target: ");
                    appendPrintId(jump.target, printIds, sb);
                    sb.append(']');
                }
            } else if (type == Token.NUMBER) {
                sb.append(' ');
                sb.append(getDouble());
            } else if (type == Token.BIGINT) {
                sb.append(' ');
                sb.append(getBigInt().toString());
            } else if (type == Token.TARGET) {
                sb.append(' ');
                appendPrintId(this, printIds, sb);
            }
            if (lineno != -1) {
                sb.append(' ');
                sb.append(lineno);
            }

            for (PropListItem x = propListHead; x != null; x = x.next) {
                int type = x.type;
                sb.append(" [");
                sb.append(propToString(type));
                sb.append(": ");
                switch (type) {
                    case TARGETBLOCK_PROP: // can't add this as it recurses
                        sb.append("target block property");
                        break;
                    case LOCAL_BLOCK_PROP: // can't add this as it is dull
                        sb.append("last local block");
                        break;
                    case ISNUMBER_PROP:
                        switch (x.intValue) {
                            case BOTH:
                                sb.append("both");
                                break;
                            case RIGHT:
                                sb.append("right");
                                break;
                            case LEFT:
                                sb.append("left");
                                break;
                            default:
                                throw Kit.codeBug();
                        }
                        break;
                    case SPECIALCALL_PROP:
                        switch (x.intValue) {
                            case SPECIALCALL_EVAL:
                                sb.append("eval");
                                break;
                            case SPECIALCALL_WITH:
                                sb.append("with");
                                break;
                            default:
                                // NON_SPECIALCALL should not be stored
                                throw Kit.codeBug();
                        }
                        break;
                    case OBJECT_IDS_PROP:
                        {
                            Object[] a = (Object[]) x.objectValue;
                            sb.append("[");
                            for (int i = 0; i < a.length; i++) {
                                if (a[i] != null) sb.append(a[i].toString());
                                if (i + 1 < a.length) sb.append(", ");
                            }
                            sb.append("]");
                            break;
                        }
                    default:
                        Object obj = x.objectValue;
                        if (obj != null) {
                            sb.append(obj.toString());
                        } else {
                            sb.append(String.valueOf(x.intValue));
                        }
                        break;
                }
                sb.append(']');
            }
        }
    }