All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cfml.parsing.cfscript.CFJavaMethodExpression Maven / Gradle / Ivy

There is a newer version: 2.11.0
Show newest version
package cfml.parsing.cfscript;

/**
 * This cannot be invoked/evaluated as a normal CFExpression is.
 * It simply acts as a holder of the Java method attributes 
 * (i.e. method name, and arguments being passed to it)
 */

import java.util.ArrayList;
import java.util.List;

import org.antlr.v4.runtime.Token;

import cfml.parsing.cfscript.script.CFScriptStatement;
import cfml.parsing.util.ArrayBuilder;

public class CFJavaMethodExpression extends CFExpression {
	
	private static final long serialVersionUID = 1L;
	
	private CFExpression name;
	private ArrayList args; // ArrayList of CFExpression's
	private boolean _onMissingMethod = false;
	
	public CFJavaMethodExpression(Token _t, CFExpression _name, ArrayList _args) {
		super(_t);
		name = _name;
		args = _args;
	}
	
	@Override
	public byte getType() {
		return CFExpression.FUNCTION;
	}
	
	public String getFunctionName() {
		return ((CFIdentifier) name).getName();
	}
	
	public ArrayList getArguments() {
		return args;
	}
	
	public boolean isOnMethodMissing() {
		return _onMissingMethod;
	}
	
	public void setOnMethodMissing() {
		_onMissingMethod = true;
	}
	
	@Override
	public String Decompile(int indent) {
		StringBuilder sb = new StringBuilder();
		sb.append(name.Decompile(indent));
		sb.append("(");
		
		for (int i = 0; i < args.size(); i++) {
			sb.append((args.get(i)).toString());
			if (i < args.size() - 1) {
				sb.append(", ");
			}
		}
		
		sb.append(")");
		
		return sb.toString();
	}
	
	public CFExpression getName() {
		return name;
	}
	
	public ArrayList getArgs() {
		return args;
	}
	
	public boolean isOnMissingMethod() {
		return _onMissingMethod;
	}
	
	@Override
	public List decomposeExpression() {
		List retval = new ArrayList();
		retval.add(name);
		retval.addAll(args);
		return retval;
	}
	
	@Override
	public List decomposeScript() {
		return ArrayBuilder.createCFScriptStatement();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy