PageRenderTime 41ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-5-pre1/org/gjt/sp/jedit/bsh/commands/print.bsh

#
Unknown | 53 lines | 46 code | 7 blank | 0 comment | 0 complexity | 51054b84e44bd33746400d4bc081d339 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  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. Most often the printed value of an object will simply be the Java
  7. toString() of the object. However if the argument is an array the contents
  8. of the array will be (recursively) listed in a verbose way.
  9. <p>
  10. Note that you are always free to use System.out.println()
  11. instead of print().
  12. */
  13. bsh.help.print = "usage: print( value )";
  14. import org.gjt.sp.jedit.bsh.CollectionManager;
  15. import org.gjt.sp.jedit.bsh.StringUtil;
  16. import org.gjt.sp.jedit.bsh.Primitive;
  17. void print( arg )
  18. {
  19. if ( arg == null )
  20. arg = "null";
  21. if ( !(arg instanceof Primitive)
  22. && !(arg instanceof bsh.ClassIdentifier )
  23. && arg.getClass().isArray() )
  24. {
  25. print( StringUtil.normalizeClassName(arg.getClass()) + ": {");
  26. for(int i=0; i<arg.length; i++)
  27. print( arg[i] + (i<arg.length?",":"") );
  28. print("}");
  29. }
  30. else
  31. this.interpreter.println(String.valueOf(arg));
  32. /*
  33. Do we want to iterate over iterable things?
  34. Most of the them already know how to print themselves.
  35. this.cm = CollectionManager.getCollectionManager();
  36. if ( cm.isBshIterable( arg ) )
  37. {
  38. // could also just use a for(:) loop here... except for the commas
  39. this.iterator = cm.getBshIterator( arg );
  40. print( StringUtil.normalizeClassName(arg.getClass()) + ": {");
  41. while( iterator.hasNext() )
  42. print( iterator.next() + (iterator.hasNext()?",":"") );
  43. print("}");
  44. }
  45. */
  46. }