PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 1ms RepoModel.GetById 39ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre4/bsh/commands/print.bsh

#
Unknown | 53 lines | 46 code | 7 blank | 0 comment | 0 complexity | d6a06daa019d40336d51ec5f60fab412 MD5 | raw file
 1/**
 2	Print the string value of the argument, which may be of any type.
 3	If beanshell is running interactively, the output will always go to the 
 4	command line, otherwise it will go to System.out.
 5	<p>
 6
 7	Most often the printed value of an object will simply be the Java 
 8	toString() of the object.  However if the argument is an array the contents 
 9	of the array will be (recursively) listed in a verbose way.
10	<p>
11
12	Note that you are always free to use System.out.println() 
13	instead of print().
14*/
15bsh.help.print = "usage: print( value )";
16import bsh.CollectionManager;
17import bsh.StringUtil;
18import bsh.Primitive;
19
20void print( arg ) 
21{
22	if ( arg == null )
23		arg = "null";
24	
25	if ( !(arg instanceof Primitive) 
26		&& !(arg instanceof bsh.ClassIdentifier ) 
27		&& arg.getClass().isArray() )
28	{
29        print( StringUtil.normalizeClassName(arg.getClass()) + ": {");
30		for(int i=0; i<arg.length; i++)
31			print( arg[i] + (i<arg.length?",":"") );
32		print("}");
33	}
34	else
35		this.interpreter.println(String.valueOf(arg));
36
37/*
38Do we want to iterate over iterable things?
39Most of the them already know how to print themselves.
40
41	this.cm = CollectionManager.getCollectionManager();
42	if ( cm.isBshIterable( arg ) )
43	{
44		// could also just use a for(:) loop here... except for the commas
45		this.iterator = cm.getBshIterator( arg );
46        print( StringUtil.normalizeClassName(arg.getClass()) + ": {");
47		while( iterator.hasNext() )
48			print( iterator.next() + (iterator.hasNext()?",":"") );
49		print("}");
50	}
51*/
52}
53