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


Java NodeUtil.getBestJSDocInfo方法代码示例

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


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

示例1: createTypeAlias

import com.google.javascript.jscomp.NodeUtil; //导入方法依赖的package包/类
private void createTypeAlias(Node n, Node parent) {
  JSDocInfo bestJSDocInfo = NodeUtil.getBestJSDocInfo(n);
  if (bestJSDocInfo != null && bestJSDocInfo.hasTypedefType()) {
    String name;
    switch (n.getToken()) {
      case NAME:
        name = n.getString();
        break;
      case GETPROP:
        // Inner typedef
        name = n.getSecondChild().getString();
        break;
      default:
        name = n.getFirstChild().getString();
        break;
    }
    Node typeDef = Node.newString(Token.TYPE_ALIAS, name);
    types.put(name, typeDef);
    typeDef.setJSDocInfo(bestJSDocInfo);
    replaceExpressionOrAssignment(n, parent, typeDef);
  }
}
 
开发者ID:angular,项目名称:clutz,代码行数:23,代码来源:TypeConversionPass.java

示例2: maybeAddProvidesExport

import com.google.javascript.jscomp.NodeUtil; //导入方法依赖的package包/类
private void maybeAddProvidesExport(Node exportsName) {
  String fullname = exportsName.getQualifiedName();

  if (providesObjectChildren.containsKey(fullname)) {
    googProvideNamespaceToNode.put(fullname, exportsName);
    addExport(fullname, fullname, nameUtil.lastStepOfName(exportsName));

  } else if (exportsName.isGetProp()
      && providesObjectChildren.containsKey(exportsName.getFirstChild().getQualifiedName())) {
    googProvideNamespaceToNode.put(fullname, exportsName);

    // functions declared on functions should be exported.
    // static functions on classes should not be exported.
    String parentName = exportsName.getFirstChild().getQualifiedName();
    @Nullable Node parentNode = googProvideNamespaceToNode.get(parentName);
    JSDocInfo jsDoc = parentNode != null ? NodeUtil.getBestJSDocInfo(parentNode) : null;

    if (providesObjectChildren.containsKey(parentName)
        && (jsDoc == null || !jsDoc.isConstructor())) {
      addExport(fullname, fullname, nameUtil.lastStepOfName(exportsName));
    }
  }
}
 
开发者ID:angular,项目名称:clutz,代码行数:24,代码来源:CollectModuleMetadata.java

示例3: visit

import com.google.javascript.jscomp.NodeUtil; //导入方法依赖的package包/类
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
  JSDocInfo bestJSDocInfo = NodeUtil.getBestJSDocInfo(n);
  if (bestJSDocInfo == null) {
    return;
  }

  // Add visibility for private and protected.
  if (Visibility.PRIVATE.equals(bestJSDocInfo.getVisibility())) {
    n.putProp(Node.ACCESS_MODIFIER, Visibility.PRIVATE);
  } else if (Visibility.PROTECTED.equals(bestJSDocInfo.getVisibility())) {
    n.putProp(Node.ACCESS_MODIFIER, Visibility.PROTECTED);
  }

  // Change variable declarations to constants
  if (bestJSDocInfo.isConstant() && (n.isVar() || n.isLet())) {
    n.setToken(Token.CONST);
  }
}
 
开发者ID:angular,项目名称:clutz,代码行数:20,代码来源:TypeAnnotationPass.java

示例4: getGoogRequiresFromNode

