• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java NodeTraversal类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: compileFiles

import com.google.javascript.jscomp.NodeTraversal; //导入依赖的package包/类
@SuppressWarnings("deprecation")
private OOPSourceCodeModel compileFiles(List<RawFile> files, List<String> projectFileTypes) {
    OOPSourceCodeModel model = new OOPSourceCodeModel();
    for (RawFile file : files) {
        try {
            Compiler compiler = new Compiler();
            CompilerOptions options = new CompilerOptions();
            options.setIdeMode(true);
            options.setParseJsDocDocumentation(JsDocParsing.INCLUDE_DESCRIPTIONS_WITH_WHITESPACE);
            compiler.initOptions(options);
            Node root = new JsAst(SourceFile.fromCode(file.name(), file.content())).getAstRoot(compiler);
            JavaScriptListener jsListener = new JavaScriptListener(model, file, projectFileTypes);
            NodeTraversal.traverseEs6(compiler, root, jsListener);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return model;
}
 
开发者ID:Zir0-93,项目名称:clarpse,代码行数:20,代码来源:ClarpseJSCompiler.java


示例2: process

import com.google.javascript.jscomp.NodeTraversal; //导入依赖的package包/类
@Override
public void process(Node externs, Node root) {
  this.typesToRename = new LinkedHashMap<>();
  this.typesToFilename = new LinkedHashMap<>();
  for (Node child : root.children()) {
    // We convert each file independently to avoid merging class methods from different files.
    if (child.isScript()) {
      this.types = new LinkedHashMap<>();
      NodeTraversal.traverseEs6(compiler, child, new TypeConverter());
      NodeTraversal.traverseEs6(compiler, child, new TypeMemberConverter());
      NodeTraversal.traverseEs6(compiler, child, new FieldOnThisConverter());
      NodeTraversal.traverseEs6(compiler, child, new InheritanceConverter());
      NodeTraversal.traverseEs6(compiler, child, new EnumConverter());
    }
  }
  convertTypeAlias();
}
 
开发者ID:angular,项目名称:clutz,代码行数:18,代码来源:TypeConversionPass.java


示例3: visit

import com.google.javascript.jscomp.NodeTraversal; //导入依赖的package包/类
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
  switch (n.getToken()) {
    case CLASS:
      addClassToScope(n);
      break;
    case EXPR_RESULT:
      ClassMemberDeclaration declaration = ClassMemberDeclaration.newDeclaration(n, types);
      if (declaration == null) {
        break;
      }
      if (declaration.rhs != null && declaration.rhs.isFunction()) {
        moveMethodsIntoClasses(declaration);
      } else {
        // Ignore field declarations without a type annotation
        if (declaration.jsDoc != null && declaration.jsDoc.getType() != null) {
          moveFieldsIntoClasses(declaration);
        }
      }
      break;
    default:
      break;
  }
}
 
开发者ID:angular,项目名称:clutz,代码行数:25,代码来源:TypeConversionPass.java


示例4: visit

import com.google.javascript.jscomp.NodeTraversal; //导入依赖的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


示例5: visit

import com.google.javascript.jscomp.NodeTraversal; //导入依赖的package包/类
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
  if (isDone()) {
    return;
  }
  if (n.isScript()) {
    // New dummy node at the end of the file
    Node dummy = new Node(Token.EMPTY);
    n.addChildToBack(dummy);

    while (hasRemainingComments()) {
      // If the new comment is separated from the current one by at least a line,
      // output the current group of comments.
      if (getFirstLineOfNextComment() - getLastLineOfCurrentComment() > 1) {
        dummy.getParent().addChildBefore(newFloatingCommentFromBuffer(), dummy);
      }
      addNextCommentToBuffer();
    }
    n.addChildBefore(newFloatingCommentFromBuffer(), dummy);
    addNextCommentToBuffer();
    n.removeChild(dummy);
  }
}
 
