webit.script.core.ast.expressions.NativeStaticValue Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of webit-script Show documentation
Show all versions of webit-script Show documentation
a template-like script and engine, all writen with Java.
The newest version!
// Copyright (c) 2013-2014, Webit Team. All Rights Reserved.
package webit.script.core.ast.expressions;
import java.lang.reflect.Field;
import webit.script.Context;
import webit.script.core.ast.ResetableValueExpression;
import webit.script.exceptions.ScriptRuntimeException;
/**
*
* @author zqq90
*/
public class NativeStaticValue extends ResetableValueExpression {
private final Field field;
public NativeStaticValue(Field field, int line, int column) {
super(line, column);
this.field = field;
}
public Object execute(Context context) {
try {
return field.get(null);
} catch (Exception ex) {
return new ScriptRuntimeException("Failed to get static field value: ".concat(field.toString()), ex, this);
}
}
public Object setValue(Context context, Object value) {
try {
field.set(null, value);
return value;
} catch (Exception ex) {
return new ScriptRuntimeException("Failed to set static field value: ".concat(field.toString()), ex, this);
}
}
}