Java Code Examples for com.google.javascript.rhino.JSDocInfo#getTypeNodes()

The following examples show how to use com.google.javascript.rhino.JSDocInfo#getTypeNodes() . 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: SymbolTable.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Override public void visit(NodeTraversal t, Node n, Node parent) {
  if (n.getJSDocInfo() != null) {

    // Find references in the JSDocInfo.
    JSDocInfo info = n.getJSDocInfo();
    docInfos.add(info);

    for (Node typeAst : info.getTypeNodes()) {
      SymbolScope scope = scopes.get(t.getScopeRoot());
      visitTypeNode(scope == null ? globalScope : scope, typeAst);
    }
  }
}
 
Example 2
Source File: NodeModulePass.java    From js-dossier with Apache License 2.0 5 votes vote down vote up
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
  JSDocInfo info = n.getJSDocInfo();
  if (info != null) {
    for (Node node : info.getTypeNodes()) {
      fixTypeNode(t, node);
    }
  }
}
 
Example 3
Source File: Closure_108_ScopedAliases_s.java    From coming with MIT License 4 votes vote down vote up
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
  if (isCallToScopeMethod(n)) {
    validateScopeCall(t, n, n.getParent());
  }

  if (t.getScopeDepth() < 2) {
    return;
  }

  int type = n.getType();
  Var aliasVar = null;
  if (type == Token.NAME) {
    String name = n.getString();
    Var lexicalVar = t.getScope().getVar(n.getString());
    if (lexicalVar != null && lexicalVar == aliases.get(name)) {
      aliasVar = lexicalVar;
    }
  }

  // Validate the top-level of the goog.scope block.
  if (t.getScopeDepth() == 2) {
    if (aliasVar != null && NodeUtil.isLValue(n)) {
      if (aliasVar.getNode() == n) {
        aliasDefinitionsInOrder.add(n);

        // Return early, to ensure that we don't record a definition
        // twice.
        return;
      } else {
        report(t, n, GOOG_SCOPE_ALIAS_REDEFINED, n.getString());
      }
    }

    if (type == Token.RETURN) {
      report(t, n, GOOG_SCOPE_USES_RETURN);
    } else if (type == Token.THIS) {
      report(t, n, GOOG_SCOPE_REFERENCES_THIS);
    } else if (type == Token.THROW) {
      report(t, n, GOOG_SCOPE_USES_THROW);
    }
  }

  // Validate all descendent scopes of the goog.scope block.
  if (t.getScopeDepth() >= 2) {
    // Check if this name points to an alias.
    if (aliasVar != null) {
      // Note, to support the transitive case, it's important we don't
      // clone aliasedNode here.  For example,
      // var g = goog; var d = g.dom; d.createElement('DIV');
      // The node in aliasedNode (which is "g") will be replaced in the
      // changes pass above with "goog".  If we cloned here, we'd end up
      // with <code>g.dom.createElement('DIV')</code>.
      aliasUsages.add(new AliasedNode(aliasVar, n));
    }

    // When we inject declarations, we duplicate jsdoc. Make sure
    // we only process that jsdoc once.
    JSDocInfo info = n.getJSDocInfo();
    if (info != null) {
      for (Node node : info.getTypeNodes()) {
        fixTypeNode(node);
      }
    }

    // TODO(robbyw): Error for goog.scope not at root.
  }
}
 