开发者ID:angular,项目名称:clutz,代码行数:24,代码来源:CommentLinkingPass.java


示例6: shouldTraverse

import com.google.javascript.jscomp.NodeTraversal; //导入依赖的package包/类
@Override
public boolean shouldTraverse(NodeTraversal t, Node n, Node parent) {
  // Rewrite all imported variable name usages
  if (n.isName() || n.isGetProp()) {
    if (!valueRewrite.containsRow(n.getSourceFileName())) {
      return true;
    }

    Map<String, String> rewriteMap = valueRewrite.rowMap().get(n.getSourceFileName());
    String importedNamespace = nameUtil.findLongestNamePrefix(n, rewriteMap.keySet());
    if (importedNamespace != null) {
      nameUtil.replacePrefixInName(n, importedNamespace, rewriteMap.get(importedNamespace));
      return false;
    }
  }
  return true;
}
 
开发者ID:angular,项目名称:clutz,代码行数:18,代码来源:ModuleConversionPass.java


示例7: visit

import com.google.javascript.jscomp.NodeTraversal; //导入依赖的package包/类
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
  Node maybeCallNode = n.getFirstChild();
  if (maybeCallNode == null || !maybeCallNode.isCall()) {
    return;
  }

  String callName = maybeCallNode.getFirstChild().getQualifiedName();
  if (callName == null) {
    return;
  }

  switch (callName) {
    case "goog.provide":
    case "goog.require":
      // Register the goog.provide/require namespaces, so that we can remove any aliases.
      providedNamespaces.add(maybeCallNode.getLastChild().getString());
      return;
    case "goog.scope":
      rewriteGoogScope(n);
      return;
    default:
      return;
  }
}
 
开发者ID:angular,项目名称:clutz,代码行数:26,代码来源:RemoveGoogScopePass.java


示例8: hotSwapScript

import com.google.javascript.jscomp.NodeTraversal; //导入依赖的package包/类
@Override
public void hotSwapScript(Node scriptRoot, Node originalRoot) {
  NodeTraversal.traverseEs6(compiler, scriptRoot, this);
  // Inline React.createMixin calls, since they're just decorators.
  for (Node mixinSpecNode : reactMixinsByName.values()) {
    Node mixinSpecParentNode = mixinSpecNode.getParent();
    if (mixinSpecParentNode.isCall() &&
        mixinSpecParentNode.hasMoreThanOneChild() &&
        mixinSpecParentNode.getFirstChild().getQualifiedName().equals(
          "React.createMixin")) {
      mixinSpecNode.detachFromParent();
      mixinSpecParentNode.getParent().replaceChild(
        mixinSpecParentNode,
        mixinSpecNode);
      compiler.reportChangeToEnclosingScope(mixinSpecNode.getParent());
    }
  }
}
 
开发者ID:mihaip,项目名称:react-closure-compiler,代码行数:19,代码来源:ReactCompilerPass.java


示例9: splitNameDeclarationsAndRemoveDestructuring

import com.google.javascript.jscomp.NodeTraversal; //导入依赖的package包/类
/**
 * Does two simplifications to const/let/var nodes.
 * 1. Splits them so that each declaration is a separate statement.
 * 2. Removes non-import destructuring statements, which we assume are not type declarations.
 */
