Java Code Examples for com.google.javascript.rhino.Node#setJSDocInfo()

The following examples show how to use com.google.javascript.rhino.Node#setJSDocInfo() . 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_84_IRFactory_t.java    From coming with MIT License 6 votes vote down vote up
private Node transform(AstNode node) {
  JSDocInfo jsDocInfo = handleJsDoc(node);
  Node irNode = justTransform(node);
  if (jsDocInfo != null) {
    irNode.setJSDocInfo(jsDocInfo);
  }

  // If we have a named function, set the position to that of the name.
  if (irNode.getType() == Token.FUNCTION &&
      irNode.getFirstChild().getLineno() != -1) {
    irNode.setLineno(irNode.getFirstChild().getLineno());
    irNode.setCharno(irNode.getFirstChild().getCharno());
  } else {
    if (irNode.getLineno() == -1) {
      // If we didn't already set the line, then set it now.  This avoids
      // cases like ParenthesizedExpression where we just return a previous
      // node, but don't want the new node to get its parent's line number.
      int lineno = node.getLineno();
      irNode.setLineno(lineno);
      int charno = position2charno(node.getAbsolutePosition());
      irNode.setCharno(charno);
    }
  }
  return irNode;
}
 
Example 2
Source File: Nopol2017_0031_t.java    From coming with MIT License 5 votes vote down vote up
private void addExtern() {
  Node name = IR.name(PROTECTOR_FN);
  name.putBooleanProp(Node.IS_CONSTANT_NAME, true);
  Node var = IR.var(name);
  // Add "@noalias" so we can strip the method when AliasExternals is enabled.
  JSDocInfoBuilder builder = new JSDocInfoBuilder(false);
  builder.recordNoAlias();
  var.setJSDocInfo(builder.build(var));
  CompilerInput input = compiler.getSynthesizedExternsInput();
  input.getAstRoot(compiler).addChildrenToBack(var);
  compiler.reportCodeChange();
}
 
Example 3
Source File: jMutRepair_0023_s.java    From coming with MIT License 5 votes vote down vote up
private void addExtern() {
  Node name = IR.name(PROTECTOR_FN);
  name.putBooleanProp(Node.IS_CONSTANT_NAME, true);
  Node var = IR.var(name);
  // Add "@noalias" so we can strip the method when AliasExternals is enabled.
  JSDocInfoBuilder builder = new JSDocInfoBuilder(false);
  builder.recordNoAlias();
  var.setJSDocInfo(builder.build(var));
  CompilerInput input = compiler.getSynthesizedExternsInput();
  input.getAstRoot(compiler).addChildrenToBack(var);
  compiler.reportCodeChange();
}
 
Example 4
Source File: jKali_006_t.java    From coming with MIT License 5 votes vote down vote up
private void addExtern() {
  Node name = IR.name(PROTECTOR_FN);
  name.putBooleanProp(Node.IS_CONSTANT_NAME, true);
  Node var = IR.var(name);
  // Add "@noalias" so we can strip the method when AliasExternals is enabled.
  JSDocInfoBuilder builder = new JSDocInfoBuilder(false);
  builder.recordNoAlias();
  var.setJSDocInfo(builder.build(var));
  CompilerInput input = compiler.getSynthesizedExternsInput();
  input.getAstRoot(compiler).addChildrenToBack(var);
  compiler.reportCodeChange();
}
 
Example 5
Source File: patch1-Closure-22-Nopol2017_patch1-Closure-22-Nopol2017_t.java    From coming with MIT License 5 votes vote down vote up
private void addExtern() {
  Node name = IR.name(PROTECTOR_FN);
  name.putBooleanProp(Node.IS_CONSTANT_NAME, true);
  Node var = IR.var(name);
  // Add "@noalias" so we can strip the method when AliasExternals is enabled.
  JSDocInfoBuilder builder = new JSDocInfoBuilder(false);
  builder.recordNoAlias();
  var.setJSDocInfo(builder.build(var));
  CompilerInput input = compiler.getSynthesizedExternsInput();
  input.getAstRoot(compiler).addChildrenToBack(var);
  compiler.reportCodeChange();
}
 
Example 6
Source File: Closure_21_CheckSideEffects_t.java    From coming with MIT License 5 votes vote down vote up
private void addExtern() {
  Node name = IR.name(PROTECTOR_FN);
  name.putBooleanProp(Node.IS_CONSTANT_NAME, true);
  Node var = IR.var(name);
  // Add "@noalias" so we can strip the method when AliasExternals is enabled.
  JSDocInfoBuilder builder = new JSDocInfoBuilder(false);
  builder.recordNoAlias();
  var.setJSDocInfo(builder.build(var));
  CompilerInput input = compiler.getSynthesizedExternsInput();
  input.getAstRoot(compiler).addChildrenToBack(var);
  compiler.reportCodeChange();
}
 