Example 4
Source File: Closure_108_ScopedAliases_t.java    From coming with MIT License 4 votes vote down vote up
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
  if (isCallToScopeMethod(n)) {
    validateScopeCall(t, n, n.getParent());
  }

  if (t.getScopeDepth() < 2) {
    return;
  }

  int type = n.getType();
  Var aliasVar = null;
  if (type == Token.NAME) {
    String name = n.getString();
    Var lexicalVar = t.getScope().getVar(n.getString());
    if (lexicalVar != null && lexicalVar == aliases.get(name)) {
      aliasVar = lexicalVar;
    }
  }

  // Validate the top-level of the goog.scope block.
  if (t.getScopeDepth() == 2) {
    if (aliasVar != null && NodeUtil.isLValue(n)) {
      if (aliasVar.getNode() == n) {
        aliasDefinitionsInOrder.add(n);

        // Return early, to ensure that we don't record a definition
        // twice.
        return;
      } else {
        report(t, n, GOOG_SCOPE_ALIAS_REDEFINED, n.getString());
      }
    }

    if (type == Token.RETURN) {
      report(t, n, GOOG_SCOPE_USES_RETURN);
    } else if (type == Token.THIS) {
      report(t, n, GOOG_SCOPE_REFERENCES_THIS);
    } else if (type == Token.THROW) {
      report(t, n, GOOG_SCOPE_USES_THROW);
    }
  }

  // Validate all descendent scopes of the goog.scope block.
  if (t.getScopeDepth() >= 2) {
    // Check if this name points to an alias.
    if (aliasVar != null) {
      // Note, to support the transitive case, it's important we don't
      // clone aliasedNode here.  For example,
      // var g = goog; var d = g.dom; d.createElement('DIV');
      // The node in aliasedNode (which is "g") will be replaced in the
      // changes pass above with "goog".  If we cloned here, we'd end up
      // with <code>g.dom.createElement('DIV')</code>.
      aliasUsages.add(new AliasedNode(aliasVar, n));
    }

    // When we inject declarations, we duplicate jsdoc. Make sure
    // we only process that jsdoc once.
    JSDocInfo info = n.getJSDocInfo();
    if (info != null && !injectedDecls.contains(n)) {
      for (Node node : info.getTypeNodes()) {
        fixTypeNode(node);
      }
    }

    // TODO(robbyw): Error for goog.scope not at root.
  }
}
 
Example 5
Source File: Closure_110_ScopedAliases_s.java    From coming with MIT License 4 votes vote down vote up
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
  if (isCallToScopeMethod(n)) {
    validateScopeCall(t, n, n.getParent());
  }

  if (t.getScopeDepth() < 2) {
    return;
  }

  int type = n.getType();
  Var aliasVar = null;
  if (type == Token.NAME) {
    String name = n.getString();
    Var lexicalVar = t.getScope().getVar(n.getString());
    if (lexicalVar != null && lexicalVar == aliases.get(name)) {
      aliasVar = lexicalVar;
    }
  }

  // Validate the top-level of the goog.scope block.
  if (t.getScopeDepth() == 2) {
    if (aliasVar != null && NodeUtil.isLValue(n)) {
      if (aliasVar.getNode() == n) {
        aliasDefinitionsInOrder.add(n);

        // Return early, to ensure that we don't record a definition
        // twice.
        return;
      } else {
        report(t, n, GOOG_SCOPE_ALIAS_REDEFINED, n.getString());
      }
    }

    if (type == Token.RETURN) {
      report(t, n, GOOG_SCOPE_USES_RETURN);
    } else if (type == Token.THIS) {
      report(t, n, GOOG_SCOPE_REFERENCES_THIS);
    } else if (type == Token.THROW) {
      report(t, n, GOOG_SCOPE_USES_THROW);
    }
  }

  // Validate all descendent scopes of the goog.scope block.
  if (t.getScopeDepth() >= 2) {
    // Check if this name points to an alias.
    if (aliasVar != null) {
      // Note, to support the transitive case, it's important we don't
      // clone aliasedNode here.  For example,
      // var g = goog; var d = g.dom; d.createElement('DIV');
      // The node in aliasedNode (which is "g") will be replaced in the
      // changes pass above with "goog".  If we cloned here, we'd end up
      // with <code>g.dom.createElement('DIV')</code>.
      aliasUsages.add(new AliasedNode(aliasVar, n));
    }

    JSDocInfo info = n.getJSDocInfo();
    if (info != null) {
      for (Node node : info.getTypeNodes()) {
        fixTypeNode(node);
      }
    }

    // TODO(robbyw): Error for goog.scope not at root.
  }
}
 
