/** Shared system object visible under bsh.system */ public static void setShutdownOnExit(final boolean value) { try { SYSTEM_OBJECT.getNameSpace().setVariable("shutdownOnExit", Boolean.valueOf(value), false); } catch (final UtilEvalError utilEvalError) { throw new IllegalStateException(utilEvalError); } }
/** Delegate method to return enum values array. * @return array of enum values */ public Object[] enumValues() { return Reflect.getEnumConstants(getNameSpace().classStatic); }
public static void setShutdownOnExit(final boolean value) { try { SYSTEM_OBJECT.getNameSpace().setVariable("shutdownOnExit", Boolean.valueOf(value), false); } catch (final UtilEvalError utilEvalError) { throw new IllegalStateException(utilEvalError); } }
/** * Change the parent of the class instance namespace. * This is currently used for inner class support. * Note: This method will likely be removed in the future. */ // This could be static public void setInstanceNameSpaceParent(Object instance, String className, NameSpace parent) { This ithis = ClassGeneratorUtil.getClassInstanceThis(instance, className); ithis.getNameSpace().setParent(parent); }
public PreparsedScript(final String source, final ClassLoader classLoader) throws EvalError { final ClassManagerImpl classManager = new ClassManagerImpl(); classManager.setClassLoader(classLoader); final NameSpace nameSpace = new NameSpace("global", classManager); _interpreter = new Interpreter(new StringReader(""), System.out, System.err, false, nameSpace, null, null); try { final This callable = (This) _interpreter.eval("__execute() { " + source + "\n" + "}\n" + "return this;"); _method = callable.getNameSpace().getMethod("__execute", Reflect.ZERO_TYPES, false); } catch (final UtilEvalError e) { throw new IllegalStateException(e); } }
public PreparsedScript(final String source, final ClassLoader classLoader) throws EvalError { final ClassManagerImpl classManager = new ClassManagerImpl(); classManager.setClassLoader(classLoader); final NameSpace nameSpace = new NameSpace(classManager, "global"); _interpreter = new Interpreter(new StringReader(""), System.out, System.err, false, nameSpace, null, null); try { final This callable = (This) _interpreter.eval("__execute() { " + source + "\n" + "}\n" + "return this;"); _method = callable.getNameSpace().getMethod("__execute", new Class[0], false); } catch (final UtilEvalError e) { throw new IllegalStateException(e); } }
try { This instanceThis = initClassInstanceThis(instance, className); NameSpace instanceNameSpace = instanceThis.getNameSpace();
while (Reflect.isGeneratedClass(supr = supr.getSuperclass())) { This ths = Reflect.getClassInstanceThis(object, supr.getSimpleName()); if (null != ths && null != (var = ths.getNameSpace().variables.get(name))) break;
Name.getClassNameSpace( ths.getNameSpace() );
NameSpace instanceNameSpace = classStaticThis.getNameSpace().copy(); if (CONTEXT_NAMESPACE.get() != null) instanceNameSpace.setParent(CONTEXT_NAMESPACE.get()); instanceInitBlock = (BSHBlock) classStaticThis.getNameSpace().getVariable(BSHINIT.toString()); } catch (Exception e) { throw new InterpreterError("unable to get instance initializer: " + e, e);
/** Lazy initialize static context implementation. * Called from <clinit> after static This was populated we will now * proceed to evaluate the static block node. * @param genClass the generated class. * @param className name of the class. * @throws UtilEvalError combined exceptions. */ public static void initStatic(Class<?> genClass) throws UtilEvalError { String className = genClass.getSimpleName(); try { This staticThis = Reflect.getClassStaticThis(genClass, className); NameSpace classStaticNameSpace = staticThis.getNameSpace(); Interpreter interpreter = staticThis.declaringInterpreter; if (null == interpreter) throw new UtilEvalError("No namespace or interpreter for statitc This." +" Start interpreter for class not implemented yet."); //startInterpreterForClass(genClass); ??? BSHBlock block = (BSHBlock) classStaticNameSpace.getVariable(BSHINIT.toString()); CallStack callstack = new CallStack(classStaticNameSpace); // evaluate the static portion of the block in the static space block.evalBlock(callstack, interpreter, true/*override*/, CLASSSTATIC); // Validate that static final variables were set for (Variable var : Reflect.getVariables(classStaticNameSpace)) var.validateFinalIsSet(true); } catch (Exception e) { throw new UtilEvalError("Exception in static init block <clinit> for class " + className + ". With message: " + e.getMessage(), e); } }
thisNameSpace= ths.getNameSpace(); Object result = ths; thisNameSpace = ths.getNameSpace();
NameSpace instanceNameSpace = ths.getNameSpace();
instanceInitBlock = (BSHBlock) classStaticThis.getNameSpace().getVariable(BSHINIT); } catch (Exception e) { throw new InterpreterError("unable to get instance initializer: " + e); instanceNameSpace = classStaticThis.getNameSpace().copy(); instanceNameSpace.setParent(CONTEXT_NAMESPACE.get()); } else { instanceNameSpace = new NameSpace(classStaticThis.getNameSpace(), className); // todo: old code instanceNameSpace = instanceThis.getNameSpace();
thisNameSpace= ths.getNameSpace(); Object result = ths; thisNameSpace = ths.getNameSpace();
Object cons = classStaticThis.getNameSpace().getVariable(BSHCONSTRUCTORS.toString()); if (cons == Primitive.VOID) throw new InterpreterError("Unable to find constructors array in class"); NameSpace consArgsNameSpace = new NameSpace(classStaticThis.getNameSpace(), "consArgs"); String[] consArgNames = constructor.getParameterNames(); Class<?>[] consArgTypes = constructor.getParameterTypes();
DelayedEvalBshMethod[] constructors; try { constructors = (DelayedEvalBshMethod[]) classStaticThis.getNameSpace().getVariable(BSHCONSTRUCTORS); } catch (Exception e) { throw new InterpreterError("unable to get instance initializer: " + e); NameSpace consArgsNameSpace = new NameSpace(classStaticThis.getNameSpace(), "consArgs"); String[] consArgNames = constructor.getParameterNames(); Class[] consArgTypes = constructor.getParameterTypes();
NameSpace thisNameSpace = ths.getNameSpace(); thisNameSpace.setNode(callerInfo); NameSpace classNameSpace = getClassNameSpace( thisNameSpace );
NameSpace thisNameSpace = ths.getNameSpace(); NameSpace classNameSpace = getClassNameSpace( thisNameSpace ); if ( classNameSpace != null )