public BlockNameSpace( NameSpace parent ) throws EvalError { super( parent, parent.getName()+ "/BlockNameSpace" ); }
public BlockNameSpace( NameSpace parent ) { super( parent, parent.getName()+ "/BlockNameSpace" ); this.isMethod = parent.isMethod; }
private Object constructWithClassBody( Class type, Object[] args, BSHBlock block, CallStack callstack, Interpreter interpreter ) throws EvalError { String anon = "anon" + (++innerClassCount); String name = callstack.top().getName() + "$" + anon; This.CONTEXT_ARGS.get().put(anon, args); Modifiers modifiers = new Modifiers(Modifiers.CLASS); Class clas = ClassGenerator.getClassGenerator().generateClass( name, modifiers, null/*interfaces*/, type/*superClass*/, block, ClassGenerator.Type.CLASS, callstack, interpreter ); try { return Reflect.constructObject( clas, args ); } catch ( Exception e ) { Throwable cause = e; if ( e instanceof InvocationTargetException ) { cause = ((InvocationTargetException) e).getTargetException(); } throw new EvalError("Error constructing inner class instance: "+e, this, callstack, cause); } }
static DelayedEvalBshMethod[] getDeclaredMethods(BSHBlock body, CallStack callstack, Interpreter interpreter, String defaultPackage, Class<?> superClass) throws EvalError { List<DelayedEvalBshMethod> methods = new ArrayList<>(); if ( callstack.top().getName().indexOf("$anon") > -1 ) { // anonymous classes need super constructor String classBaseName = Types.getBaseName(callstack.top().getName()); Invocable con = BshClassManager.memberCache.get(superClass) .findMethod(superClass.getName(), This.CONTEXT_ARGS.get().get(classBaseName)); DelayedEvalBshMethod bm = new DelayedEvalBshMethod(classBaseName, con, callstack.top()); methods.add(bm); } for (int child = 0; child < body.jjtGetNumChildren(); child++) { SimpleNode node = (SimpleNode) body.jjtGetChild(child); if (node instanceof BSHMethodDeclaration) { BSHMethodDeclaration md = (BSHMethodDeclaration) node; md.insureNodesParsed(); Modifiers modifiers = md.modifiers; String name = md.name; String returnType = md.getReturnTypeDescriptor(callstack, interpreter, defaultPackage); BSHReturnType returnTypeNode = md.getReturnTypeNode(); BSHFormalParameters paramTypesNode = md.paramsNode; String[] paramTypes = paramTypesNode.getTypeDescriptors(callstack, interpreter, defaultPackage); DelayedEvalBshMethod bm = new DelayedEvalBshMethod(name, returnType, returnTypeNode, md.paramsNode.getParamNames(), paramTypes, paramTypesNode, md.blockNode, null/*declaringNameSpace*/, modifiers, callstack, interpreter); methods.add(bm); } } return methods.toArray(new DelayedEvalBshMethod[methods.size()]); }
public Object constructWithClassBody( BSHAllocationExpression node, Class type, Object[] args, BSHBlock block ) throws EvalError { String name = callstack.top().getName() + "$" + (++node.innerClassCount); Modifiers modifiers = new Modifiers(); modifiers.addModifier( Modifiers.CLASS, "public" ); Class clas = ClassGenerator.getClassGenerator() .generateClass( name, modifiers, null/*interfaces*/, type/*superClass*/, block, false/*isInterface*/, callstack, interpreter ); try { return Reflect.constructObject( clas, args ); } catch ( Exception e ) { Throwable cause = e; if ( e instanceof InvocationTargetException ) { cause = ((InvocationTargetException) e).getTargetException(); } throw new EvalError("Error constructing inner class instance: "+e, node, callstack, cause); } }
&& className.startsWith( instanceNameSpace.getName() +"$")
public String getScriptStackTrace() { if ( callstack == null ) return "<Unknown>"; String trace = ""; CallStack stack = callstack.copy(); while ( stack.depth() > 0 ) { NameSpace ns = stack.pop(); SimpleNode node = ns.getNode(); if ( ns.isMethod ) { trace = trace + "\nCalled from method: " + ns.getName(); if ( node != null ) trace += " : at Line: "+ node.getLineNumber() + " : in file: "+ node.getSourceFile() + " : "+node.getText(); } } return trace; }
/** This is the invocation handler for the dynamic proxy. <p> Notes: Inner class for the invocation handler seems to shield this unavailable interface from JDK1.2 VM... I don't understand this. JThis works just fine even if those classes aren't there (doesn't it?) This class shouldn't be loaded if an XThis isn't instantiated in NameSpace.java, should it? */ class Handler implements InvocationHandler, java.io.Serializable { public Object invoke( Object proxy, Method method, Object[] args ) throws Throwable { try { return invokeImpl( proxy, method, args ); } catch ( TargetError te ) { // Unwrap target exception. If the interface declares that // it throws the ex it will be delivered. If not it will be // wrapped in an UndeclaredThrowable // This isn't simple because unwrapping this loses all context info. // So rewrap is better than unwrap. - fschmidt Throwable t = te.getTarget(); Class<? extends Throwable> c = t.getClass(); String msg = t.getMessage(); try {
public String getScriptStackTrace() { if ( callstack == null ) return "<Unknown>"; String trace = ""; CallStack stack = callstack.copy(); while ( stack.depth() > 0 ) { NameSpace ns = stack.pop(); SimpleNode node = ns.getNode(); if ( ns.isMethod ) { trace = trace + "\nCalled from method: " + ns.getName(); if ( node != null ) trace += " : at Line: "+ node.getLineNumber() + " : in file: "+ node.getSourceFile() + " : "+node.getText(); } } return trace; }
String className = enclosingNameSpace.isClass ? (enclosingNameSpace.getName() + "$" + name) : name; String fqClassName = packageName == null ? className : packageName + "." + className;
NameSpace enclosingNameSpace = callstack.top(); String packageName = enclosingNameSpace.getPackage(); String className = enclosingNameSpace.isClass ? (enclosingNameSpace.getName() + "$" + name) : name; String fqClassName = packageName == null ? className : packageName + "." + className; BshClassManager bcm = interpreter.getClassManager();