Example 6
Source File: Closure_110_ScopedAliases_t.java    From coming with MIT License 4 votes vote down vote up
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
  if (isCallToScopeMethod(n)) {
    validateScopeCall(t, n, n.getParent());
  }

  if (t.getScopeDepth() < 2) {
    return;
  }

  int type = n.getType();
  Var aliasVar = null;
  if (type == Token.NAME) {
    String name = n.getString();
    Var lexicalVar = t.getScope().getVar(n.getString());
    if (lexicalVar != null && lexicalVar == aliases.get(name)) {
      aliasVar = lexicalVar;
    }
  }

  // Validate the top-level of the goog.scope block.
  if (t.getScopeDepth() == 2) {
    if (aliasVar != null && NodeUtil.isLValue(n)) {
      if (aliasVar.getNode() == n) {
        aliasDefinitionsInOrder.add(n);

        // Return early, to ensure that we don't record a definition
        // twice.
        return;
      } else {
        report(t, n, GOOG_SCOPE_ALIAS_REDEFINED, n.getString());
      }
    }

    if (type == Token.RETURN) {
      report(t, n, GOOG_SCOPE_USES_RETURN);
    } else if (type == Token.THIS) {
      report(t, n, GOOG_SCOPE_REFERENCES_THIS);
    } else if (type == Token.THROW) {
      report(t, n, GOOG_SCOPE_USES_THROW);
    }
  }

  // Validate all descendent scopes of the goog.scope block.
  if (t.getScopeDepth() >= 2) {
    // Check if this name points to an alias.
    if (aliasVar != null) {
      // Note, to support the transitive case, it's important we don't
      // clone aliasedNode here.  For example,
      // var g = goog; var d = g.dom; d.createElement('DIV');
      // The node in aliasedNode (which is "g") will be replaced in the
      // changes pass above with "goog".  If we cloned here, we'd end up
      // with <code>g.dom.createElement('DIV')</code>.
      aliasUsages.add(new AliasedNode(aliasVar, n));
    }

    JSDocInfo info = n.getJSDocInfo();
    if (info != null) {
      for (Node node : info.getTypeNodes()) {
        fixTypeNode(node);
      }
    }

    // TODO(robbyw): Error for goog.scope not at root.
  }
}
 
Example 7
Source File: Closure_16_ScopedAliases_t.java    From coming with MIT License 4 votes vote down vote up
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
  if (isCallToScopeMethod(n)) {
    validateScopeCall(t, n, n.getParent());
  }

  if (t.getScopeDepth() < 2) {
    return;
  }

  int type = n.getType();
  Var aliasVar = null;
  if (type == Token.NAME) {
    String name = n.getString();
    Var lexicalVar = t.getScope().getVar(n.getString());
    if (lexicalVar != null && lexicalVar == aliases.get(name)) {
      aliasVar = lexicalVar;
    }
  }

  // Validate the top-level of the goog.scope block.
  if (t.getScopeDepth() == 2) {
    if (aliasVar != null && NodeUtil.isLValue(n)) {
      if (aliasVar.getNode() == n) {
        aliasDefinitionsInOrder.add(n);

        // Return early, to ensure that we don't record a definition
        // twice.
        return;
      } else {
        report(t, n, GOOG_SCOPE_ALIAS_REDEFINED, n.getString());
      }
    }

    if (type == Token.RETURN) {
      report(t, n, GOOG_SCOPE_USES_RETURN);
    } else if (type == Token.THIS) {
      report(t, n, GOOG_SCOPE_REFERENCES_THIS);
    } else if (type == Token.THROW) {
      report(t, n, GOOG_SCOPE_USES_THROW);
    }
  }

  // Validate all descendent scopes of the goog.scope block.
  if (t.getScopeDepth() >= 2) {
    // Check if this name points to an alias.
    if (aliasVar != null) {
      // Note, to support the transitive case, it's important we don't
      // clone aliasedNode here.  For example,
      // var g = goog; var d = g.dom; d.createElement('DIV');
      // The node in aliasedNode (which is "g") will be replaced in the
      // changes pass above with "goog".  If we cloned here, we'd end up
      // with <code>g.dom.createElement('DIV')</code>.
      Node aliasedNode = aliasVar.getInitialValue();
      aliasUsages.add(new AliasedNode(n, aliasedNode));
    }

    JSDocInfo info = n.getJSDocInfo();
    if (info != null) {
      for (Node node : info.getTypeNodes()) {
        fixTypeNode(node);
      }
    }

    // TODO(robbyw): Error for goog.scope not at root.
  }
}
 
