// Path: src/gr/omadak/leviathan/asp/CommonConstants.java
// public final class CommonConstants {
//     private CommonConstants() {}
// 
// 	/** The common prefix of all anonymous functions in JavaScript */
// 	public static final String KEY_START = "$$$$";
// 
// 	private static final int MIN_TOKEN = 100000; //10^5
//     /** Declares an AST which contains an Object reference */ 
//     public static final int OBJECT = MIN_TOKEN + 1;
//     /** AST of this type are used as place holders for other AST */
//     public static final int TEMPLATE = MIN_TOKEN + 3;
//     /** Template node used to indicate the place for an instance AST */ 
//     public static final int INSTANCE = MIN_TOKEN + 4;
//     /** Template AST which is substituted with all the arguments a method
//     received*/
//     public static final int ALL_ARGS = MIN_TOKEN + 5;
//     /** The type for an uknown object */
//     public static final int INVALID_OBJECT = MIN_TOKEN + 6;
//     /** The type for headers which can not be translated */
//     public static final int NON_APPLICABLE_HEADER = MIN_TOKEN + 7;
//     /** Indicates the begining of the Root node for a Template AST */
//     public static final int TRANSLATE_ROOT = MIN_TOKEN + 8;
//     /** Indicates any type for an argument.
//     Means that the type is indifferent */
//     public static final int ANY = MIN_TOKEN + 9;
//     /** Inidcates an unsupported method or object */
//     public static final int UNSUPPORTED = MIN_TOKEN + 10;
//     /** The type could not be resolved */
//     public static final int UKNOWN_TYPE = MIN_TOKEN + 11;
//     /** Nodes which has this type, are the product of a Member translation
//     which returns an Object*/ 
//     public static final int OBJECT_RET = MIN_TOKEN + 12;
// 	/** Command to store a property. The node will be removed from
// 		the produced tree
// 	*/
// 	public static final int STORE = MIN_TOKEN + 13;
// 	/** Placeholder for a stored property.
// 		The node will be replaced with the value of the stored
// 		property
// 	*/
// 	public static final int STORED = MIN_TOKEN + 14;
// }


import antlr.ASTFactory;
import antlr.CommonToken;
import antlr.collections.AST;
import gr.omadak.leviathan.asp.CommonConstants;
import java.util.Arrays;
import java.util.BitSet;
import java.util.List;
import java.util.StringTokenizer;
import org.apache.log4j.Logger;
        if (ast.getType() == CommonConstants.TEMPLATE) {
            try {
                int index = Integer.parseInt(ast.getText().trim());
                index--;
                if (index < 0 || args == null || index >= args.size()) {
                    String msg = "Invalid index for argument replacement:"
                    + ast.getText();
                    if (args == null) {
                        msg += " because no args available";
                    } else if (index < 0) {
                        msg += " index should be at least 1";
                    } else {
                        msg += " index can not be greater than " + args.size();
                    }
                    throw new IndexOutOfBoundsException(msg);
                }
                AST replacement = getAST(index);
                result = dupList(replacement);
            } catch (IndexOutOfBoundsException ifb) {
                LOG.error(ifb.getMessage());
                errorsFound = true;
                result = create(INVALID_ARG);
            } catch (NumberFormatException nfe) {
                LOG.error(
                "Invalid text for argument template.Expected an int");
                errorsFound = true;
                result = create(INVALID_ARG);
            }
        } else if (ast.getType() == CommonConstants.ALL_ARGS) {
            result = dupAllArgs(ast);
// Path: src/gr/omadak/leviathan/asp/CommonConstants.java
// public final class CommonConstants {
//     private CommonConstants() {}
// 
// 	/** The common prefix of all anonymous functions in JavaScript */
// 	public static final String KEY_START = "$$$$";
// 
// 	private static final int MIN_TOKEN = 100000; //10^5
//     /** Declares an AST which contains an Object reference */ 
//     public static final int OBJECT = MIN_TOKEN + 1;
//     /** AST of this type are used as place holders for other AST */
//     public static final int TEMPLATE = MIN_TOKEN + 3;
//     /** Template node used to indicate the place for an instance AST */ 
//     public static final int INSTANCE = MIN_TOKEN + 4;
//     /** Template AST which is substituted with all the arguments a method
//     received*/
//     public static final int ALL_ARGS = MIN_TOKEN + 5;
//     /** The type for an uknown object */
//     public static final int INVALID_OBJECT = MIN_TOKEN + 6;
//     /** The type for headers which can not be translated */
//     public static final int NON_APPLICABLE_HEADER = MIN_TOKEN + 7;
//     /** Indicates the begining of the Root node for a Template AST */
//     public static final int TRANSLATE_ROOT = MIN_TOKEN + 8;
//     /** Indicates any type for an argument.
//     Means that the type is indifferent */
//     public static final int ANY = MIN_TOKEN + 9;
//     /** Inidcates an unsupported method or object */
//     public static final int UNSUPPORTED = MIN_TOKEN + 10;
//     /** The type could not be resolved */
//     public static final int UKNOWN_TYPE = MIN_TOKEN + 11;
//     /** Nodes which has this type, are the product of a Member translation
//     which returns an Object*/ 
//     public static final int OBJECT_RET = MIN_TOKEN + 12;
// 	/** Command to store a property. The node will be removed from
// 		the produced tree
// 	*/
// 	public static final int STORE = MIN_TOKEN + 13;
// 	/** Placeholder for a stored property.
// 		The node will be replaced with the value of the stored
// 		property
// 	*/
// 	public static final int STORED = MIN_TOKEN + 14;
// }


// Path: src/gr/omadak/leviathan/asp/objects/ASPFactory.java
import antlr.ASTFactory;
import antlr.CommonToken;
import antlr.collections.AST;
import gr.omadak.leviathan.asp.CommonConstants;
import java.util.Arrays;
import java.util.BitSet;
import java.util.List;
import java.util.StringTokenizer;
import org.apache.log4j.Logger;

        if (ast.getType() == CommonConstants.TEMPLATE) {
            try {
                int index = Integer.parseInt(ast.getText().trim());
                index--;
                if (index < 0 || args == null || index >= args.size()) {
                    String msg = "Invalid index for argument replacement:"
                    + ast.getText();
                    if (args == null) {
                        msg += " because no args available";
                    } else if (index < 0) {
                        msg += " index should be at least 1";
                    } else {
                        msg += " index can not be greater than " + args.size();
                    }
                    throw new IndexOutOfBoundsException(msg);
                }
                AST replacement = getAST(index);
                result = dupList(replacement);
            } catch (IndexOutOfBoundsException ifb) {
                LOG.error(ifb.getMessage());
                errorsFound = true;
                result = create(INVALID_ARG);
            } catch (NumberFormatException nfe) {
                LOG.error(
                "Invalid text for argument template.Expected an int");
                errorsFound = true;
                result = create(INVALID_ARG);
            }
        } else if (ast.getType() == CommonConstants.ALL_ARGS) {
            result = dupAllArgs(ast);
        } else if (ast.getType() == CommonConstants.INSTANCE) {