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


Java Node.copyInformationFrom方法代码示例

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


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

示例1: visit

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
public void visit(NodeTraversal t, Node n, Node parent) {
  if (OBJECT_PROPERTY_STRING.equals(n.getQualifiedName())) {
    Node newName =
        Node.newString(Token.NAME, EXTERN_OBJECT_PROPERTY_STRING);
    newName.copyInformationFrom(n);
    parent.replaceChild(n, newName);
    compiler.reportCodeChange();
    return;
  }

  // Rewrite "new goog.testing.ObjectPropertyString(foo, 'bar')" to
  // "new goog.testing.ObjectPropertyString(window, foo.bar)" and
  // issues errors if bad arguments are encountered.
  if (n.getType() != Token.NEW) {
    return;
  }

  Node objectName = n.getFirstChild();

  if (!EXTERN_OBJECT_PROPERTY_STRING.equals(
          objectName.getQualifiedName())) {
    return;
  }

  if (n.getChildCount() != 3) {
    compiler.report(JSError.make(t, n, INVALID_NUM_ARGUMENTS_ERROR,
        "" + n.getChildCount()));
    return;
  }

  Node firstArgument = objectName.getNext();
  if (!firstArgument.isQualifiedName()) {
    compiler.report(JSError.make(t, firstArgument,
        QUALIFIED_NAME_EXPECTED_ERROR,
        Token.name(firstArgument.getType())));
    return;
  }

  Node secondArgument = firstArgument.getNext();
  if (secondArgument.getType() != Token.STRING) {
    compiler.report(JSError.make(t, secondArgument,
        STRING_LITERAL_EXPECTED_ERROR,
        Token.name(secondArgument.getType())));
    return;
  }

  Node newFirstArgument = NodeUtil.newQualifiedNameNode(
      compiler.getCodingConvention().getGlobalObject(),
      firstArgument.getLineno(), firstArgument.getCharno());
  Node newSecondArgument = NodeUtil.newQualifiedNameNode(
      firstArgument.getQualifiedName() + "." +
      firstArgument.getNext().getString(),
      secondArgument.getLineno(), secondArgument.getCharno());
  n.replaceChild(firstArgument, newFirstArgument);
  n.replaceChild(secondArgument, newSecondArgument);

  compiler.reportCodeChange();
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:59,代码来源:ObjectPropertyStringPreprocess.java

示例2: replace

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Replace the provide statement.
 *
 * If we're providing a name with no definition, then create one.
 * If we're providing a name with a duplicate definition, then make sure
 * that definition becomes a declaration.
 */
void replace() {
  if (firstNode == null) {
    // Don't touch the base case ('goog').
    replacementNode = candidateDefinition;
    return;
  }

  // Handle the case where there is a duplicate definition for an explicitly
  // provided symbol.
  if (candidateDefinition != null && explicitNode != null) {
    explicitNode.detachFromParent();
    compiler.reportCodeChange();

    // Does this need a VAR keyword?
    replacementNode = candidateDefinition;
    if (NodeUtil.isExpressionNode(candidateDefinition)) {
      candidateDefinition.putBooleanProp(Node.IS_NAMESPACE, true);
      Node assignNode = candidateDefinition.getFirstChild();
      Node nameNode = assignNode.getFirstChild();
      if (nameNode.getType() == Token.NAME) {
        // Need to convert this assign to a var declaration.
        Node valueNode = nameNode.getNext();
        assignNode.removeChild(nameNode);
        assignNode.removeChild(valueNode);
        nameNode.addChildToFront(valueNode);
        Node varNode = new Node(Token.VAR, nameNode);
        varNode.copyInformationFrom(candidateDefinition);
        candidateDefinition.getParent().replaceChild(
            candidateDefinition, varNode);
        nameNode.setJSDocInfo(assignNode.getJSDocInfo());
        compiler.reportCodeChange();
        replacementNode = varNode;
      }
    }
  } else {
    // Handle the case where there's not a duplicate definition.
    replacementNode = createDeclarationNode();
    if (firstModule == minimumModule) {
      firstNode.getParent().addChildBefore(replacementNode, firstNode);
    } else {
      // In this case, the name was implicitly provided by two independent
      // modules. We need to move this code up to a common module.
      int indexOfDot = namespace.indexOf('.');
      if (indexOfDot == -1) {
        // Any old place is fine.
        compiler.getNodeForCodeInsertion(minimumModule)
            .addChildToBack(replacementNode);
      } else {
        // Add it after the parent namespace.
        ProvidedName parentName =
            providedNames.get(namespace.substring(0, indexOfDot));
        Preconditions.checkNotNull(parentName);
        Preconditions.checkNotNull(parentName.replacementNode);
        parentName.replacementNode.getParent().addChildAfter(
            replacementNode, parentName.replacementNode);
      }
    }
    if (explicitNode != null) {
      explicitNode.detachFromParent();
    }
    compiler.reportCodeChange();
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:71,代码来源:ProcessClosurePrimitives.java

示例3: newName

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Creates a new node representing an *existing* name, copying over the source
 * location information from the basis node.
 *
 * @param name The name for the new NAME node.
 * @param basisNode The node that represents the name as currently found in
 *     the AST.
 *
 * @return The node created.
 */
static Node newName(String name, Node basisNode) {
  Node nameNode = Node.newString(Token.NAME, name);
  nameNode.copyInformationFrom(basisNode);
  return nameNode;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:16,代码来源:NodeUtil.java


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