Example 8
Source File: Closure_16_ScopedAliases_s.java    From coming with MIT License 4 votes vote down vote up
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
  if (isCallToScopeMethod(n)) {
    validateScopeCall(t, n, n.getParent());
  }

  if (t.getScopeDepth() < 2) {
    return;
  }

  int type = n.getType();
  Var aliasVar = null;
  if (type == Token.NAME) {
    String name = n.getString();
    Var lexicalVar = t.getScope().getVar(n.getString());
    if (lexicalVar != null && lexicalVar == aliases.get(name)) {
      aliasVar = lexicalVar;
    }
  }

  // Validate the top-level of the goog.scope block.
  if (t.getScopeDepth() == 2) {
    if (aliasVar != null && NodeUtil.isLValue(n)) {
      if (aliasVar.getNode() == n) {
        aliasDefinitionsInOrder.add(n);

        // Return early, to ensure that we don't record a definition
        // twice.
        return;
      } else {
        report(t, n, GOOG_SCOPE_ALIAS_REDEFINED, n.getString());
      }
    }

    if (type == Token.RETURN) {
      report(t, n, GOOG_SCOPE_USES_RETURN);
    } else if (type == Token.THIS) {
      report(t, n, GOOG_SCOPE_REFERENCES_THIS);
    } else if (type == Token.THROW) {
      report(t, n, GOOG_SCOPE_USES_THROW);
    }
  }

  // Validate all descendent scopes of the goog.scope block.
  if (t.getScopeDepth() >= 2) {
    // Check if this name points to an alias.
    if (aliasVar != null) {
      // Note, to support the transitive case, it's important we don't
      // clone aliasedNode here.  For example,
      // var g = goog; var d = g.dom; d.createElement('DIV');
      // The node in aliasedNode (which is "g") will be replaced in the
      // changes pass above with "goog".  If we cloned here, we'd end up
      // with <code>g.dom.createElement('DIV')</code>.
      Node aliasedNode = aliasVar.getInitialValue();
      aliasUsages.add(new AliasedNode(n, aliasedNode));
    }

    JSDocInfo info = n.getJSDocInfo();
    if (info != null) {
      for (Node node : info.getTypeNodes()) {
        fixTypeNode(node);
      }
    }

    // TODO(robbyw): Error for goog.scope not at root.
  }
}
 
Example 9
Source File: Closure_24_ScopedAliases_t.java    From coming with MIT License 4 votes vote down vote up
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
  if (isCallToScopeMethod(n)) {
    validateScopeCall(t, n, n.getParent());
  }

  if (t.getScopeDepth() < 2) {
    return;
  }

  int type = n.getType();
  Var aliasVar = null;
  if (type == Token.NAME) {
    String name = n.getString();
    Var lexicalVar = t.getScope().getVar(n.getString());
    if (lexicalVar != null && lexicalVar == aliases.get(name)) {
      aliasVar = lexicalVar;
    }
  }

  // Validate the top-level of the goog.scope block.
  if (t.getScopeDepth() == 2) {
    if (aliasVar != null && NodeUtil.isLValue(n)) {
      if (aliasVar.getNode() == n) {
        aliasDefinitionsInOrder.add(n);

        // Return early, to ensure that we don't record a definition
        // twice.
        return;
      } else {
        report(t, n, GOOG_SCOPE_ALIAS_REDEFINED, n.getString());
      }
    }

    if (type == Token.RETURN) {
      report(t, n, GOOG_SCOPE_USES_RETURN);
    } else if (type == Token.THIS) {
      report(t, n, GOOG_SCOPE_REFERENCES_THIS);
    } else if (type == Token.THROW) {
      report(t, n, GOOG_SCOPE_USES_THROW);
    }
  }

  // Validate all descendent scopes of the goog.scope block.
  if (t.getScopeDepth() >= 2) {
    // Check if this name points to an alias.
    if (aliasVar != null) {
      // Note, to support the transitive case, it's important we don't
      // clone aliasedNode here.  For example,
      // var g = goog; var d = g.dom; d.createElement('DIV');
      // The node in aliasedNode (which is "g") will be replaced in the
      // changes pass above with "goog".  If we cloned here, we'd end up
      // with <code>g.dom.createElement('DIV')</code>.
      Node aliasedNode = aliasVar.getInitialValue();
      aliasUsages.add(new AliasedNode(n, aliasedNode));
    }

    JSDocInfo info = n.getJSDocInfo();
    if (info != null) {
      for (Node node : info.getTypeNodes()) {
        fixTypeNode(node);
      }
    }

    // TODO(robbyw): Error for goog.scope not at root.
  }
}
 
