当前位置: 首页>>代码示例>>Java>>正文


Java Token.GETPROP属性代码示例

本文整理汇总了Java中com.google.javascript.rhino.Token.GETPROP属性的典型用法代码示例。如果您正苦于以下问题:Java Token.GETPROP属性的具体用法?Java Token.GETPROP怎么用?Java Token.GETPROP使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在com.google.javascript.rhino.Token的用法示例。


在下文中一共展示了Token.GETPROP属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: visitNew

/**
 * Visits a NEW node.
 */
private void visitNew(NodeTraversal t, Node n) {
  Node constructor = n.getFirstChild();
  FunctionType type = getFunctionType(constructor);
  if (type != null && type.isConstructor()) {
    visitParameterList(t, n, type);
    ensureTyped(t, n, type.getInstanceType());
  } else {
    // TODO(user): add support for namespaced objects.
    if (constructor.getType() != Token.GETPROP) {
      // TODO(user): make the constructor node have lineno/charno
      // and use constructor for a more precise error indication.
      // It seems that GETPROP nodes are missing this information.
      Node line;
      if (constructor.getLineno() < 0 || constructor.getCharno() < 0) {
        line = n;
      } else {
        line = constructor;
      }
      t.report(line, NOT_A_CONSTRUCTOR);
    }
    ensureTyped(t, n);
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:26,代码来源:TypeCheck.java

示例2: mayThrowException

/**
 * Determines if the subtree might throw an exception.
 */
private static boolean mayThrowException(Node n) {
  switch (n.getType()) {
    case Token.CALL:
    case Token.GETPROP:
    case Token.GETELEM:
    case Token.THROW:
    case Token.NEW:
    case Token.ASSIGN:
    case Token.INC:
    case Token.DEC:
    case Token.INSTANCEOF:
      return true;
    case Token.FUNCTION:
      return false;
  }
  for (Node c = n.getFirstChild(); c != null; c = c.getNext()) {
    if (!ControlFlowGraph.isEnteringNewCfgNode(c) && mayThrowException(c)) {
      return true;
    }
  }
  return false;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:25,代码来源:ControlFlowAnalysis.java

示例3: visit

/**
 * {@inheritDoc}
 */
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
  if (n.getType() == Token.STRING &&
      parent.getType() != Token.GETPROP &&
      parent.getType() != Token.REGEXP &&
      !NodeUtil.isObjectLitKey(n, parent)) {
    String s = n.getString();

    for (blacklist.reset(s); blacklist.find();) {
      if (insideGetCssNameCall(n, parent)) {
        continue;
      }
      if (insideGetUniqueIdCall(n, parent)) {
        continue;
      }
      if (insideAssignmentToIdConstant(n, parent)) {
        continue;
      }
      compiler.report(JSError.make(t, n, level, MISSING_GETCSSNAME,
                                   blacklist.group()));
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:26,代码来源:CheckMissingGetCssName.java

示例4: definitionTypeContainsFunctionType

/**
 * Determines if the type of the value of the rhs expression can
 * be a function node.
 */
private static boolean definitionTypeContainsFunctionType(Definition def) {
  Node rhs = def.getRValue();
  if (rhs == null) {
    return true;
  }

  switch (rhs.getType()) {
    case Token.ASSIGN:
    case Token.AND:
    case Token.CALL:
    case Token.GETPROP:
    case Token.GETELEM:
    case Token.FUNCTION:
    case Token.HOOK:
    case Token.NAME:
    case Token.NEW:
    case Token.OR:
      return true;
    default:
      return false;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:26,代码来源:MarkNoSideEffectCalls.java

示例5: canBeSideEffected

/**
 * @param knownConstants A set of names known to be constant value at
 * node 'n' (such as locals that are last written before n can execute).
 * @return Whether the tree can be affected by side-effects or
 * has side-effects.
 */
static boolean canBeSideEffected(Node n, Set<String> knownConstants) {
  switch (n.getType()) {
    case Token.CALL:
    case Token.NEW:
      // Function calls or constructor can reference changed values.
      // TODO(johnlenz): Add some mechanism for determining that functions
      // are unaffected by side effects.
      return true;
    case Token.NAME:
      // Non-constant names values may have been changed.
      return !NodeUtil.isConstantName(n)
          && !knownConstants.contains(n.getString());

    // Properties on constant NAMEs can still be side-effected.
    case Token.GETPROP:
    case Token.GETELEM:
      return true;
  }

  for (Node c = n.getFirstChild(); c != null; c = c.getNext()) {
    if (canBeSideEffected(c, knownConstants)) {
      return true;
    }
  }

  return false;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:33,代码来源:NodeUtil.java

示例6: isMethodCallThatTriggersRemoval

/**
 * Gets whether a CALL node triggers statement removal, based on the name
 * of the object whose method is being called, or the name of the method.
 * Checks whether the name begins with a strip type, ends with a field name
 * that's a strip name, or belongs to the set of global class-defining
 * functions (e.g. goog.inherits).
 *
 * @param t The traversal
 * @param n A CALL node
 * @return Whether the node triggers statement removal
 */
boolean isMethodCallThatTriggersRemoval(NodeTraversal t, Node n,
                                        Node parent) {
  // CALL
  //   GETPROP (function)         <-- we're interested in this, the function
  //     GETPROP (callee object)  <-- or the object on which it is called
  //       ...
  //       STRING (field name)
  //     STRING (method name)
  //   ... (arguments)

  Node function = n.getFirstChild();
  if (function == null || function.getType() != Token.GETPROP) {
    // We are only interested in calls on object references that are
    // properties. We don't need to eliminate method calls on variables
    // that are getting removed, since that's already done by the code
    // that removes all references to those variables.
    return false;
  }

  if (parent != null && parent.getType() == Token.NAME) {
    Node gramps = parent.getParent();
    if (gramps != null && gramps.getType() == Token.VAR) {
      // The call's return value is being used to initialize a newly
      // declared variable. We should leave the call intact for now.
      // That way, when the traversal reaches the variable declaration,
      // we'll recognize that the variable and all references to it need
      // to be eliminated.
      return false;
    }
  }

  Node callee = function.getFirstChild();
  return nameEndsWithFieldNameToStrip(callee) ||
      nameEndsWithFieldNameToStrip(function) ||
      qualifiedNameBeginsWithStripType(callee) ||
      actsOnStripType(t, n);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:48,代码来源:StripCode.java

示例7: getImplicitActions

/**
 * Returns any actions that are implicit in the given code.  This can return
 * null instead of an empty collection if none are found.
 */
private Collection<Action> getImplicitActions(Node n) {
  switch (n.getType()) {
    case Token.CALL:
      // Functions passed to externs functions are considered called.
      // E.g. window.setTimeout(callback, 100);
      // TODO(user): support global extern function calls if necessary
      // TODO(user): handle addEventListener for the case of an object
      //     implementing the EventListener interface.
      Node receiver = n.getFirstChild();
      if (!inExterns && receiver.getType() == Token.GETPROP) {
        return getImplicitActionsFromCall(n, receiver.getJSType());
      }
      break;

    case Token.ASSIGN:
      Node lhs = n.getFirstChild();
      // Functions assigned to externs properties are considered called.
      // E.g. element.onclick = function handle(evt) {};
      if (!inExterns && lhs.getType() == Token.GETPROP) {
        return getImplicitActionsFromProp(lhs.getFirstChild().getJSType(),
            lhs.getLastChild().getString(), n.getLastChild());
      }
      break;
  }
  return null;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:30,代码来源:TightenTypes.java

示例8: processPropertyGet

@Override
Node processPropertyGet(PropertyGet getNode) {
  return new Node(
      Token.GETPROP,
      transform(getNode.getTarget()),
      transformAsString(getNode.getProperty()));
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:7,代码来源:IRFactory.java

示例9: getPrototypePropertyOwner

/**
 * Given a node, determines whether that node names a prototype
 * property, and if so, returns the qualfied name node representing
 * the owner of that property. Otherwise, returns null.
 */
private static Node getPrototypePropertyOwner(Node n) {
  if (n.getType() == Token.GETPROP) {
    Node firstChild = n.getFirstChild();
    if (firstChild.getType() == Token.GETPROP &&
        firstChild.getLastChild().getString().equals("prototype")) {
      Node maybeOwner = firstChild.getFirstChild();
      if (maybeOwner.isQualifiedName()) {
        return maybeOwner;
      }
    }
  }
  return null;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:18,代码来源:TypedScopeCreator.java

示例10: processPrototypeParent

/**
 * Processes the parent of a GETPROP prototype, which can either be
 * another GETPROP (in the case of Foo.prototype.bar), or can be
 * an assignment (in the case of Foo.prototype = ...).
 */
private void processPrototypeParent(NodeTraversal t, Node n) {
  switch (n.getType()) {
    // Foo.prototype.getBar = function() { ... } or
    // Foo.prototype.getBar = getBaz (where getBaz is a function)
    // parse tree looks like:
    // assign                          <- parent
    //     getprop                     <- n
    //         getprop
    //             name Foo
    //             string prototype
    //         string getBar
    //     function or name            <- assignee
    case Token.GETPROP:
    case Token.GETELEM:
      Node dest = n.getFirstChild().getNext();
      Node parent = n.getParent().getParent();

      if (dest.getType() == Token.STRING &&
          parent.getType() == Token.ASSIGN) {
        Node assignee = parent.getFirstChild().getNext();

        addPossibleSignature(dest.getString(), assignee, t);
      }
      break;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:31,代码来源:MethodCompilerPass.java

示例11: visit

public void visit(NodeTraversal t, Node n, Node parent) {
  switch (n.getType()) {
    case Token.GETPROP:
    case Token.GETELEM:
      Node dest = n.getFirstChild().getNext();

      if (dest.getType() == Token.STRING) {
        if (dest.getString().equals("prototype")) {
          processPrototypeParent(t, parent);
        } else {
          // Static methods of the form Foo.bar = function() {} or
          // Static methods of the form Foo.bar = baz (where baz is a
          // function name). Parse tree looks like:
          // assign                 <- parent
          //      getprop           <- n
          //          name Foo
          //          string bar
          //      function or name  <- n.getNext()
          if (parent.getType() == Token.ASSIGN &&
              parent.getFirstChild() == n) {
            addPossibleSignature(dest.getString(), n.getNext(), t);
          }
        }
      }
      break;

    case Token.OBJECTLIT:
      // assumes the object literal is well formed
      // (has an even number of children)
      for (Node key = n.getFirstChild();
           key != null; key = key.getNext().getNext()) {
        if (key.getType() == Token.STRING) {
          Node value = key.getNext();
          addPossibleSignature(key.getString(), value, t);
        }
      }
      break;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:39,代码来源:MethodCompilerPass.java

示例12: visit

@Override
public void visit(NodeTraversal t, Node n, Node parent) {
  // Annotate with the source file.
  if (sourceFile != null) {
    n.putProp(Node.SOURCEFILE_PROP, sourceFile);
  }

  // Annotate the original name.
  switch (n.getType()) {
    case Token.GETPROP:
      Node propNode = n.getFirstChild().getNext();
      if (propNode.getType() == Token.STRING) {
        n.putProp(Node.ORIGINALNAME_PROP, propNode.getString());
      }

      break;

    case Token.NAME:
      n.putProp(Node.ORIGINALNAME_PROP, n.getString());
      break;

    case Token.OBJECTLIT:
       for (Node key = n.getFirstChild(); key != null;
            key = key.getNext().getNext()) {
         // We only want keys that are strings (not numbers), and only keys
         // that were unquoted.
         if (key.getType() == Token.STRING) {
           if (!key.isQuotedString()) {
             key.putProp(Node.ORIGINALNAME_PROP, key.getString());
           }
         }
       }
      break;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:35,代码来源:SourceInformationAnnotator.java

示例13: checkForTypedef

/**
 * Handle typedefs.
 * @param t The current traversal.
 * @param candidate A qualified name node.
 * @param info JSDoc comments.
 */
private void checkForTypedef(
    NodeTraversal t, Node candidate, JSDocInfo info) {
  if (info == null || !info.hasTypedefType()) {
    return;
  }

  String typedef = candidate.getQualifiedName();
  if (typedef == null) {
    return;
  }

  // TODO(nicksantos|user): This is a terrible, terrible hack
  // to bail out on recusive typedefs. We'll eventually need
  // to handle these properly.
  typeRegistry.forwardDeclareType(typedef);

  JSType realType = info.getTypedefType().evaluate(scope);
  if (realType == null) {
    compiler.report(
        JSError.make(
            t.getSourceName(), candidate, MALFORMED_TYPEDEF, typedef));
  }

  typeRegistry.declareType(typedef, realType);
  if (candidate.getType() == Token.GETPROP) {
    defineSlot(candidate, candidate.getParent(),
        typeRegistry.getNativeType(NO_TYPE), false);
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:35,代码来源:TypedScopeCreator.java

示例14: visit

public void visit(NodeTraversal t, Node n, Node parent) {
  switch (n.getType()) {
    case Token.GETPROP:
    case Token.GETELEM:
      Node dest = n.getFirstChild().getNext();
      if (dest.getType() == Token.STRING) {
        externPropertyNames.add(dest.getString());
      }
      break;
    case Token.OBJECTLIT:
      for (Node child = n.getFirstChild();
           child != null;
           child = child.getNext()) {
        if (child.getType() == Token.STRING) {
          externPropertyNames.add(child.getString());
        }
      }
      break;
    case Token.NAME:
      // Treat global extern vars and funcs as extern properties,
      // because they are sometimes used as properties of window objects.
      String name = n.getString();

      // Avoid anonymous functions
      if (name.length() > 0) {
        // Only count globals
        Scope.Var var = t.getScope().getVar(name);
        if (var != null && !var.isLocal()) {
          externPropertyNames.add(name);
        }
      }
      break;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:34,代码来源:SuspiciousPropertiesCheck.java

示例15: createAssignmentActions

/**
 * Returns an action for assigning the right-hand-side to the left or null
 * if this assignment should be ignored.
 */
private List<Action> createAssignmentActions(
    Node lhs, Node rhs, Node parent) {
  switch (lhs.getType()) {
    case Token.NAME:
      ConcreteSlot var = (ConcreteSlot) scope.getSlot(lhs.getString());
      Preconditions.checkState(var != null,
          "Type tightener could not find variable with name %s",
          lhs.getString());
      return Lists.<Action>newArrayList(
          new VariableAssignAction(var, rhs));

    case Token.GETPROP:
      Node receiver = lhs.getFirstChild();
      return Lists.<Action>newArrayList(
          new PropertyAssignAction(receiver, rhs));

    case Token.GETELEM:
      return Lists.newArrayList();

    case Token.GET_REF:
      // We ignore ref specials as their types should not be computed.
      if (lhs.getFirstChild().getType() == Token.REF_SPECIAL) {
        return Lists.newArrayList();
      } else {
        throw new AssertionError(
            "Bad LHS for getref: " + parent.toStringTree());
      }

    default:
      throw new AssertionError(
          "Bad LHS for assignment: " + parent.toStringTree());
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:37,代码来源:TightenTypes.java


注:本文中的com.google.javascript.rhino.Token.GETPROP属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。