Class RhinoUtil


  • public class RhinoUtil
    extends java.lang.Object
    Utility methods for walking ASTs from Rhino.
    Version:
    1.0
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private RhinoUtil()
      Private constructor to prevent instantiation.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String getFunctionArgsString​(org.mozilla.javascript.ast.FunctionNode fn)
      Iterates through a function's parameters and returns a string representation of them, suitable for presentation as part of the method's signature.
      static java.lang.String getPropertyName​(org.mozilla.javascript.ast.AstNode propKeyNode)
      Property keys in object literals can be identifiers or string literals.
      static java.lang.String getPrototypeClazz​(java.util.List<org.mozilla.javascript.ast.AstNode> nodes)  
      static java.lang.String getPrototypeClazz​(java.util.List<org.mozilla.javascript.ast.AstNode> nodes, int depth)  
      private static boolean isName​(org.mozilla.javascript.ast.AstNode node, java.lang.String value)
      Returns whether an AST node is a Name with the specified value.
      static boolean isPrototypeNameNode​(org.mozilla.javascript.ast.AstNode node)  
      static boolean isPrototypePropertyGet​(org.mozilla.javascript.ast.PropertyGet pg)  
      static boolean isSimplePropertyGet​(org.mozilla.javascript.ast.PropertyGet pg, java.lang.String expectedObj, java.lang.String expectedField)
      Returns whether a PropertyGet is a simple one, referencing an object's value 1 level deep.
      static java.util.List<org.mozilla.javascript.ast.AstNode> toList​(org.mozilla.javascript.ast.AstNode... nodes)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • RhinoUtil

        private RhinoUtil()
        Private constructor to prevent instantiation.
    • Method Detail

      • getFunctionArgsString

        public static java.lang.String getFunctionArgsString​(org.mozilla.javascript.ast.FunctionNode fn)
        Iterates through a function's parameters and returns a string representation of them, suitable for presentation as part of the method's signature.
        Parameters:
        fn - The function node.
        Returns:
        The string representation of the function's arguments.
      • getPropertyName

        public static java.lang.String getPropertyName​(org.mozilla.javascript.ast.AstNode propKeyNode)
        Property keys in object literals can be identifiers or string literals. This method takes an AST node that was the key of an ObjectProperty and returns its value, no matter what the concrete AST node's type.
        Parameters:
        propKeyNode - The AST node for the property key.
        Returns:
        The property key's value.
      • getPrototypeClazz

        public static java.lang.String getPrototypeClazz​(java.util.List<org.mozilla.javascript.ast.AstNode> nodes)
      • getPrototypeClazz

        public static java.lang.String getPrototypeClazz​(java.util.List<org.mozilla.javascript.ast.AstNode> nodes,
                                                         int depth)
      • isName

        private static boolean isName​(org.mozilla.javascript.ast.AstNode node,
                                      java.lang.String value)
        Returns whether an AST node is a Name with the specified value.
        Parameters:
        node - The AST node.
        value - The expected value.
        Returns:
        Whether the AST node is a Name with the specified value.
      • isPrototypeNameNode

        public static boolean isPrototypeNameNode​(org.mozilla.javascript.ast.AstNode node)
      • isPrototypePropertyGet

        public static boolean isPrototypePropertyGet​(org.mozilla.javascript.ast.PropertyGet pg)
      • isSimplePropertyGet

        public static boolean isSimplePropertyGet​(org.mozilla.javascript.ast.PropertyGet pg,
                                                  java.lang.String expectedObj,
                                                  java.lang.String expectedField)
        Returns whether a PropertyGet is a simple one, referencing an object's value 1 level deep. For example, Object.create.
        Parameters:
        pg - The PropertyGet.
        expectedObj - The expected object value.
        expectedField - The expected string value.
        Returns:
        Whether the object is what was expected.
      • toList

        public static java.util.List<org.mozilla.javascript.ast.AstNode> toList​(org.mozilla.javascript.ast.AstNode... nodes)