Example 10
Source File: Closure_24_ScopedAliases_s.java    From coming with MIT License 4 votes vote down vote up
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
  if (isCallToScopeMethod(n)) {
    validateScopeCall(t, n, n.getParent());
  }

  if (t.getScopeDepth() < 2) {
    return;
  }

  int type = n.getType();
  Var aliasVar = null;
  if (type == Token.NAME) {
    String name = n.getString();
    Var lexicalVar = t.getScope().getVar(n.getString());
    if (lexicalVar != null && lexicalVar == aliases.get(name)) {
      aliasVar = lexicalVar;
    }
  }

  // Validate the top-level of the goog.scope block.
  if (t.getScopeDepth() == 2) {
    if (aliasVar != null && NodeUtil.isLValue(n)) {
      if (aliasVar.getNode() == n) {
        aliasDefinitionsInOrder.add(n);

        // Return early, to ensure that we don't record a definition
        // twice.
        return;
      } else {
        report(t, n, GOOG_SCOPE_ALIAS_REDEFINED, n.getString());
      }
    }

    if (type == Token.RETURN) {
      report(t, n, GOOG_SCOPE_USES_RETURN);
    } else if (type == Token.THIS) {
      report(t, n, GOOG_SCOPE_REFERENCES_THIS);
    } else if (type == Token.THROW) {
      report(t, n, GOOG_SCOPE_USES_THROW);
    }
  }

  // Validate all descendent scopes of the goog.scope block.
  if (t.getScopeDepth() >= 2) {
    // Check if this name points to an alias.
    if (aliasVar != null) {
      // Note, to support the transitive case, it's important we don't
      // clone aliasedNode here.  For example,
      // var g = goog; var d = g.dom; d.createElement('DIV');
      // The node in aliasedNode (which is "g") will be replaced in the
      // changes pass above with "goog".  If we cloned here, we'd end up
      // with <code>g.dom.createElement('DIV')</code>.
      Node aliasedNode = aliasVar.getInitialValue();
      aliasUsages.add(new AliasedNode(n, aliasedNode));
    }

    JSDocInfo info = n.getJSDocInfo();
    if (info != null) {
      for (Node node : info.getTypeNodes()) {
        fixTypeNode(node);
      }
    }

    // TODO(robbyw): Error for goog.scope not at root.
  }
}
 
Example 11
Source File: ScopedAliases.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
  if (isCallToScopeMethod(n)) {
    validateScopeCall(t, n, n.getParent());
  }

  if (t.getScopeDepth() < 2) {
    return;
  }

  int type = n.getType();
  Var aliasVar = null;
  if (type == Token.NAME) {
    String name = n.getString();
    Var lexicalVar = t.getScope().getVar(n.getString());
    if (lexicalVar != null && lexicalVar == aliases.get(name)) {
      aliasVar = lexicalVar;
    }
  }

  // Validate the top-level of the goog.scope block.
  if (t.getScopeDepth() == 2) {
    if (aliasVar != null && NodeUtil.isLValue(n)) {
      if (aliasVar.getNode() == n) {
        aliasDefinitionsInOrder.add(n);

        // Return early, to ensure that we don't record a definition
        // twice.
        return;
      } else {
        report(t, n, GOOG_SCOPE_ALIAS_REDEFINED, n.getString());
      }
    }

    if (type == Token.RETURN) {
      report(t, n, GOOG_SCOPE_USES_RETURN);
    } else if (type == Token.THIS) {
      report(t, n, GOOG_SCOPE_REFERENCES_THIS);
    } else if (type == Token.THROW) {
      report(t, n, GOOG_SCOPE_USES_THROW);
    }
  }

  // Validate all descendent scopes of the goog.scope block.
  if (t.getScopeDepth() >= 2) {
    // Check if this name points to an alias.
    if (aliasVar != null) {
      // Note, to support the transitive case, it's important we don't
      // clone aliasedNode here.  For example,
      // var g = goog; var d = g.dom; d.createElement('DIV');
      // The node in aliasedNode (which is "g") will be replaced in the
      // changes pass above with "goog".  If we cloned here, we'd end up
      // with <code>g.dom.createElement('DIV')</code>.
      Node aliasedNode = aliasVar.getInitialValue();
      aliasUsages.add(new AliasedNode(n, aliasedNode));
    }

    JSDocInfo info = n.getJSDocInfo();
    if (info != null) {
      for (Node node : info.getTypeNodes()) {
        fixTypeNode(node);
      }
    }

    // TODO(robbyw): Error for goog.scope not at root.
  }
}