import com.google.javascript.jscomp.NodeUtil; //导入方法依赖的package包/类
private static ImmutableList<String> getGoogRequiresFromNode(
    Pattern pattern, Node beforeTemplate) {
  JSDocInfo jsDoc = NodeUtil.getBestJSDocInfo(beforeTemplate);
  if (jsDoc == null) {
    return ImmutableList.of();
  }
  String jsDocContent = jsDoc.getOriginalCommentString();
  if (jsDocContent == null) {
    return ImmutableList.of();
  }
  ImmutableList.Builder<String> requires = ImmutableList.builder();
  Matcher m = pattern.matcher(jsDocContent);
  while (m.find()) {
    requires.add(m.group(1));
  }
  return requires.build();
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:18,代码来源:RefasterJsScanner.java

示例5: isReturnTypeNullable

import com.google.javascript.jscomp.NodeUtil; //导入方法依赖的package包/类
/**
 * @return True if n is a function node which is explicitly annotated
 * as returning a nullable type, other than {?}.
 */
private static boolean isReturnTypeNullable(Node n) {
  if (n == null || !n.isFunction()) {
    return false;
  }
  FunctionTypeI functionType = n.getTypeI().toMaybeFunctionType();
  if (functionType == null) {
    // If the JSDoc declares a non-function type on a function node, we still shouldn't crash.
    return false;
  }
  TypeI returnType = functionType.getReturnType();
  if (returnType == null
      || returnType.isUnknownType() || !returnType.isNullable()) {
    return false;
  }
  JSDocInfo info = NodeUtil.getBestJSDocInfo(n);
  return info != null && info.hasReturnType();
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:22,代码来源:CheckNullableReturn.java

示例6: visitFunction

import com.google.javascript.jscomp.NodeUtil; //导入方法依赖的package包/类
private void visitFunction(NodeTraversal t, Node function, Node parent) {
  JSDocInfo jsDoc = NodeUtil.getBestJSDocInfo(function);

  if (jsDoc == null && !hasAnyInlineJsDoc(function)) {
    checkMissingJsDoc(t, function);
  } else {
    if (t.inGlobalScope()
        || hasAnyInlineJsDoc(function)
        || !jsDoc.getParameterNames().isEmpty()
        || jsDoc.hasReturnType()) {
      checkParams(t, function, jsDoc);
    }
    checkReturn(t, function, jsDoc);
  }

  if (parent.isMemberFunctionDef()
      && "constructor".equals(parent.getString())
      && jsDoc != null
      && !jsDoc.getVisibility().equals(Visibility.INHERITED)) {
    t.report(function, CONSTRUCTOR_DISALLOWED_JSDOC);
  }
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:23,代码来源:CheckJSDocStyle.java

示例7: visit

import com.google.javascript.jscomp.NodeUtil; //导入方法依赖的package包/类
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
  if (NodeUtil.isPrototypePropertyDeclaration(n)) {
    Node assign = n.getFirstChild();
    Node rhs = assign.getLastChild();
    if (rhs.isArrayLit() || rhs.isObjectLit()) {
      JSDocInfo jsDoc = NodeUtil.getBestJSDocInfo(rhs);
      if (jsDoc != null && jsDoc.hasEnumParameterType()) {
        // Don't report for @enum's on the prototype. Sometimes this is necessary, for example,
        // to expose the enum values to an Angular template.
        return;
      }
      String propName = assign.getFirstChild().getLastChild().getString();
      compiler.report(t.makeError(assign, ILLEGAL_PROTOTYPE_MEMBER, propName));
    }
  }
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:18,代码来源:CheckPrototypeProperties.java

示例8: getProtoPropDeclaredType

import com.google.javascript.jscomp.NodeUtil; //导入方法依赖的package包/类
public JSType getProtoPropDeclaredType(String pname) {
  if (this.protoProps.containsKey(pname)) {
    Property p = this.protoProps.get(pname);
    Node defSite = p.getDefSite();
    if (defSite != null && defSite.isGetProp()) {
      JSDocInfo jsdoc = NodeUtil.getBestJSDocInfo(defSite);
      JSType declType = p.getDeclaredType();
      if (declType != null
          // Methods have a "declared" type which represents their arity,
          // even when they don't have a jsdoc. Don't include that here.
          && (!declType.isFunctionType() || jsdoc != null)) {
        return declType;
      }
    }
  }
  return null;
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:18,代码来源:RawNominalType.java

示例9: replaceRange

import com.google.javascript.jscomp.NodeUtil; //导入方法依赖的package包/类
/**
 * Replaces a range of nodes with the given content.
 */
public Builder replaceRange(Node first, Node last, String newContent) {
  checkState(first.getParent() == last.getParent());

  int start;
  JSDocInfo jsdoc = NodeUtil.getBestJSDocInfo(first);
  if (jsdoc == null) {
    start = first.getSourceOffset();
  } else {
    start = jsdoc.getOriginalCommentPosition();
  }

  int end = last.getSourceOffset() + last.getLength();
  int length = end - start;
  replacements.put(
      first.getSourceFileName(), CodeReplacement.create(start, length, newContent));
  return this;
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:21,代码来源:SuggestedFix.java

示例10: getFixForUnsortedRequiresOrProvides

import com.google.javascript.jscomp.NodeUtil; //导入方法依赖的package包/类
private static SuggestedFix getFixForUnsortedRequiresOrProvides(
    JSError error, AbstractCompiler compiler, String... closureFunctions) {
  SuggestedFix.Builder fix = new SuggestedFix.Builder();
  fix.attachMatchedNodeInfo(error.node, compiler);
  Node script = NodeUtil.getEnclosingScript(error.node);
  RequireProvideSorter cb = new RequireProvideSorter(closureFunctions);
  NodeTraversal.traverseEs6(compiler, script, cb);
  Node first = cb.calls.get(0);
  Node last = Iterables.getLast(cb.calls);

  cb.sortCallsAlphabetically();
  StringBuilder sb = new StringBuilder();
  for (Node n : cb.calls) {
    String statement = fix.generateCode(compiler, n);
    JSDocInfo jsDoc = NodeUtil.getBestJSDocInfo(n);
    if (jsDoc != null) {
      statement = jsDoc.getOriginalCommentString() + "\n" + statement;
    }
    sb.append(statement);
  }
  // Trim to remove the newline after the last goog.require/provide.
  String newContent = sb.toString().trim();
  return fix.replaceRange(first, last, newContent).build();
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:25,代码来源:ErrorToFixMapper.java

示例11: isReturnTypeNullable

import com.google.javascript.jscomp.NodeUtil; //导入方法依赖的package包/类
/**
 * @return True if n is a function node which is explicitly annotated
 * as returning a nullable type, other than {?}.
 */
private static boolean isReturnTypeNullable(Node n) {
  if (n == null) {
    return false;
  }
  if (!n.isFunction()) {
    return false;
  }
  JSType returnType = n.getJSType().toMaybeFunctionType().getReturnType();
  if (returnType == null ||
      returnType.isUnknownType() || !returnType.isNullable()) {
    return false;
  }
  JSDocInfo info = NodeUtil.getBestJSDocInfo(n);
  return info != null && info.hasReturnType();
}
 
开发者ID:nicks,项目名称:closure-compiler-old,代码行数:20,代码来源:CheckNullableReturn.java

示例12: createComponent

import com.google.javascript.jscomp.NodeUtil; //导入方法依赖的package包/类
/**
 * Creates a new component representing the given node object, see
 * {@link Component}.
 */
private Component createComponent(ComponentType componentType, Node n) {
    final Component newCmp = new Component();
    newCmp.setComponentType(componentType);
    newCmp.setSourceFilePath(file.name());
    if (NodeUtil.getBestJSDocInfo(n) != null) {
        String doc = NodeUtil.getBestJSDocInfo(n).getOriginalCommentString();
        if (doc != null) {
            newCmp.setComment(doc);
        }
    }
    return newCmp;
}
 
开发者ID:Zir0-93,项目名称:clarpse,代码行数:17,代码来源:JavaScriptListener.java

示例13: ClassMemberDeclaration

import com.google.javascript.jscomp.NodeUtil; //导入方法依赖的package包/类
private ClassMemberDeclaration(Node n, boolean isStatic, Node classNode, String memberName) {
  this.exprRoot = n;
  this.rhs = getRhs(n);
  this.jsDoc = NodeUtil.getBestJSDocInfo(n);
  this.isStatic = isStatic;
  this.classNode = classNode;
  this.memberName = memberName;
}
 
开发者ID:angular,项目名称:clutz,代码行数:9,代码来源:TypeConversionPass.java

示例14: replacePrefixInName

import com.google.javascript.jscomp.NodeUtil; //导入方法依赖的package包/类
/**
 * In-place replaces a prefix with a new prefix in a name node. Does nothing if prefix does not
 * exist.
 */
void replacePrefixInName(Node name, String prefix, String newPrefix) {
  if (name.matchesQualifiedName(prefix)) {
    Node newName = NodeUtil.newQName(compiler, newPrefix);
    JSDocInfo jsdoc = NodeUtil.getBestJSDocInfo(name);
    newName.setJSDocInfo(jsdoc);
    name.getParent().replaceChild(name, newName);
  } else {
    if (name.isGetProp()) {
      replacePrefixInName(name.getFirstChild(), prefix, newPrefix);
    }
  }
}
 
开发者ID:angular,项目名称:clutz,代码行数:17,代码来源:NameUtil.java

示例15: setParameterTypeFromFunctionDoc

import com.google.javascript.jscomp.NodeUtil; //导入方法依赖的package包/类
/**
 * Attempts to set the type of parameter represented by node by extracting it from @param
 * annotations in the function's jsDoc. Returns true if it succeeds (i.e. if it finds the type).
 */
private boolean setParameterTypeFromFunctionDoc(Node node, Node parent) {
  JSDocInfo parentDocInfo = NodeUtil.getBestJSDocInfo(parent.getParent());
  if (parentDocInfo == null) {
    return false;
  }
  JSTypeExpression parameterType = parentDocInfo.getParameterType(node.getString());
  if (parameterType == null) {
    return false;
  }
  // Parameter is declared using verbose @param syntax before the function definition.
  Node attachTypeExpr = node;
  // Modify the primary AST to represent a function parameter as a
  // REST node, if the type indicates it is a rest parameter.
  if (parameterType.getRoot().getToken() == Token.ELLIPSIS) {
    attachTypeExpr = IR.rest(IR.name(node.getString()));
    nodeComments.replaceWithComment(node, attachTypeExpr);
  }
  // Modify the AST to represent an optional parameter
  if (parameterType.getRoot().getToken() == Token.EQUALS) {
    attachTypeExpr = IR.name(node.getString());
    attachTypeExpr.putBooleanProp(Node.OPT_ES6_TYPED, true);
    nodeComments.replaceWithComment(node, attachTypeExpr);
  }
  setTypeExpression(attachTypeExpr, parameterType, false);
  return true;
}
 
开发者ID:angular,项目名称:clutz,代码行数:31,代码来源:TypeAnnotationPass.java


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