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


Java NodeTraversal类代码示例

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


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


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