Example 7
Source File: Cardumen_00150_s.java    From coming with MIT License 5 votes vote down vote up
private void addExtern() {
  Node name = IR.name(PROTECTOR_FN);
  name.putBooleanProp(Node.IS_CONSTANT_NAME, true);
  Node var = IR.var(name);
  // Add "@noalias" so we can strip the method when AliasExternals is enabled.
  JSDocInfoBuilder builder = new JSDocInfoBuilder(false);
  builder.recordNoAlias();
  var.setJSDocInfo(builder.build(var));
  CompilerInput input = compiler.getSynthesizedExternsInput();
  input.getAstRoot(compiler).addChildrenToBack(var);
  compiler.reportCodeChange();
}
 
Example 8
Source File: Closure_42_IRFactory_s.java    From coming with MIT License 5 votes vote down vote up
private Node transformNumberAsString(NumberLiteral literalNode) {
  Node irNode = newStringNode(getStringValue(literalNode.getNumber()));
  JSDocInfo jsDocInfo = handleJsDoc(literalNode, irNode);
  if (jsDocInfo != null) {
    irNode.setJSDocInfo(jsDocInfo);
  }
  setSourceInfo(irNode, literalNode);
  return irNode;
}
 
Example 9
Source File: Cardumen_0018_t.java    From coming with MIT License 5 votes vote down vote up
private void addExtern() {
  Node name = IR.name(PROTECTOR_FN);
  name.putBooleanProp(Node.IS_CONSTANT_NAME, true);
  Node var = IR.var(name);
  // Add "@noalias" so we can strip the method when AliasExternals is enabled.
  JSDocInfoBuilder builder = new JSDocInfoBuilder(false);
  builder.recordNoAlias();
  var.setJSDocInfo(builder.build(var));
  CompilerInput input = compiler.getSynthesizedExternsInput();
  input.getAstRoot(compiler).addChildrenToBack(var);
  compiler.reportCodeChange();
}
 
Example 10
Source File: Closure_84_IRFactory_s.java    From coming with MIT License 5 votes vote down vote up
private void setFileOverviewJsDoc(Node irNode) {
  // Only after we've seen all @fileoverview entries, attach the
  // last one to the root node, and copy the found license strings
  // to that node.
  irNode.setJSDocInfo(rootNodeJsDocHolder.getJSDocInfo());
  if (fileOverviewInfo != null) {
    if ((irNode.getJSDocInfo() != null) &&
        (irNode.getJSDocInfo().getLicense() != null)) {
      fileOverviewInfo.setLicense(irNode.getJSDocInfo().getLicense());
    }
    irNode.setJSDocInfo(fileOverviewInfo);
  }
}
 
Example 11
Source File: Closure_122_IRFactory_t.java    From coming with MIT License 5 votes vote down vote up
private Node transformNumberAsString(NumberLiteral literalNode) {
  Node irNode = newStringNode(getStringValue(literalNode.getNumber()));
  JSDocInfo jsDocInfo = handleJsDoc(literalNode, irNode);
  if (jsDocInfo != null) {
    irNode.setJSDocInfo(jsDocInfo);
  }
  setSourceInfo(irNode, literalNode);
  return irNode;
}
 
Example 12
Source File: Cardumen_00201_t.java    From coming with MIT License 5 votes vote down vote up
private void addExtern() {
  Node name = IR.name(PROTECTOR_FN);
  name.putBooleanProp(Node.IS_CONSTANT_NAME, true);
  Node var = IR.var(name);
  // Add "@noalias" so we can strip the method when AliasExternals is enabled.
  JSDocInfoBuilder builder = new JSDocInfoBuilder(false);
  builder.recordNoAlias();
  var.setJSDocInfo(builder.build(var));
  CompilerInput input = compiler.getSynthesizedExternsInput();
  input.getAstRoot(compiler).addChildrenToBack(var);
  compiler.reportCodeChange();
}
 
