Package anvil.script.expression

Source Code of anvil.script.expression.StringBufferNode

/*
* $Id: StringBufferNode.java,v 1.5 2002/09/16 08:05:05 jkl Exp $
*
* Copyright (c) 2002 Njet Communications Ltd. All Rights Reserved.
*
* Use is subject to license terms, as defined in
* Anvil Sofware License, Version 1.1. See LICENSE
* file, or http://njet.org/license-1.1.txt
*/
package anvil.script.expression;

import anvil.core.Any;
import anvil.codec.Code;
import anvil.codec.ConstantPool;
import anvil.script.compiler.ByteCompiler;
import anvil.script.Context;
import java.io.IOException;

/**
* class StringBufferNode
*
* @author: Jani Lehtim�ki
*/
public class StringBufferNode extends MultiParent
{

  public StringBufferNode(Parent elements)
  {
    super(elements);
  }


  public int typeOf()
  {
    return Node.EXPR_STRING_BUFFER;
  }



  public Any eval()
  {
    StringBuffer buffer = new StringBuffer();
    int n = childs();
    for(int i=0; i<n; i++) {
      buffer.append(getChild(i).eval());
    }
    return Any.create(buffer.toString())
  }



  public void compile(ByteCompiler context, int operation)
  {
    Code code = context.getCode();
    ConstantPool pool = code.getPool();
    int clazz = pool.addClass("java/lang/StringBuffer");
    int appendmethod = pool.addMethodRef(clazz, "append",
      "(Ljava/lang/Object;)Ljava/lang/StringBuffer;");
    code.anew(clazz);
    code.dup();
    code.invokespecial(pool.addMethodRef(clazz, "<init>", "()V"));
    int n = childs();
    for(int i=0; i<n; i++) {
      getChild(i).compile(context, GET);
      code.invokevirtual(appendmethod);
    }
    code.invokevirtual(code.getPool().addMethodRef(context.TYPE_OBJECT,
      "toString", "()Ljava/lang/String;"));
    code.invokestatic(code.getPool().addMethodRef(context.TYPE_ANY,
      "create", "(Ljava/lang/String;)Lanvil/core/Any;"));
    if (operation == GET_BOOLEAN) {
      context.any2boolean();
    }
  }

}
TOP

Related Classes of anvil.script.expression.StringBufferNode

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.