static void splitNameDeclarationsAndRemoveDestructuring(Node n, NodeTraversal t) {
  checkArgument(NodeUtil.isNameDeclaration(n));
  while (n.hasChildren()) {
    Node lhsToSplit = n.getLastChild();
    if (lhsToSplit.isDestructuringLhs() && !isImportRhs(lhsToSplit.getLastChild())) {
      // Remove destructuring statements, which we assume are not type declarations
      NodeUtil.markFunctionsDeleted(lhsToSplit, t.getCompiler());
      NodeUtil.removeChild(n, lhsToSplit);
      t.reportCodeChange();
      continue;
    }
    if (n.hasOneChild()) {
      return;
    }
    // A name declaration with more than one LHS is split into separate declarations.
    Node rhs = lhsToSplit.hasChildren() ? lhsToSplit.removeFirstChild() : null;
    Node newDeclaration =
        NodeUtil.newDeclaration(lhsToSplit.detach(), rhs, n.getToken()).srcref(n);
    n.getParent().addChildAfter(newDeclaration, n);
    t.reportCodeChange();
  }
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:28,代码来源:ConvertToTypedInterface.java


示例10: propagateJsdocAtName

import com.google.javascript.jscomp.NodeTraversal; //导入依赖的package包/类
private void propagateJsdocAtName(NodeTraversal t, Node nameNode) {
  checkArgument(
      nameNode.isQualifiedName() || nameNode.isStringKey() || nameNode.isDestructuringLhs(),
      nameNode);
  Node jsdocNode = NodeUtil.getBestJSDocInfoNode(nameNode);
  JSDocInfo originalJsdoc = jsdocNode.getJSDocInfo();
  if (!isConstToBeInferred(originalJsdoc, nameNode)) {
    return;
  }
  Node rhs = NodeUtil.getRValueOfLValue(nameNode);
  if (rhs == null) {
    return;
  }
  JSDocInfo newJsdoc = JsdocUtil.getJSDocForRhs(rhs, originalJsdoc);
  if (newJsdoc == null && ClassUtil.isThisProp(nameNode)) {
    Var decl = findNameDeclaration(t.getScope(), rhs);
    newJsdoc = JsdocUtil.getJSDocForName(decl, originalJsdoc);
  }
  if (newJsdoc != null) {
    jsdocNode.setJSDocInfo(newJsdoc);
    t.reportCodeChange();
  }
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:24,代码来源:ConvertToTypedInterface.java


示例11: checkSemicolon

import com.google.javascript.jscomp.NodeTraversal; //导入依赖的package包/类
private void checkSemicolon(NodeTraversal t, Node n) {
  StaticSourceFile staticSourceFile = n.getStaticSourceFile();
  if (staticSourceFile instanceof SourceFile) {
    SourceFile sourceFile = (SourceFile) staticSourceFile;

    String code;
    try {
      code = sourceFile.getCode();
    } catch (IOException e) {
      // We can't read the original source file. Just skip this check.
      return;
    }

    int length = n.getLength();
    if (length == 0) {
      // This check needs node lengths to work correctly. If we're not in IDE mode, we don't have
      // that information, so just skip the check.
      return;
    }
    int position = n.getSourceOffset() + length - 1;
    boolean endsWithSemicolon = code.charAt(position) == ';';
    if (!endsWithSemicolon) {
      t.report(n, MISSING_SEMICOLON);
    }
  }
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:27,代码来源:CheckMissingSemicolon.java


示例12: shouldTraverse

import com.google.javascript.jscomp.NodeTraversal; //导入依赖的package包/类
@Override
public final boolean shouldTraverse(NodeTraversal t, Node n, Node parent) {
  switch (n.getToken()) {
    case BREAK:
    case CONTINUE:
      if (n.hasChildren()) {
        LabelContext temp = currentContext;
        while (temp != null) {
          if (temp.name.equals(n.getFirstChild().getString())) {
            temp.used = true;
            break;
          }
          temp = temp.parent;
        }
      }
      return false;
    case LABEL:
      currentContext = new LabelContext(n.getFirstChild().getString(), currentContext);
      break;
    default:
      break;
  }
  return true;
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:25,代码来源:CheckUnusedLabels.java


示例13: checkDuplicateEnumValues

import com.google.javascript.jscomp.NodeTraversal; //导入依赖的package包/类
private void checkDuplicateEnumValues(NodeTraversal t, Node n) {
  Set<String> values = new HashSet<>();
  for (Node child : n.children()) {
    Node valueNode = child.getLastChild();
    String value;
    if (valueNode == null) {
      return;
    } else if (valueNode.isString()) {
      value = valueNode.getString();
    } else if (valueNode.isNumber()) {
      value = Double.toString(valueNode.getDouble());
    } else {
      return;
    }

    if (!values.add(value)) {
      t.report(valueNode, DUPLICATE_ENUM_VALUE, value);
    }
  }
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:21,代码来源:CheckEnums.java


示例14: visitFunction

import com.google.javascript.jscomp.NodeTraversal; //导入依赖的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


示例15: checkInlineParams

import com.google.javascript.jscomp.NodeTraversal; //导入依赖的package包/类
/**
 * Checks that the inline type annotations are correct.
 */
private void checkInlineParams(NodeTraversal t, Node function) {
  Node paramList = NodeUtil.getFunctionParameters(function);

  for (Node param : paramList.children()) {
    JSDocInfo jsDoc = param.getJSDocInfo();
    if (jsDoc == null) {
      t.report(param, MISSING_PARAMETER_JSDOC);
      return;
    } else {
      JSTypeExpression paramType = jsDoc.getType();
      checkNotNull(paramType, "Inline JSDoc info should always have a type");
      checkParam(t, param, null, paramType);
    }
  }
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:19,代码来源:CheckJSDocStyle.java


示例16: checkReturn

import com.google.javascript.jscomp.NodeTraversal; //导入依赖的package包/类
private void checkReturn(NodeTraversal t, Node function, JSDocInfo jsDoc) {
  if (jsDoc != null
      && (jsDoc.hasType()
          || jsDoc.hasReturnType()
          || jsDoc.isOverride())) {
    return;
  }
  if (function.getFirstChild().getJSDocInfo() != null) {
    return;
  }

  FindNonTrivialReturn finder = new FindNonTrivialReturn();
  NodeTraversal.traverseEs6(compiler, function.getLastChild(), finder);
  if (finder.found) {
    t.report(function, MISSING_RETURN_JSDOC);
  }
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:18,代码来源:CheckJSDocStyle.java


示例17: shouldTraverse

import com.google.javascript.jscomp.NodeTraversal; //导入依赖的package包/类
@Override
public boolean shouldTraverse(NodeTraversal t, Node n, Node parent) {
  if (found) {
    return false;
  }

  // Shallow traversal, since we don't need to inspect within functions or expressions.
  if (parent == null
      || NodeUtil.isControlStructure(parent)
      || NodeUtil.isStatementBlock(parent)) {
    if (n.isReturn() && n.hasChildren()) {
      found = true;
      return false;
    }
    return true;
  }
  return false;
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:19,代码来源:CheckJSDocStyle.java


示例18: visit

import com.google.javascript.jscomp.NodeTraversal; //导入依赖的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


示例19: checkTypeNodeForPrimitiveObjectDeclaration

import com.google.javascript.jscomp.NodeTraversal; //导入依赖的package包/类
private void checkTypeNodeForPrimitiveObjectDeclaration(final NodeTraversal t, Node typeRoot) {
  NodeUtil.visitPreOrder(
      typeRoot,
      new NodeUtil.Visitor() {
        @Override
        public void visit(Node node) {
          if (node.isString()) {
            String typeName = node.getString();
            if (PRIMITIVE_OBJECT_CONSTRUCTORS.contains(typeName)) {
              t.report(node, PRIMITIVE_OBJECT_DECLARATION, typeName);
            }
          }
        }
      },
      Predicates.<Node>alwaysTrue());
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:17,代码来源:CheckPrimitiveAsObject.java


示例20: getFixForUnsortedRequiresOrProvides

import com.google.javascript.jscomp.NodeTraversal; //导入依赖的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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java GetJobReportResponseProto类代码示例发布时间:2022-05-22
下一篇:
Java DualHashBidiMap类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap