Java Code Examples for com.google.javascript.rhino.Token#SET

The following examples show how to use com.google.javascript.rhino.Token#SET . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Closure_75_NodeUtil_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Gets the function's name. This method recognizes the forms:
 * <ul>
 * <li>{@code &#123;'name': function() ...&#125;}</li>
 * <li>{@code &#123;name: function() ...&#125;}</li>
 * <li>{@code function name() ...}</li>
 * <li>{@code var name = function() ...}</li>
 * <li>{@code qualified.name = function() ...}</li>
 * <li>{@code var name2 = function name1() ...}</li>
 * <li>{@code qualified.name2 = function name1() ...}</li>
 * </ul>
 *
 * @param n a node whose type is {@link Token#FUNCTION}
 * @return the function's name, or {@code null} if it has no name
 */
static String getNearestFunctionName(Node n) {
  String name = getFunctionName(n);
  if (name != null) {
    return name;
  }

  // Check for the form { 'x' : function() { } }
  Node parent = n.getParent();
  switch (parent.getType()) {
    case Token.SET:
    case Token.GET:
    case Token.STRING:
      // Return the name of the literal's key.
      return parent.getString();
    case Token.NUMBER:
      return getStringValue(parent);
  }

  return null;
}
 
Example 2
Source File: Closure_60_NodeUtil_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Gets the function's name. This method recognizes the forms:
 * <ul>
 * <li>{@code &#123;'name': function() ...&#125;}</li>
 * <li>{@code &#123;name: function() ...&#125;}</li>
 * <li>{@code function name() ...}</li>
 * <li>{@code var name = function() ...}</li>
 * <li>{@code qualified.name = function() ...}</li>
 * <li>{@code var name2 = function name1() ...}</li>
 * <li>{@code qualified.name2 = function name1() ...}</li>
 * </ul>
 *
 * @param n a node whose type is {@link Token#FUNCTION}
 * @return the function's name, or {@code null} if it has no name
 */
public static String getNearestFunctionName(Node n) {
  String name = getFunctionName(n);
  if (name != null) {
    return name;
  }

  // Check for the form { 'x' : function() { } }
  Node parent = n.getParent();
  switch (parent.getType()) {
    case Token.SET:
    case Token.GET:
    case Token.STRING:
      // Return the name of the literal's key.
      return parent.getString();
    case Token.NUMBER:
      return getStringValue(parent);
  }

  return null;
}
 
Example 3
Source File: Closure_80_NodeUtil_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Gets the function's name. This method recognizes the forms:
 * <ul>
 * <li>{@code &#123;'name': function() ...&#125;}</li>
 * <li>{@code &#123;name: function() ...&#125;}</li>
 * <li>{@code function name() ...}</li>
 * <li>{@code var name = function() ...}</li>
 * <li>{@code qualified.name = function() ...}</li>
 * <li>{@code var name2 = function name1() ...}</li>
 * <li>{@code qualified.name2 = function name1() ...}</li>
 * </ul>
 *
 * @param n a node whose type is {@link Token#FUNCTION}
 * @return the function's name, or {@code null} if it has no name
 */
static String getNearestFunctionName(Node n) {
  String name = getFunctionName(n);
  if (name != null) {
    return name;
  }

  // Check for the form { 'x' : function() { } }
  Node parent = n.getParent();
  switch (parent.getType()) {
    case Token.SET:
    case Token.GET:
    case Token.STRING:
      // Return the name of the literal's key.
      return parent.getString();
    case Token.NUMBER:
      return getStringValue(parent);
  }

  return null;
}
 
Example 4
Source File: Closure_60_NodeUtil_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Gets the function's name. This method recognizes the forms:
 * <ul>
 * <li>{@code &#123;'name': function() ...&#125;}</li>
 * <li>{@code &#123;name: function() ...&#125;}</li>
 * <li>{@code function name() ...}</li>
 * <li>{@code var name = function() ...}</li>
 * <li>{@code qualified.name = function() ...}</li>
 * <li>{@code var name2 = function name1() ...}</li>
 * <li>{@code qualified.name2 = function name1() ...}</li>
 * </ul>
 *
 * @param n a node whose type is {@link Token#FUNCTION}
 * @return the function's name, or {@code null} if it has no name
 */
public static String getNearestFunctionName(Node n) {
  String name = getFunctionName(n);
  if (name != null) {
    return name;
  }

  // Check for the form { 'x' : function() { } }
  Node parent = n.getParent();
  switch (parent.getType()) {
    case Token.SET:
    case Token.GET:
    case Token.STRING:
      // Return the name of the literal's key.
      return parent.getString();
    case Token.NUMBER:
      return getStringValue(parent);
  }

  return null;
}
 
Example 5
Source File: Closure_61_NodeUtil_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Gets the function's name. This method recognizes the forms:
 * <ul>
 * <li>{@code &#123;'name': function() ...&#125;}</li>
 * <li>{@code &#123;name: function() ...&#125;}</li>
 * <li>{@code function name() ...}</li>
 * <li>{@code var name = function() ...}</li>
 * <li>{@code qualified.name = function() ...}</li>
 * <li>{@code var name2 = function name1() ...}</li>
 * <li>{@code qualified.name2 = function name1() ...}</li>
 * </ul>
 *
 * @param n a node whose type is {@link Token#FUNCTION}
 * @return the function's name, or {@code null} if it has no name
 */
public static String getNearestFunctionName(Node n) {
  String name = getFunctionName(n);
  if (name != null) {
    return name;
  }

  // Check for the form { 'x' : function() { } }
  Node parent = n.getParent();
  switch (parent.getType()) {
    case Token.SET:
    case Token.GET:
    case Token.STRING:
      // Return the name of the literal's key.
      return parent.getString();
    case Token.NUMBER:
      return getStringValue(parent);
  }

  return null;
}
 
Example 6
Source File: Closure_75_NodeUtil_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Get the name of an object literal key.
 *
 * @param key A node
 */
static String getObjectLitKeyName(Node key) {
  switch (key.getType()) {
    case Token.NUMBER:
      return NodeUtil.getStringValue(key);
    case Token.STRING:
    case Token.GET:
    case Token.SET:
      return key.getString();
  }
  throw new IllegalStateException("Unexpected node type: " + key);
}
 
Example 7
Source File: Closure_86_NodeUtil_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Determines whether a node represents an object literal key
 * (e.g. key1 in {key1: value1, key2: value2}).
 *
 * @param node A node
 * @param parent The node's parent
 */
static boolean isObjectLitKey(Node node, Node parent) {
  switch (node.getType()) {
    case Token.NUMBER:
    case Token.STRING:
      return parent.getType() == Token.OBJECTLIT;
    case Token.GET:
    case Token.SET:
      return true;
  }
  return false;
}
 
Example 8
Source File: Closure_86_NodeUtil_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Determines whether a node represents an object literal get or set key
 * (e.g. key1 in {get key1() {}, set key2(a){}).
 *
 * @param node A node
 */
static boolean isGetOrSetKey(Node node) {
  switch (node.getType()) {
    case Token.GET:
    case Token.SET:
      return true;
  }
  return false;
}
 
Example 9
Source File: Closure_86_NodeUtil_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Determines whether a node represents an object literal key
 * (e.g. key1 in {key1: value1, key2: value2}).
 *
 * @param node A node
 * @param parent The node's parent
 */
static boolean isObjectLitKey(Node node, Node parent) {
  switch (node.getType()) {
    case Token.NUMBER:
    case Token.STRING:
      return parent.getType() == Token.OBJECTLIT;
    case Token.GET:
    case Token.SET:
      return true;
  }
  return false;
}
 
Example 10
Source File: Closure_75_NodeUtil_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Determines whether a node represents an object literal key
 * (e.g. key1 in {key1: value1, key2: value2}).
 *
 * @param node A node
 * @param parent The node's parent
 */
static boolean isObjectLitKey(Node node, Node parent) {
  switch (node.getType()) {
    case Token.NUMBER:
    case Token.STRING:
      return parent.getType() == Token.OBJECTLIT;
    case Token.GET:
    case Token.SET:
      return true;
  }
  return false;
}
 
Example 11
Source File: Closure_60_NodeUtil_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Determines whether a node represents an object literal get or set key
 * (e.g. key1 in {get key1() {}, set key2(a){}).
 *
 * @param node A node
 */
static boolean isGetOrSetKey(Node node) {
  switch (node.getType()) {
    case Token.GET:
    case Token.SET:
      return true;
  }
  return false;
}
 
Example 12
Source File: Closure_61_NodeUtil_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Determines whether a node represents an object literal get or set key
 * (e.g. key1 in {get key1() {}, set key2(a){}).
 *
 * @param node A node
 */
static boolean isGetOrSetKey(Node node) {
  switch (node.getType()) {
    case Token.GET:
    case Token.SET:
      return true;
  }
  return false;
}
 
Example 13
Source File: Closure_80_NodeUtil_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Get the name of an object literal key.
 *
 * @param key A node
 */
static String getObjectLitKeyName(Node key) {
  switch (key.getType()) {
    case Token.NUMBER:
      return NodeUtil.getStringValue(key);
    case Token.STRING:
    case Token.GET:
    case Token.SET:
      return key.getString();
  }
  throw new IllegalStateException("Unexpected node type: " + key);
}
 
Example 14
Source File: Closure_75_NodeUtil_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Determines whether a node represents an object literal get or set key
 * (e.g. key1 in {get key1() {}, set key2(a){}).
 *
 * @param node A node
 */
static boolean isGetOrSetKey(Node node) {
  switch (node.getType()) {
    case Token.GET:
    case Token.SET:
      return true;
  }
  return false;
}
 
Example 15
Source File: 1_NodeUtil.java    From SimFix with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the name of an object literal key.
 *
 * @param key A node
 */
static String getObjectLitKeyName(Node key) {
  switch (key.getType()) {
    case Token.NUMBER:
      return NodeUtil.getStringValue(key);
    case Token.STRING:
    case Token.GET:
    case Token.SET:
      return key.getString();
  }
  throw new IllegalStateException("Unexpected node type: " + key);
}
 
Example 16
Source File: Closure_75_NodeUtil_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Determines whether a node represents an object literal key
 * (e.g. key1 in {key1: value1, key2: value2}).
 *
 * @param node A node
 * @param parent The node's parent
 */
static boolean isObjectLitKey(Node node, Node parent) {
  switch (node.getType()) {
    case Token.NUMBER:
    case Token.STRING:
      return parent.getType() == Token.OBJECTLIT;
    case Token.GET:
    case Token.SET:
      return true;
  }
  return false;
}
 
Example 17
Source File: Closure_60_NodeUtil_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Get the name of an object literal key.
 *
 * @param key A node
 */
static String getObjectLitKeyName(Node key) {
  switch (key.getType()) {
    case Token.STRING:
    case Token.GET:
    case Token.SET:
      return key.getString();
  }
  throw new IllegalStateException("Unexpected node type: " + key);
}
 
Example 18
Source File: Closure_60_NodeUtil_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Determines whether a node represents an object literal key
 * (e.g. key1 in {key1: value1, key2: value2}).
 *
 * @param node A node
 * @param parent The node's parent
 */
static boolean isObjectLitKey(Node node, Node parent) {
  switch (node.getType()) {
    case Token.STRING:
      return parent.getType() == Token.OBJECTLIT;
    case Token.GET:
    case Token.SET:
      return true;
  }
  return false;
}
 
Example 19
Source File: Closure_79_Normalize_s.java    From coming with MIT License 5 votes vote down vote up
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
  switch (n.getType()) {
    case Token.WHILE:
      if (CONVERT_WHILE_TO_FOR) {
        Node expr = n.getFirstChild();
        n.setType(Token.FOR);
        Node empty = new Node(Token.EMPTY);
        empty.copyInformationFrom(n);
        n.addChildBefore(empty, expr);
        n.addChildAfter(empty.cloneNode(), expr);
        reportCodeChange("WHILE node");
      }
      break;

    case Token.FUNCTION:
      normalizeFunctionDeclaration(n);
      break;

    case Token.NAME:
    case Token.STRING:
    case Token.GET:
    case Token.SET:
      if (!compiler.getLifeCycleStage().isNormalizedObfuscated()) {
        annotateConstantsByConvention(n, parent);
      }
      break;
  }
}
 
Example 20
Source File: Closure_79_Normalize_t.java    From coming with MIT License 5 votes vote down vote up
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
  switch (n.getType()) {
    case Token.WHILE:
      if (CONVERT_WHILE_TO_FOR) {
        Node expr = n.getFirstChild();
        n.setType(Token.FOR);
        Node empty = new Node(Token.EMPTY);
        empty.copyInformationFrom(n);
        n.addChildBefore(empty, expr);
        n.addChildAfter(empty.cloneNode(), expr);
        reportCodeChange("WHILE node");
      }
      break;

    case Token.FUNCTION:
      normalizeFunctionDeclaration(n);
      break;

    case Token.NAME:
    case Token.STRING:
    case Token.GET:
    case Token.SET:
      if (!compiler.getLifeCycleStage().isNormalizedObfuscated()) {
        annotateConstantsByConvention(n, parent);
      }
      break;
  }
}