idx
int64
0
41.2k
question
stringlengths
73
5.81k
target
stringlengths
5
918
30,300
public static void fail ( String message , Object ... args ) { throw new IllegalStateException ( message == null ? "" : String . format ( message , args ) ) ; }
Fails a test with the given message .
30,301
public boolean canAccess ( ResourceField field , HttpMethod method , QueryContext queryContext , boolean allowIgnore ) { if ( field == null ) { return true ; } FilterBehavior filterBehavior = get ( field , method , queryContext ) ; if ( filterBehavior == FilterBehavior . NONE ) { return true ; } else if ( filterBehavior == FilterBehavior . FORBIDDEN || ! allowIgnore ) { String resourceType = field . getParentResourceInformation ( ) . getResourceType ( ) ; throw new ForbiddenException ( "field '" + resourceType + "." + field . getJsonName ( ) + "' cannot be accessed for " + method ) ; } else { LOGGER . debug ( "ignoring field {}" , field . getUnderlyingName ( ) ) ; PreconditionUtil . verifyEquals ( FilterBehavior . IGNORED , filterBehavior , "unknown behavior" ) ; return false ; } }
Allows to check whether the given field can be written .
30,302
public static MetaAttribute findAttribute ( MetaDataObject meta , Object value ) { if ( value == null ) { throw new IllegalArgumentException ( "null as value not supported" ) ; } for ( MetaAttribute attr : meta . getAttributes ( ) ) { if ( attr . getName ( ) . equals ( TYPE_ATTRIBUTE ) ) { continue ; } if ( attr . isDerived ( ) ) { continue ; } if ( attr . getType ( ) . getImplementationClass ( ) . isAssignableFrom ( value . getClass ( ) ) ) { return attr ; } } throw new IllegalArgumentException ( "cannot find anyType attribute for value '" + value + '\'' ) ; }
Finds a matching attribute for a given value .
30,303
public void setClassPath ( URL [ ] cp ) { baseClassPath . setPath ( cp ) ; initBaseLoader ( ) ; loaderMap = new HashMap ( ) ; classLoaderChanged ( ) ; }
Set a new base classpath and create a new base classloader . This means all types change .
30,304
public void reloadAllClasses ( ) throws ClassPathException { BshClassPath bcp = new BshClassPath ( "temp" ) ; bcp . addComponent ( baseClassPath ) ; bcp . addComponent ( BshClassPath . getUserClassPath ( ) ) ; setClassPath ( bcp . getPathComponents ( ) ) ; }
Overlay the entire path with a new class loader . Set the base path to the user path + base path .
30,305
public void reloadClasses ( String [ ] classNames ) throws ClassPathException { clearCaches ( ) ; if ( baseLoader == null ) initBaseLoader ( ) ; DiscreteFilesClassLoader . ClassSourceMap map = new DiscreteFilesClassLoader . ClassSourceMap ( ) ; for ( int i = 0 ; i < classNames . length ; i ++ ) { String name = classNames [ i ] ; ClassSource classSource = baseClassPath . getClassSource ( name ) ; if ( classSource == null ) { BshClassPath . getUserClassPath ( ) . insureInitialized ( ) ; classSource = BshClassPath . getUserClassPath ( ) . getClassSource ( name ) ; } if ( classSource == null ) throw new ClassPathException ( "Nothing known about class: " + name ) ; if ( classSource instanceof JarClassSource ) throw new ClassPathException ( "Cannot reload class: " + name + " from source: " + classSource ) ; map . put ( name , classSource ) ; } DiscreteFilesClassLoader . newInstance ( this , map ) ; Iterator it = map . keySet ( ) . iterator ( ) ; while ( it . hasNext ( ) ) loaderMap . put ( it . next ( ) , DiscreteFilesClassLoader . instance ( ) ) ; classLoaderChanged ( ) ; }
Reloading classes means creating a new classloader and using it whenever we are asked for classes in the appropriate space . For this we use a DiscreteFilesClassLoader
30,306
public BshClassPath getClassPath ( ) throws ClassPathException { if ( fullClassPath != null ) return fullClassPath ; fullClassPath = new BshClassPath ( "BeanShell Full Class Path" ) ; fullClassPath . addComponent ( BshClassPath . getUserClassPath ( ) ) ; try { fullClassPath . addComponent ( BshClassPath . getBootClassPath ( ) ) ; } catch ( ClassPathException e ) { System . err . println ( "Warning: can't get boot class path" ) ; } fullClassPath . addComponent ( baseClassPath ) ; return fullClassPath ; }
Get the full blown classpath .
30,307
protected void classLoaderChanged ( ) { Vector toRemove = new Vector ( ) ; for ( Enumeration e = listeners . elements ( ) ; e . hasMoreElements ( ) ; ) { WeakReference wr = ( WeakReference ) e . nextElement ( ) ; Listener l = ( Listener ) wr . get ( ) ; if ( l == null ) toRemove . add ( wr ) ; else l . classLoaderChanged ( ) ; } for ( Enumeration e = toRemove . elements ( ) ; e . hasMoreElements ( ) ; ) listeners . removeElement ( e . nextElement ( ) ) ; }
Clear global class cache and notify namespaces to clear their class caches .
30,308
public NameSpace get ( int depth ) { int size = stack . size ( ) ; if ( depth >= size ) return NameSpace . JAVACODE ; return stack . toArray ( new NameSpace [ size ] ) [ size - 1 - depth ] ; }
zero based .
30,309
public synchronized void set ( int depth , NameSpace ns ) { stack . set ( stack . size ( ) - 1 - depth , ns ) ; }
This is kind of crazy but used by the setNameSpace command . zero based .
30,310
public NameSpace swap ( NameSpace newTop ) { NameSpace oldTop = stack . pop ( ) ; stack . push ( newTop ) ; return oldTop ; }
Swap in the value as the new top of the stack and return the old value .
30,311
private byte [ ] replaceAsmInstructions ( final byte [ ] classFile , final boolean hasFrames ) { Attribute [ ] attributes = getAttributePrototypes ( ) ; firstField = null ; lastField = null ; firstMethod = null ; lastMethod = null ; firstAttribute = null ; compute = hasFrames ? MethodWriter . COMPUTE_INSERTED_FRAMES : MethodWriter . COMPUTE_NOTHING ; return toByteArray ( ) ; }
Returns the equivalent of the given class file with the ASM specific instructions replaced with standard ones . This is done with a ClassReader - &gt ; ClassWriter round trip .
30,312
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 ) ; } }
Shared system object visible under bsh . system
30,313
public static void main ( String [ ] args ) { if ( args . length > 0 ) { String filename = args [ 0 ] ; String [ ] bshArgs ; if ( args . length > 1 ) { bshArgs = new String [ args . length - 1 ] ; System . arraycopy ( args , 1 , bshArgs , 0 , args . length - 1 ) ; } else bshArgs = new String [ 0 ] ; try { Interpreter interpreter = new Interpreter ( ) ; interpreter . setu ( "bsh.args" , bshArgs ) ; Object result = interpreter . source ( filename , interpreter . globalNameSpace ) ; if ( result instanceof Class ) try { invokeMain ( ( Class < ? > ) result , bshArgs ) ; } catch ( Exception e ) { Object o = e ; if ( e instanceof InvocationTargetException ) o = e . getCause ( ) ; System . err . println ( "Class: " + result + " main method threw exception:" + o ) ; } } catch ( FileNotFoundException e ) { System . err . println ( "File not found: " + e ) ; } catch ( TargetError e ) { System . err . println ( "Script threw exception: " + e ) ; if ( e . inNativeCode ( ) ) e . printStackTrace ( DEBUG . get ( ) , System . err ) ; } catch ( EvalError e ) { System . err . println ( "Evaluation Error: " + e ) ; } catch ( IOException e ) { System . err . println ( "I/O Error: " + e ) ; } } else { @ SuppressWarnings ( "resource" ) Interpreter interpreter = new Interpreter ( new CommandLineReader ( new FileReader ( System . in ) ) , System . out , System . err , true ) ; interpreter . run ( ) ; } }
Run the text only interpreter on the command line or specify a file .
30,314
public Object source ( String filename , NameSpace nameSpace ) throws FileNotFoundException , IOException , EvalError { File file = pathToFile ( filename ) ; Interpreter . debug ( "Sourcing file: " , file ) ; Reader sourceIn = new BufferedReader ( new FileReader ( file ) ) ; try { return eval ( sourceIn , nameSpace , filename ) ; } finally { sourceIn . close ( ) ; } }
Read text from fileName and eval it .
30,315
public Object source ( String filename ) throws FileNotFoundException , IOException , EvalError { return source ( filename , globalNameSpace ) ; }
Read text from fileName and eval it . Convenience method . Use the global namespace .
30,316
public Object eval ( Reader in ) throws EvalError { return eval ( in , globalNameSpace , null == sourceFileInfo ? "eval stream" : sourceFileInfo ) ; }
Evaluate the inputstream in this interpreter s global namespace .
30,317
public Object eval ( String statements ) throws EvalError { Interpreter . debug ( "eval(String): " , statements ) ; return eval ( statements , globalNameSpace ) ; }
Evaluate the string in this interpreter s global namespace .
30,318
public Object eval ( String statements , NameSpace nameSpace ) throws EvalError { String s = ( statements . endsWith ( ";" ) ? statements : statements + ";" ) ; return eval ( new StringReader ( s ) , nameSpace , "inline evaluation of: ``" + showEvalString ( s ) + "''" ) ; }
Evaluate the string in the specified namespace .
30,319
public final static void debug ( Object ... msg ) { if ( DEBUG . get ( ) ) { StringBuilder sb = new StringBuilder ( ) ; for ( Object m : msg ) sb . append ( m ) ; Console . debug . println ( "// Debug: " + sb . toString ( ) ) ; } }
Print a debug message on debug stream associated with this interpreter only if debugging is turned on .
30,320
Object getu ( String name ) { try { return get ( name ) ; } catch ( EvalError e ) { throw new InterpreterError ( "set: " + e , e ) ; } }
Unchecked get for internal use
30,321
void setu ( String name , Object value ) { try { set ( name , value ) ; } catch ( EvalError e ) { throw new InterpreterError ( "set: " + e , e ) ; } }
Unchecked set for internal use
30,322
public void unset ( String name ) throws EvalError { CallStack callstack = new CallStack ( ) ; try { LHS lhs = globalNameSpace . getNameResolver ( name ) . toLHS ( callstack , this ) ; if ( lhs . type != LHS . VARIABLE ) throw new EvalError ( "Can't unset, not a variable: " + name , SimpleNode . JAVACODE , new CallStack ( ) ) ; lhs . nameSpace . unsetVariable ( name ) ; } catch ( UtilEvalError e ) { throw new EvalError ( e . getMessage ( ) , SimpleNode . JAVACODE , new CallStack ( ) , e ) ; } }
Unassign the variable name . Name should evaluate to a variable .
30,323
private boolean readLine ( ) throws ParseException { try { return parser . Line ( ) ; } catch ( ParseException e ) { yield ( ) ; if ( EOF ) return true ; throw e ; } }
Blocking call to read a line from the parser .
30,324
public File pathToFile ( String fileName ) throws IOException { String cwd = ( String ) getu ( "bsh.cwd" ) ; File file = new File ( fileName ) ; if ( ! file . isAbsolute ( ) ) { file = new File ( cwd + File . separator + fileName ) ; } return new File ( file . getCanonicalPath ( ) ) ; }
Localize a path to the file name based on the bsh . cwd interpreter working directory .
30,325
private void readObject ( ObjectInputStream stream ) throws IOException , ClassNotFoundException { stream . defaultReadObject ( ) ; setOut ( System . out ) ; setErr ( System . err ) ; }
De - serialization setup . Default out and err streams to stdout stderr if they are null .
30,326
public void addComponent ( BshClassPath bcp ) { if ( bcp == null ) return ; if ( compPaths == null ) compPaths = new ArrayList ( ) ; compPaths . add ( bcp ) ; bcp . addListener ( this ) ; }
Add the specified BshClassPath as a component of our path . Changes in the bcp will be reflected through us .
30,327
synchronized public Set getClassesForPackage ( String pack ) { insureInitialized ( ) ; Set set = new HashSet ( ) ; Collection c = ( Collection ) packageMap . get ( pack ) ; if ( c != null ) set . addAll ( c ) ; if ( compPaths != null ) for ( int i = 0 ; i < compPaths . size ( ) ; i ++ ) { c = ( ( BshClassPath ) compPaths . get ( i ) ) . getClassesForPackage ( pack ) ; if ( c != null ) set . addAll ( c ) ; } return set ; }
Return the set of class names in the specified package including all component paths .
30,328
synchronized public ClassSource getClassSource ( String className ) { ClassSource cs = ( ClassSource ) classSource . get ( className ) ; if ( cs != null ) return cs ; insureInitialized ( ) ; cs = ( ClassSource ) classSource . get ( className ) ; if ( cs == null && compPaths != null ) for ( int i = 0 ; i < compPaths . size ( ) && cs == null ; i ++ ) cs = ( ( BshClassPath ) compPaths . get ( i ) ) . getClassSource ( className ) ; return cs ; }
Return the source of the specified class which may lie in component path .
30,329
synchronized private void clearCachedStructures ( ) { mapsInitialized = false ; packageMap = new HashMap ( ) ; classSource = new HashMap ( ) ; unqNameTable = null ; nameSpaceChanged ( ) ; }
Clear anything cached . All will be reconstructed as necessary .
30,330
static String [ ] traverseDirForClasses ( File dir ) throws IOException { List list = traverseDirForClassesAux ( dir , dir ) ; return ( String [ ] ) list . toArray ( new String [ 0 ] ) ; }
Begin Static stuff
30,331
static String [ ] searchJrtFSForClasses ( URL url ) throws IOException { try { Path path = FileSystems . getFileSystem ( new URI ( "jrt:/" ) ) . getPath ( "modules" , url . getPath ( ) ) ; return Files . walk ( path ) . map ( Path :: toString ) . filter ( BshClassPath :: isClassFileName ) . map ( BshClassPath :: canonicalizeClassName ) . toArray ( String [ ] :: new ) ; } catch ( URISyntaxException e ) { } return new String [ 0 ] ; }
Search jrt file system for module classes .
30,332
static String [ ] searchJarFSForClasses ( URL url ) throws IOException { try { try { FileSystems . newFileSystem ( url . toURI ( ) , new HashMap < > ( ) ) ; } catch ( FileSystemAlreadyExistsException e ) { } Path path = FileSystems . getFileSystem ( url . toURI ( ) ) . getPath ( "/" ) ; return Files . walk ( path ) . map ( Path :: toString ) . filter ( BshClassPath :: isClassFileName ) . map ( BshClassPath :: canonicalizeClassName ) . toArray ( String [ ] :: new ) ; } catch ( URISyntaxException e ) { } return new String [ 0 ] ; }
Search jar file system for classes .
30,333
static String [ ] searchArchiveForClasses ( URL url ) throws IOException { List < String > list = new ArrayList < > ( ) ; ZipInputStream zip = new ZipInputStream ( url . openStream ( ) ) ; ZipEntry ze ; while ( zip . available ( ) == 1 ) if ( ( ze = zip . getNextEntry ( ) ) != null && isClassFileName ( ze . getName ( ) ) ) list . add ( canonicalizeClassName ( ze . getName ( ) ) ) ; zip . close ( ) ; return list . toArray ( new String [ list . size ( ) ] ) ; }
Search Archive for classes .
30,334
public static String [ ] splitClassname ( String classname ) { classname = canonicalizeClassName ( classname ) ; int i = classname . lastIndexOf ( "." ) ; String classn , packn ; if ( i == - 1 ) { classn = classname ; packn = "<unpackaged>" ; } else { packn = classname . substring ( 0 , i ) ; classn = classname . substring ( i + 1 ) ; } return new String [ ] { packn , classn } ; }
Split class name into package and name
30,335
public static Collection removeInnerClassNames ( Collection col ) { List list = new ArrayList ( ) ; list . addAll ( col ) ; Iterator it = list . iterator ( ) ; while ( it . hasNext ( ) ) { String name = ( String ) it . next ( ) ; if ( name . indexOf ( "$" ) != - 1 ) it . remove ( ) ; } return list ; }
Return a new collection without any inner class names
30,336
public Set getPackagesSet ( ) { insureInitialized ( ) ; Set set = new HashSet ( ) ; set . addAll ( packageMap . keySet ( ) ) ; if ( compPaths != null ) for ( int i = 0 ; i < compPaths . size ( ) ; i ++ ) set . addAll ( ( ( BshClassPath ) compPaths . get ( i ) ) . packageMap . keySet ( ) ) ; return set ; }
Get a list of all of the known packages
30,337
void nameSpaceChanged ( ) { if ( nameSourceListeners == null ) return ; for ( int i = 0 ; i < nameSourceListeners . size ( ) ; i ++ ) ( ( NameSource . Listener ) ( nameSourceListeners . get ( i ) ) ) . nameSourceChanged ( this ) ; }
Fire the NameSourceListeners
30,338
public void addNameSourceListener ( NameSource . Listener listener ) { if ( nameSourceListeners == null ) nameSourceListeners = new ArrayList ( ) ; nameSourceListeners . add ( listener ) ; }
Implements NameSource Add a listener who is notified upon changes to names in this space .
30,339
Object getClassInstance ( ) throws UtilEvalError { if ( this . classInstance != null ) return this . classInstance ; if ( this . classStatic != null ) throw new UtilEvalError ( "Can't refer to class instance from static context." ) ; else throw new InterpreterError ( "Can't resolve class instance 'this' in: " + this ) ; }
Gets the class instance .
30,340
public Object get ( final String name , final Interpreter interpreter ) throws UtilEvalError { final CallStack callstack = new CallStack ( this ) ; return this . getNameResolver ( name ) . toObject ( callstack , interpreter ) ; }
Resolve name to an object through this namespace .
30,341
public Variable setLocalVariable ( final String name , final Object value , final boolean strictJava ) throws UtilEvalError { return this . setVariable ( name , value , strictJava , false ) ; }
Set a variable explicitly in the local scope .
30,342
public boolean isChildOf ( NameSpace parent ) { return null != this . getParent ( ) && ( this . getParent ( ) . equals ( parent ) || this . getParent ( ) . isChildOf ( parent ) ) ; }
Check if this namespace is a child of the given namespace .
30,343
public This getSuper ( final Interpreter declaringInterpreter ) { if ( this . parent != null ) return this . parent . getThis ( declaringInterpreter ) ; else return this . getThis ( declaringInterpreter ) ; }
Get the parent namespace This reference or this namespace This reference if we are the top .
30,344
public BshClassManager getClassManager ( ) { if ( this . classManager != null ) return this . classManager ; if ( this . parent != null && this . parent != JAVACODE ) return this . parent . getClassManager ( ) ; this . setClassManager ( BshClassManager . createClassManager ( null ) ) ; return this . classManager ; }
Gets the class manager .
30,345
public Object getVariable ( final String name , final boolean recurse ) throws UtilEvalError { final Variable var = this . getVariableImpl ( name , recurse ) ; return this . unwrapVariable ( var ) ; }
Get the specified variable in this namespace .
30,346
public void setTypedVariable ( final String name , final Class < ? > type , final Object value , final boolean isFinal ) throws UtilEvalError { final Modifiers modifiers = new Modifiers ( Modifiers . FIELD ) ; if ( isFinal ) modifiers . addModifier ( "final" ) ; this . setTypedVariable ( name , type , value , modifiers ) ; }
Sets the typed variable .
30,347
public void setMethod ( BshMethod method ) { String name = method . getName ( ) ; if ( ! this . methods . containsKey ( name ) ) this . methods . put ( name , new ArrayList < BshMethod > ( 1 ) ) ; this . methods . get ( name ) . remove ( method ) ; this . methods . get ( name ) . add ( 0 , method ) ; }
Dissallow static vars outside of a class .
30,348
public BshMethod getMethod ( final String name , final Class < ? > [ ] sig ) throws UtilEvalError { return this . getMethod ( name , sig , false ) ; }
Gets the method .
30,349
public void importClass ( final String name ) { this . importedClasses . put ( Name . suffix ( name , 1 ) , name ) ; this . nameSpaceChanged ( ) ; }
Import a class name . Subsequent imports override earlier ones
30,350
public void importPackage ( final String name ) { this . importedPackages . remove ( name ) ; this . importedPackages . add ( 0 , name ) ; this . nameSpaceChanged ( ) ; }
subsequent imports override earlier ones .
30,351
protected BshMethod getImportedMethod ( final String name , final Class < ? > [ ] sig ) throws UtilEvalError { for ( final Object object : this . importedObjects ) { final Invocable method = Reflect . resolveJavaMethod ( object . getClass ( ) , name , sig , false ) ; if ( method != null ) return new BshMethod ( method , object ) ; } for ( final Class < ? > stat : this . importedStatic ) { final Invocable method = Reflect . resolveJavaMethod ( stat , name , sig , true ) ; if ( method != null ) return new BshMethod ( method , null ) ; } return null ; }
Gets the imported method .
30,352
protected Variable getImportedVar ( final String name ) throws UtilEvalError { Variable var = null ; for ( final Object object : this . importedObjects ) { final Invocable field = Reflect . resolveJavaField ( object . getClass ( ) , name , false ) ; if ( field != null ) var = this . createVariable ( name , field . getReturnType ( ) , new LHS ( object , field ) ) ; else if ( this . isClass ) { Class < ? > supr = object . getClass ( ) ; while ( Reflect . isGeneratedClass ( supr = supr . getSuperclass ( ) ) ) { This ths = Reflect . getClassInstanceThis ( object , supr . getSimpleName ( ) ) ; if ( null != ths && null != ( var = ths . getNameSpace ( ) . variables . get ( name ) ) ) break ; } } if ( null != var ) { this . variables . put ( name , var ) ; return var ; } } for ( final Class < ? > stat : this . importedStatic ) { final Invocable field = Reflect . resolveJavaField ( stat , name , true ) ; if ( field != null ) { var = this . createVariable ( name , field . getReturnType ( ) , new LHS ( field ) ) ; this . variables . put ( name , var ) ; return var ; } } return null ; }
Gets the imported var .
30,353
private BshMethod loadScriptedCommand ( final InputStream in , final String name , final Class < ? > [ ] argTypes , final String resourcePath , final Interpreter interpreter ) throws UtilEvalError { try ( FileReader reader = new FileReader ( in ) ) { interpreter . eval ( reader , this , resourcePath ) ; } catch ( IOException | EvalError e ) { Interpreter . debug ( e . toString ( ) ) ; throw new UtilEvalError ( "Error loading script: " + e . getMessage ( ) , e ) ; } final BshMethod meth = this . getMethod ( name , argTypes ) ; return meth ; }
Load a command script from the input stream and find the BshMethod in the target namespace .
30,354
public Class < ? > getClass ( final String name ) throws UtilEvalError { final Class < ? > c = this . getClassImpl ( name ) ; if ( c != null ) return c ; if ( this . parent != null ) return this . parent . getClass ( name ) ; return null ; }
Load a class through this namespace taking into account imports . The class search will proceed through the parent namespaces if necessary .
30,355
public String [ ] getAllNames ( ) { final List < String > vec = new ArrayList < String > ( ) ; this . getAllNamesAux ( vec ) ; return vec . toArray ( new String [ vec . size ( ) ] ) ; }
Implements NameSource .
30,356
protected void getAllNamesAux ( final List < String > vec ) { vec . addAll ( this . variables . keySet ( ) ) ; if ( methods != null ) vec . addAll ( this . methods . keySet ( ) ) ; if ( this . parent != null ) this . parent . getAllNamesAux ( vec ) ; }
Helper for implementing NameSource .
30,357
public void clear ( ) { this . variables . clear ( ) ; this . methods . clear ( ) ; this . importedClasses . clear ( ) ; this . importedPackages . clear ( ) ; this . importedCommands . clear ( ) ; this . importedObjects . clear ( ) ; if ( this . parent == null ) this . loadDefaultImports ( ) ; this . classCache . clear ( ) ; this . names . clear ( ) ; }
Clear all variables methods and imports from this namespace . If this namespace is the root it will be reset to the default imports .
30,358
public void importStatic ( final Class < ? > clas ) { this . importedStatic . remove ( clas ) ; this . importedStatic . add ( 0 , clas ) ; this . nameSpaceChanged ( ) ; }
Import static .
30,359
String getPackage ( ) { if ( this . packageName != null ) return this . packageName ; if ( this . parent != null ) return this . parent . getPackage ( ) ; return null ; }
Gets the package .
30,360
boolean attemptSetPropertyValue ( final String propName , final Object value , final Interpreter interp ) throws UtilEvalError { final String accessorName = Reflect . accessorName ( Reflect . SET_PREFIX , propName ) ; Object val = Primitive . unwrap ( value ) ; final Class < ? > [ ] classArray = new Class < ? > [ ] { val == null ? null : val . getClass ( ) } ; final BshMethod m = this . getMethod ( accessorName , classArray ) ; if ( m != null ) try { this . invokeMethod ( accessorName , new Object [ ] { value } , interp ) ; return true ; } catch ( final EvalError ee ) { throw new UtilEvalError ( "'This' property accessor threw exception: " + ee . getMessage ( ) , ee ) ; } return false ; }
If a writable property exists for the given name set it and return true otherwise do nothing and return false .
30,361
Object getPropertyValue ( final String propName , final Interpreter interp ) throws UtilEvalError { String accessorName = Reflect . accessorName ( Reflect . GET_PREFIX , propName ) ; final Class < ? > [ ] classArray = Reflect . ZERO_TYPES ; BshMethod m = this . getMethod ( accessorName , classArray ) ; try { if ( m != null ) return m . invoke ( ( Object [ ] ) null , interp ) ; accessorName = Reflect . accessorName ( Reflect . IS_PREFIX , propName ) ; m = this . getMethod ( accessorName , classArray ) ; if ( m != null && m . getReturnType ( ) == Boolean . TYPE ) return m . invoke ( ( Object [ ] ) null , interp ) ; return Primitive . VOID ; } catch ( final EvalError ee ) { throw new UtilEvalError ( "'This' property accessor threw exception: " + ee . getMessage ( ) , ee ) ; } }
Get a property from a scripted object or Primitive . VOID if no such property exists .
30,362
public Object eval ( CallStack callstack , Interpreter interpreter ) throws EvalError { NameSpace namespace = callstack . top ( ) ; BSHAmbiguousName nameNode = getNameNode ( ) ; if ( "fail" . equals ( nameNode . text ) ) interpreter . getNameSpace ( ) . setNode ( this ) ; if ( namespace . getParent ( ) != null && namespace . getParent ( ) . isClass && ( nameNode . text . equals ( "super" ) || nameNode . text . equals ( "this" ) ) ) return Primitive . VOID ; Name name = nameNode . getName ( namespace ) ; Object [ ] args = getArgsNode ( ) . getArguments ( callstack , interpreter ) ; try { return name . invokeMethod ( interpreter , args , callstack , this ) ; } catch ( ReflectError e ) { throw new EvalError ( "Error in method invocation: " + e . getMessage ( ) , this , callstack , e ) ; } catch ( InvocationTargetException e ) { String msg = "Method Invocation " + name ; Throwable te = e . getCause ( ) ; boolean isNative = true ; if ( te instanceof EvalError ) if ( te instanceof TargetError ) isNative = ( ( TargetError ) te ) . inNativeCode ( ) ; else isNative = false ; throw new TargetError ( msg , te , this , callstack , isNative ) ; } catch ( UtilEvalError e ) { throw e . toEvalError ( this , callstack ) ; } }
Evaluate the method invocation with the specified callstack and interpreter
30,363
public Class < ? > generateClass ( String name , Modifiers modifiers , Class < ? > [ ] interfaces , Class < ? > superClass , BSHBlock block , Type type , CallStack callstack , Interpreter interpreter ) throws EvalError { return generateClassImpl ( name , modifiers , interfaces , superClass , block , type , callstack , interpreter ) ; }
Parse the BSHBlock for the class definition and generate the class .
30,364
public static Class < ? > generateClassImpl ( String name , Modifiers modifiers , Class < ? > [ ] interfaces , Class < ? > superClass , BSHBlock block , Type type , CallStack callstack , Interpreter interpreter ) throws EvalError { 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 ( ) ; bcm . definingClass ( fqClassName ) ; NameSpace classStaticNameSpace = new NameSpace ( enclosingNameSpace , className ) ; classStaticNameSpace . isClass = true ; callstack . push ( classStaticNameSpace ) ; block . evalBlock ( callstack , interpreter , true , ClassNodeFilter . CLASSCLASSES ) ; Variable [ ] variables = getDeclaredVariables ( block , callstack , interpreter , packageName ) ; DelayedEvalBshMethod [ ] methods = getDeclaredMethods ( block , callstack , interpreter , packageName , superClass ) ; callstack . pop ( ) ; classStaticNameSpace . getThis ( interpreter ) ; ClassGeneratorUtil classGenerator = new ClassGeneratorUtil ( modifiers , className , packageName , superClass , interfaces , variables , methods , classStaticNameSpace , type ) ; classGenerator . initStaticNameSpace ( classStaticNameSpace , block ) ; Class < ? > genClass = bcm . getAssociatedClass ( fqClassName ) ; if ( genClass == null ) { byte [ ] code = classGenerator . generateClass ( ) ; if ( Interpreter . getSaveClasses ( ) ) saveClasses ( className , code ) ; genClass = bcm . defineClass ( fqClassName , code ) ; Interpreter . debug ( "Define " , fqClassName , " as " , genClass ) ; } enclosingNameSpace . importClass ( fqClassName . replace ( '$' , '.' ) ) ; classStaticNameSpace . setClassStatic ( genClass ) ; Interpreter . debug ( classStaticNameSpace ) ; bcm . doneDefiningClass ( fqClassName ) ; if ( interpreter . getStrictJava ( ) ) ClassGeneratorUtil . checkAbstractMethodImplementation ( genClass ) ; return genClass ; }
Parse the BSHBlock for for the class definition and generate the class using ClassGenerator .
30,365
static Object bigIntegerBinaryOperation ( BigInteger lhs , BigInteger rhs , int kind ) { switch ( kind ) { case PLUS : return lhs . add ( rhs ) ; case MINUS : return lhs . subtract ( rhs ) ; case STAR : return lhs . multiply ( rhs ) ; case SLASH : return lhs . divide ( rhs ) ; case MOD : case MODX : return lhs . mod ( rhs ) ; case POWER : case POWERX : return lhs . pow ( rhs . intValue ( ) ) ; case LSHIFT : case LSHIFTX : return lhs . shiftLeft ( rhs . intValue ( ) ) ; case RSIGNEDSHIFT : case RSIGNEDSHIFTX : return lhs . shiftRight ( rhs . intValue ( ) ) ; case RUNSIGNEDSHIFT : case RUNSIGNEDSHIFTX : if ( lhs . signum ( ) >= 0 ) return lhs . shiftRight ( rhs . intValue ( ) ) ; BigInteger opener = BigInteger . ONE . shiftLeft ( lhs . toString ( 2 ) . length ( ) + 1 ) ; BigInteger opened = lhs . subtract ( opener ) ; BigInteger mask = opener . subtract ( BigInteger . ONE ) . shiftRight ( rhs . intValue ( ) + 1 ) ; return opened . shiftRight ( rhs . intValue ( ) ) . and ( mask ) ; case BIT_AND : case BIT_ANDX : return lhs . and ( rhs ) ; case BIT_OR : case BIT_ORX : return lhs . or ( rhs ) ; case XOR : case XORX : return lhs . xor ( rhs ) ; } throw new InterpreterError ( "Unimplemented binary integer operator" ) ; }
returns Object covering both Integer and Boolean return types
30,366
static Object doubleBinaryOperation ( double lhs , double rhs , int kind ) throws UtilEvalError { switch ( kind ) { case PLUS : if ( lhs > 0d && ( Double . MAX_VALUE - lhs ) < rhs ) break ; return lhs + rhs ; case MINUS : if ( lhs < 0d && ( - Double . MAX_VALUE - lhs ) > - rhs ) break ; return lhs - rhs ; case STAR : if ( lhs != 0 && Double . MAX_VALUE / lhs < rhs ) break ; return lhs * rhs ; case SLASH : return lhs / rhs ; case MOD : case MODX : return lhs % rhs ; case POWER : case POWERX : double check = Math . pow ( lhs , rhs ) ; if ( Double . isInfinite ( check ) ) break ; return check ; case LSHIFT : case LSHIFTX : case RSIGNEDSHIFT : case RSIGNEDSHIFTX : case RUNSIGNEDSHIFT : case RUNSIGNEDSHIFTX : throw new UtilEvalError ( "Can't shift floatingpoint values" ) ; } if ( OVERFLOW_OPS . contains ( kind ) ) return bigDecimalBinaryOperation ( BigDecimal . valueOf ( lhs ) , BigDecimal . valueOf ( rhs ) , kind ) ; throw new InterpreterError ( "Unimplemented binary double operator" ) ; }
returns Object covering both Double and Boolean return types
30,367
static Number promoteToInteger ( Object wrapper ) { if ( wrapper instanceof Character ) return Integer . valueOf ( ( ( Character ) wrapper ) . charValue ( ) ) ; if ( wrapper instanceof Byte || wrapper instanceof Short ) return Integer . valueOf ( ( ( Number ) wrapper ) . intValue ( ) ) ; return ( Number ) wrapper ; }
Promote primitive wrapper type to Integer wrapper type
30,368
Symbol addConstant ( final Object value ) { if ( value instanceof Integer ) { return addConstantInteger ( ( ( Integer ) value ) . intValue ( ) ) ; } else if ( value instanceof Byte ) { return addConstantInteger ( ( ( Byte ) value ) . intValue ( ) ) ; } else if ( value instanceof Character ) { return addConstantInteger ( ( ( Character ) value ) . charValue ( ) ) ; } else if ( value instanceof Short ) { return addConstantInteger ( ( ( Short ) value ) . intValue ( ) ) ; } else if ( value instanceof Boolean ) { return addConstantInteger ( ( ( Boolean ) value ) . booleanValue ( ) ? 1 : 0 ) ; } else if ( value instanceof Float ) { return addConstantFloat ( ( ( Float ) value ) . floatValue ( ) ) ; } else if ( value instanceof Long ) { return addConstantLong ( ( ( Long ) value ) . longValue ( ) ) ; } else if ( value instanceof Double ) { return addConstantDouble ( ( ( Double ) value ) . doubleValue ( ) ) ; } else if ( value instanceof String ) { return addConstantString ( ( String ) value ) ; } else if ( value instanceof Type ) { Type type = ( Type ) value ; int typeSort = type . getSort ( ) ; if ( typeSort == Type . OBJECT ) { return addConstantClass ( type . getInternalName ( ) ) ; } else if ( typeSort == Type . METHOD ) { return addConstantMethodType ( type . getDescriptor ( ) ) ; } else { return addConstantClass ( type . getDescriptor ( ) ) ; } } else if ( value instanceof Handle ) { Handle handle = ( Handle ) value ; return addConstantMethodHandle ( handle . getTag ( ) , handle . getOwner ( ) , handle . getName ( ) , handle . getDesc ( ) , handle . isInterface ( ) ) ; } else { throw new IllegalArgumentException ( "value " + value ) ; } }
Adds a number or string constant to the constant pool of this symbol table . Does nothing if the constant pool already contains a similar item .
30,369
private void addConstantInteger ( final int index , final int tag , final int value ) { add ( new Entry ( index , tag , value , hash ( tag , value ) ) ) ; }
Adds a new CONSTANT_Integer_info or CONSTANT_Float_info to the constant pool of this symbol table .
30,370
private void addConstantLong ( final int index , final int tag , final long value ) { add ( new Entry ( index , tag , value , hash ( tag , value ) ) ) ; }
Adds a new CONSTANT_Double_info to the constant pool of this symbol table .
30,371
int addType ( final String value ) { int hashCode = hash ( Symbol . TYPE_TAG , value ) ; Entry entry = get ( hashCode ) ; while ( entry != null ) { if ( entry . tag == Symbol . TYPE_TAG && entry . hashCode == hashCode && entry . value . equals ( value ) ) { return entry . index ; } entry = entry . next ; } return addType ( new Entry ( typeCount , Symbol . TYPE_TAG , value , hashCode ) ) ; }
Adds a type in the type table of this symbol table . Does nothing if the type table already contains a similar type .
30,372
protected Class findClass ( String name ) throws ClassNotFoundException { ClassManagerImpl bcm = ( ClassManagerImpl ) getClassManager ( ) ; ClassLoader cl = bcm . getLoaderForClass ( name ) ; if ( cl != null && cl != this ) try { return cl . loadClass ( name ) ; } catch ( ClassNotFoundException e ) { throw new ClassNotFoundException ( "Designated loader could not find class: " + e ) ; } if ( getURLs ( ) . length > 0 ) try { return super . findClass ( name ) ; } catch ( ClassNotFoundException e ) { } cl = bcm . getBaseLoader ( ) ; if ( cl != null && cl != this ) try { return cl . loadClass ( name ) ; } catch ( ClassNotFoundException e ) { } return bcm . plainClassForName ( name ) ; }
add some caching for not found classes?
30,373
private Variable getVariableAtNode ( int index , CallStack callstack ) throws UtilEvalError { Node nameNode = null ; if ( jjtGetChild ( index ) . jjtGetNumChildren ( ) > 0 && ( nameNode = jjtGetChild ( index ) . jjtGetChild ( 0 ) ) instanceof BSHAmbiguousName ) return callstack . top ( ) . getVariableImpl ( ( ( BSHAmbiguousName ) nameNode ) . text , true ) ; return null ; }
Get Variable for value at specified index .
30,374
private Object checkNullValues ( Object val1 , Object val2 , int index , CallStack callstack ) throws EvalError { if ( Primitive . NULL == val1 && Primitive . VOID != val2 && jjtGetChild ( index ) . jjtGetChild ( 0 ) instanceof BSHAmbiguousName ) try { Variable var = null ; boolean val2IsString = val2 instanceof String ; Class < ? > val2Class = null ; if ( Primitive . NULL == val2 ) if ( null != ( var = getVariableAtNode ( index == 0 ? 1 : 0 , callstack ) ) ) { val2IsString = var . getType ( ) == String . class ; val2Class = var . getType ( ) ; var = null ; } if ( null == ( var = getVariableAtNode ( index , callstack ) ) ) return val1 ; switch ( kind ) { case EQ : case NE : if ( ( Primitive . NULL == val2 && val2Class == null ) || val2Class == var . getType ( ) || ( val2Class != null && ( var . getType ( ) . isAssignableFrom ( val2Class ) || val2Class . isAssignableFrom ( var . getType ( ) ) ) ) ) return val1 ; else if ( null != val2Class ) throw new EvalError ( "incomparable types: " + StringUtil . typeString ( var . getType ( ) ) + " and " + StringUtil . typeString ( val2Class ) , this , callstack ) ; } if ( kind == PLUS && ( val2IsString || var . getType ( ) == String . class ) ) return "null" ; if ( isWrapper ( var . getType ( ) ) ) throw new NullPointerException ( "null value with binary operator " + tokenImage [ kind ] ) ; throw new EvalError ( "bad operand types for binary operator " + tokenImage [ kind ] , this , callstack ) ; } catch ( NullPointerException e ) { throw new TargetError ( e , this , callstack ) ; } catch ( UtilEvalError e ) { e . toEvalError ( this , callstack ) ; } return val1 ; }
Apply null rules to operator values .
30,375
private boolean isWrapper ( Class < ? > cls ) { if ( null == cls ) return false ; if ( Boolean . class . isAssignableFrom ( cls ) ) switch ( kind ) { case EQ : case NE : case BOOL_OR : case BOOL_ORX : case BOOL_AND : case BOOL_ANDX : case BIT_AND : case BIT_ANDX : case BIT_OR : case BIT_ORX : case XOR : case XORX : return true ; default : return false ; } if ( Character . class . isAssignableFrom ( cls ) || Number . class . isAssignableFrom ( cls ) ) switch ( kind ) { case BOOL_AND : case BOOL_ANDX : case BOOL_OR : case BOOL_ORX : return false ; default : return true ; } return false ; }
Is the class a wrapper type . Also apply valid operator type to response .
30,376
private void arrayFillDefaultValue ( Object arr ) { if ( null == arr ) return ; Class < ? > clas = arr . getClass ( ) ; Class < ? > comp = Types . arrayElementType ( clas ) ; if ( ! comp . isPrimitive ( ) ) if ( Types . arrayDimensions ( clas ) > 1 ) for ( int i = 0 ; i < Array . getLength ( arr ) ; i ++ ) arrayFillDefaultValue ( Array . get ( arr , i ) ) ; else Arrays . fill ( ( Object [ ] ) arr , Primitive . unwrap ( Primitive . getDefaultValue ( comp ) ) ) ; }
Fill boxed numeric types with default numbers instead of nulls .
30,377
public void setValue ( Object value , int context ) throws UtilEvalError { if ( hasModifier ( "final" ) ) { if ( this . value != null ) throw new UtilEvalError ( "Cannot re-assign final variable " + name + "." ) ; if ( value == null ) return ; } if ( type != null && type != Object . class && value != null ) { this . value = Types . castObject ( value , type , context == DECLARATION ? Types . CAST : Types . ASSIGNMENT ) ; value = this . value ; } this . value = value ; if ( this . value == null && context != DECLARATION ) this . value = Primitive . getDefaultValue ( type ) ; if ( lhs != null ) this . value = lhs . assign ( this . value , false ) ; }
Set the value of the typed variable .
30,378
public static int eval ( String url , String text ) throws IOException { String returnValue = null ; if ( url . startsWith ( "http:" ) ) { returnValue = doHttp ( url , text ) ; } else if ( url . startsWith ( "bsh:" ) ) { returnValue = doBsh ( url , text ) ; } else throw new IOException ( "Unrecognized URL type." + "Scheme must be http:// or bsh://" ) ; if ( null != returnValue ) return Integer . parseInt ( returnValue ) ; return 0 ; }
Evaluate text in the interpreter at url returning a possible integer return value .
30,379
public Object eval ( CallStack callstack , Interpreter interpreter ) throws EvalError { throw new InterpreterError ( "Unimplemented or inappropriate for " + getClass ( ) . getName ( ) ) ; }
This is the general signature for evaluation of a node .
30,380
public String getText ( ) { StringBuilder text = new StringBuilder ( ) ; Token t = firstToken ; while ( t != null ) { text . append ( t . image ) ; if ( ! t . image . equals ( "." ) ) text . append ( " " ) ; if ( t == lastToken || t . image . equals ( "{" ) || t . image . equals ( ";" ) ) break ; t = t . next ; } return text . toString ( ) ; }
Get the text of the tokens comprising this node .
30,381
public void actionPerformed ( ActionEvent event ) { String cmd = event . getActionCommand ( ) ; if ( cmd . equals ( CUT ) ) { text . cut ( ) ; } else if ( cmd . equals ( COPY ) ) { text . copy ( ) ; } else if ( cmd . equals ( PASTE ) ) { text . paste ( ) ; } }
handle cut copy and paste
30,382
static void put ( final TypePath typePath , final ByteVector output ) { if ( typePath == null ) { output . putByte ( 0 ) ; } else { int length = typePath . typePathContainer [ typePath . typePathOffset ] * 2 + 1 ; output . putByteArray ( typePath . typePathContainer , typePath . typePathOffset , length ) ; } }
Puts the type_path JVMS structure corresponding to the given TypePath into the given ByteVector .
30,383
public String [ ] getParamTypeDescriptors ( ) { return methodType ( ) . parameterList ( ) . stream ( ) . map ( BSHType :: getTypeDescriptor ) . toArray ( String [ ] :: new ) ; }
Retrieve a bytecode descriptor representation of the parameter types .
30,384
public List < Object > collectParamaters ( Object base , Object [ ] params ) throws Throwable { parameters . clear ( ) ; for ( int i = 0 ; i < getLastParameterIndex ( ) ; i ++ ) parameters . add ( coerceToType ( params [ i ] , getParameterTypes ( ) [ i ] ) ) ; return parameters ; }
Basic parameter collection with pulling inherited cascade chaining .
30,385
protected Object coerceToType ( Object param , Class < ? > type ) throws Throwable { if ( type != Object . class ) param = Types . castObject ( param , type , Types . CAST ) ; return Primitive . unwrap ( param ) ; }
Coerce parameter values to parameter type and unwrap primitives .
30,386
private synchronized Object invokeTarget ( Object base , Object [ ] pars ) throws Throwable { Reflect . logInvokeMethod ( "Invoking method (entry): " , this , pars ) ; List < Object > params = collectParamaters ( base , pars ) ; Reflect . logInvokeMethod ( "Invoking method (after): " , this , params ) ; if ( getParameterCount ( ) > 0 ) return getMethodHandle ( ) . invokeWithArguments ( params ) ; if ( isStatic ( ) || this instanceof ConstructorInvocable ) return getMethodHandle ( ) . invoke ( ) ; return getMethodHandle ( ) . invoke ( params . get ( 0 ) ) ; }
All purpose MethodHandle invoke implementation with or without args .
30,387
public synchronized Object invoke ( Object base , Object ... pars ) throws InvocationTargetException { if ( null == pars ) pars = Reflect . ZERO_ARGS ; try { return Primitive . wrap ( invokeTarget ( base , pars ) , getReturnType ( ) ) ; } catch ( Throwable ite ) { throw new InvocationTargetException ( ite ) ; } }
Abstraction to cleanly apply the primitive result wrapping .
30,388
public void add ( NameSource source ) { if ( sources == null ) sources = new ArrayList ( ) ; sources . add ( source ) ; }
Add a NameSource which is monitored for names . Unimplemented - behavior is broken ... no updates
30,389
private < T > Iterator < T > emptyIt ( ) { return new Iterator < T > ( ) { public boolean hasNext ( ) { return false ; } public T next ( ) { return null ; } } ; }
An empty iterator with hasNext always false .
30,390
private Iterator < Object > arrayIt ( final Object array ) { return new Iterator < Object > ( ) { private int index = 0 ; private final int length = Array . getLength ( array ) ; public boolean hasNext ( ) { return this . index < this . length ; } public Object next ( ) { try { return Array . get ( array , this . index ++ ) ; } catch ( Throwable t ) { throw new NoSuchElementException ( t . getMessage ( ) ) ; } } } ; }
Obfuscated Object type or primitive array iterator .
30,391
private Stream < String > reflectNames ( Object obj ) { Class < ? > type = obj . getClass ( ) ; if ( obj instanceof Class < ? > ) type = ( Class < ? > ) obj ; if ( obj instanceof ClassIdentifier ) type = ( ( ClassIdentifier ) obj ) . getTargetClass ( ) ; if ( Reflect . isGeneratedClass ( type ) ) return Stream . concat ( Stream . concat ( Stream . of ( StringUtil . classString ( type ) ) , Stream . concat ( Stream . of ( Reflect . getDeclaredVariables ( type ) ) . map ( StringUtil :: variableString ) . map ( " " :: concat ) , Stream . of ( Reflect . getDeclaredMethods ( type ) ) . map ( StringUtil :: methodString ) . map ( " " :: concat ) ) ) , Stream . of ( "}" ) ) ; else return Stream . concat ( Stream . concat ( Stream . of ( StringUtil . classString ( type ) ) , Stream . concat ( Stream . of ( type . getFields ( ) ) . map ( StringUtil :: variableString ) . map ( " " :: concat ) , Stream . of ( type . getMethods ( ) ) . map ( StringUtil :: methodString ) . map ( " " :: concat ) ) ) , Stream . of ( "}" ) ) ; }
Apply reflection to supplied value returning an iterable stream of strings . Allows iteration over true string representations of the class and member definitions . For generated classes the true or bsh definitions are retrieved and not the java reflection of the mock instances .
30,392
public < T > Iterator < T > getBshIterator ( final Enumeration < T > obj ) { return Collections . list ( obj ) . iterator ( ) ; }
Gets iterator for enumerated elements .
30,393
public Iterator < Integer > getBshIterator ( final Number obj ) { int number = obj . intValue ( ) ; if ( number == 0 ) return this . emptyIt ( ) ; if ( number > 0 ) return IntStream . rangeClosed ( 0 , number ) . iterator ( ) ; return IntStream . rangeClosed ( number , 0 ) . map ( i -> number - i ) . iterator ( ) ; }
Gets iterator for Number range from 0 . Range from 0 up to number or 0 down to number inclusive . Empty Iterator if number is 0 .
30,394
public Iterator < String > getBshIterator ( final Character obj ) { Integer value = Integer . valueOf ( obj . charValue ( ) ) ; int check = 33 , start = 0 ; for ( int i : unicodeBlockStarts ) if ( check <= value ) { start = check ; check = i ; } else break ; return IntStream . rangeClosed ( start , value ) . boxed ( ) . map ( Character :: toChars ) . map ( String :: valueOf ) . iterator ( ) ; }
Gets iterator for character range from highest unicode block set starting position . Range from highest starting position which is less than supplied value code point .
30,395
public Iterator < ? > getBshIterator ( final Object obj ) { if ( obj == null ) return this . emptyIt ( ) ; if ( obj instanceof Primitive ) return this . getBshIterator ( Primitive . unwrap ( obj ) ) ; if ( obj . getClass ( ) . isArray ( ) ) return this . arrayIt ( obj ) ; if ( obj instanceof Iterable ) return this . getBshIterator ( ( Iterable < ? > ) obj ) ; if ( obj instanceof Iterator ) return this . getBshIterator ( ( Iterator < ? > ) obj ) ; if ( obj instanceof Enumeration ) return this . getBshIterator ( ( Enumeration < ? > ) obj ) ; if ( obj instanceof CharSequence ) return this . getBshIterator ( ( CharSequence ) obj ) ; if ( obj instanceof Number ) return this . getBshIterator ( ( Number ) obj ) ; if ( obj instanceof Character ) return this . getBshIterator ( ( Character ) obj ) ; if ( obj instanceof String ) return this . getBshIterator ( ( String ) obj ) ; return this . reflectNames ( obj ) . iterator ( ) ; }
Inspect the supplied object and cast type to delegates .
30,396
private synchronized String printTargetError ( Throwable t ) { StringBuilder msgs = new StringBuilder ( t . toString ( ) ) ; while ( null != ( t = t . getCause ( ) ) ) msgs . append ( "\n" ) . append ( t . toString ( ) ) ; return msgs . toString ( ) ; }
Generate a printable string showing the wrapped target exceptions .
30,397
public String getMessage ( ) { String trace ; if ( node != null ) trace = " : at Line: " + node . getLineNumber ( ) + " : in file: " + node . getSourceFile ( ) + " : " + node . getText ( ) ; else trace = ": <at unknown location>" ; if ( callstack != null ) trace = trace + "\n" + getScriptStackTrace ( ) ; return getRawMessage ( ) + trace ; }
Print the error with line number and stack trace .
30,398
private void prependMessage ( String s ) { if ( s == null ) return ; if ( message == null ) message = s ; else message = s + " : " + message ; }
Prepend the message if it is non - null .
30,399
public void replace ( String param , String value ) { int [ ] range ; while ( ( range = findTemplate ( param ) ) != null ) buff . replace ( range [ 0 ] , range [ 1 ] , value ) ; }
Substitute the specified text for the parameter