Example 13
Source File: Nopol2017_0031_s.java    From coming with MIT License 5 votes vote down vote up
private void addExtern() {
  Node name = IR.name(PROTECTOR_FN);
  name.putBooleanProp(Node.IS_CONSTANT_NAME, true);
  Node var = IR.var(name);
  // Add "@noalias" so we can strip the method when AliasExternals is enabled.
  JSDocInfoBuilder builder = new JSDocInfoBuilder(false);
  builder.recordNoAlias();
  var.setJSDocInfo(builder.build(var));
  CompilerInput input = compiler.getSynthesizedExternsInput();
  input.getAstRoot(compiler).addChildrenToBack(var);
  compiler.reportCodeChange();
}
 
Example 14
Source File: jKali_005_t.java    From coming with MIT License 5 votes vote down vote up
private void addExtern() {
  Node name = IR.name(PROTECTOR_FN);
  name.putBooleanProp(Node.IS_CONSTANT_NAME, true);
  Node var = IR.var(name);
  // Add "@noalias" so we can strip the method when AliasExternals is enabled.
  JSDocInfoBuilder builder = new JSDocInfoBuilder(false);
  builder.recordNoAlias();
  var.setJSDocInfo(builder.build(var));
  CompilerInput input = compiler.getSynthesizedExternsInput();
  input.getAstRoot(compiler).addChildrenToBack(var);
  compiler.reportCodeChange();
}
 
Example 15
Source File: Cardumen_00248_s.java    From coming with MIT License 5 votes vote down vote up
private void addExtern() {
  Node name = IR.name(PROTECTOR_FN);
  name.putBooleanProp(Node.IS_CONSTANT_NAME, true);
  Node var = IR.var(name);
  // Add "@noalias" so we can strip the method when AliasExternals is enabled.
  JSDocInfoBuilder builder = new JSDocInfoBuilder(false);
  builder.recordNoAlias();
  var.setJSDocInfo(builder.build(var));
  CompilerInput input = compiler.getSynthesizedExternsInput();
  input.getAstRoot(compiler).addChildrenToBack(var);
  compiler.reportCodeChange();
}
 
Example 16
Source File: Closure_122_IRFactory_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Parameter NAMEs are special, because they can have inline type docs
 * attached.
 *
 * function f(/** string */ x) {}
 * annotates 'x' as a string.
 *
 * @see <a href="http://code.google.com/p/jsdoc-toolkit/wiki/InlineDocs">
 *   Using Inline Doc Comments</a>
 */
private Node transformParameter(AstNode node) {
  Node irNode = justTransform(node);
  Comment comment = node.getJsDocNode();
  if (comment != null) {
    JSDocInfo info = parseInlineTypeDoc(comment, irNode);
    if (info != null) {
      irNode.setJSDocInfo(info);
    }
  }
  setSourceInfo(irNode, node);
  return irNode;
}
 
Example 17
Source File: jKali_0048_t.java    From coming with MIT License 5 votes vote down vote up
private void addExtern() {
  Node name = IR.name(PROTECTOR_FN);
  name.putBooleanProp(Node.IS_CONSTANT_NAME, true);
  Node var = IR.var(name);
  // Add "@noalias" so we can strip the method when AliasExternals is enabled.
  JSDocInfoBuilder builder = new JSDocInfoBuilder(false);
  builder.recordNoAlias();
  var.setJSDocInfo(builder.build(var));
  CompilerInput input = compiler.getSynthesizedExternsInput();
  input.getAstRoot(compiler).addChildrenToBack(var);
  compiler.reportCodeChange();
}
 
Example 18
Source File: Closure_37_IRFactory_s.java    From coming with MIT License 5 votes vote down vote up
private Node transformNameAsString(Name node) {
  Node irNode = transformDispatcher.processName(node, true);
  JSDocInfo jsDocInfo = handleJsDoc(node, irNode);
  if (jsDocInfo != null) {
    irNode.setJSDocInfo(jsDocInfo);
  }
  setSourceInfo(irNode, node);
  return irNode;
}
 
Example 19
Source File: Nopol2017_0032_s.java    From coming with MIT License 5 votes vote down vote up
private void addExtern() {
  Node name = IR.name(PROTECTOR_FN);
  name.putBooleanProp(Node.IS_CONSTANT_NAME, true);
  Node var = IR.var(name);
  // Add "@noalias" so we can strip the method when AliasExternals is enabled.
  JSDocInfoBuilder builder = new JSDocInfoBuilder(false);
  builder.recordNoAlias();
  var.setJSDocInfo(builder.build(var));
  CompilerInput input = compiler.getSynthesizedExternsInput();
  input.getAstRoot(compiler).addChildrenToBack(var);
  compiler.reportCodeChange();
}
 
Example 20
Source File: Closure_93_ProcessClosurePrimitives_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * 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();
  }
}