< prev index next >

src/jdk.scripting.nashorn.shell/share/classes/jdk/nashorn/tools/jjs/PropertiesHelper.java

Print this page




  37 import jdk.nashorn.internal.runtime.PropertyMap;
  38 import jdk.nashorn.internal.runtime.ScriptObject;
  39 import jdk.nashorn.internal.runtime.ScriptRuntime;
  40 import jdk.nashorn.internal.objects.NativeJava;
  41 
  42 /*
  43  * A helper class to get properties of a given object for source code completion.
  44  */
  45 final class PropertiesHelper {
  46     // Java package properties helper, may be null
  47     private PackagesHelper pkgsHelper;
  48     // cached properties list
  49     private final WeakHashMap<Object, List<String>> propsCache = new WeakHashMap<>();
  50 
  51     /**
  52      * Construct a new PropertiesHelper.
  53      *
  54      * @param classPath Class path to compute properties of java package objects
  55      */
  56     PropertiesHelper(final String classPath) {
  57         if (PackagesHelper.isAvailable()) {
  58             try {
  59                 this.pkgsHelper = new PackagesHelper(classPath);
  60             } catch (final IOException exp) {
  61                 if (Main.DEBUG) {
  62                     exp.printStackTrace();
  63                 }
  64                 this.pkgsHelper = null;
  65             }
  66         }
  67     }
  68 
  69     void close() throws Exception {
  70         propsCache.clear();
  71         pkgsHelper.close();
  72     }
  73 
  74     /**
  75      * returns the list of properties of the given object.
  76      *
  77      * @param obj object whose property list is returned
  78      * @return the list of properties of the given object
  79      */
  80     List<String> getProperties(final Object obj) {
  81         assert obj != null && obj != ScriptRuntime.UNDEFINED;
  82 
  83         // wrap JS primitives as objects before gettting properties
  84         if (JSType.isPrimitive(obj)) {
  85             return getProperties(JSType.toScriptObject(obj));




  37 import jdk.nashorn.internal.runtime.PropertyMap;
  38 import jdk.nashorn.internal.runtime.ScriptObject;
  39 import jdk.nashorn.internal.runtime.ScriptRuntime;
  40 import jdk.nashorn.internal.objects.NativeJava;
  41 
  42 /*
  43  * A helper class to get properties of a given object for source code completion.
  44  */
  45 final class PropertiesHelper {
  46     // Java package properties helper, may be null
  47     private PackagesHelper pkgsHelper;
  48     // cached properties list
  49     private final WeakHashMap<Object, List<String>> propsCache = new WeakHashMap<>();
  50 
  51     /**
  52      * Construct a new PropertiesHelper.
  53      *
  54      * @param classPath Class path to compute properties of java package objects
  55      */
  56     PropertiesHelper(final String classPath) {

  57         try {
  58             this.pkgsHelper = new PackagesHelper(classPath);
  59         } catch (final IOException exp) {
  60             if (Main.DEBUG) {
  61                 exp.printStackTrace();
  62             }
  63             this.pkgsHelper = null;

  64         }
  65     }
  66 
  67     void close() throws Exception {
  68         propsCache.clear();
  69         pkgsHelper.close();
  70     }
  71 
  72     /**
  73      * returns the list of properties of the given object.
  74      *
  75      * @param obj object whose property list is returned
  76      * @return the list of properties of the given object
  77      */
  78     List<String> getProperties(final Object obj) {
  79         assert obj != null && obj != ScriptRuntime.UNDEFINED;
  80 
  81         // wrap JS primitives as objects before gettting properties
  82         if (JSType.isPrimitive(obj)) {
  83             return getProperties(JSType.toScriptObject(obj));


< prev index next >