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


Java NodeTraversal.report方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: visit

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

  Node args = n.getSecondChild();
  if (args.hasChildren()) {
    t.report(args.getFirstChild(), INTERFACE_SHOULD_NOT_TAKE_ARGS);
  }

  Node block = n.getLastChild();
  if (block.hasChildren()) {
    if (NodeUtil.getBestJSDocInfo(n).usesImplicitMatch()) {
      for (Node stmt : block.children()) {
        if (stmt.isExprResult()
            && stmt.getFirstChild().isGetProp()
            && stmt.getFirstFirstChild().isThis()
            && stmt.getFirstChild().getJSDocInfo() != null) {
          // Field declarations are expected.
        } else {
          t.report(stmt, NON_DECLARATION_STATEMENT_IN_RECORD);
          return;
        }
      }
    } else {
      t.report(block.getFirstChild(), INTERFACE_FUNCTION_NOT_EMPTY);
    }
  }
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:31,代码来源:CheckInterfaces.java

示例7: visit

import com.google.javascript.jscomp.NodeTraversal; //导入方法依赖的package包/类
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
  if (n.isNormalBlock() && !loneBlocks.isEmpty() && loneBlocks.peek() == n) {
    loneBlocks.pop();
    t.report(n, USELESS_BLOCK);
  }
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:8,代码来源:CheckUselessBlocks.java

示例8: visit

import com.google.javascript.jscomp.NodeTraversal; //导入方法依赖的package包/类
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
  if (n.isLabel() && currentContext != null) {
    if (!currentContext.used) {
      t.report(n, UNUSED_LABEL, n.getFirstChild().getString());
    }
    currentContext = currentContext.parent;
  }
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:10,代码来源:CheckUnusedLabels.java

示例9: visit

import com.google.javascript.jscomp.NodeTraversal; //导入方法依赖的package包/类
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
  if (n.isSwitch()) {
    Set<String> cases = new HashSet<>();
    for (Node curr = n.getSecondChild(); curr != null; curr = curr.getNext()) {
      String source = compiler.toSource(curr.getFirstChild());
      if (!cases.add(source)) {
        t.report(curr, DUPLICATE_CASE);
      }
    }
  }
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:13,代码来源:CheckDuplicateCase.java

示例10: checkName

import com.google.javascript.jscomp.NodeTraversal; //导入方法依赖的package包/类
private void checkName(NodeTraversal t, Node node) {
  if (node.isComputedProp()) {
    t.report(node, COMPUTED_PROP_NAME_IN_ENUM);
    return;
  }

  if (node.isStringKey() && node.isShorthandProperty()) {
    t.report(node, SHORTHAND_ASSIGNMENT_IN_ENUM);
  }

  if (!compiler.getCodingConvention().isValidEnumKey(node.getString())) {
    t.report(node, ENUM_PROP_NOT_CONSTANT);
  }
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:15,代码来源:CheckEnums.java

示例11: checkStyleForPrivateProperties

import com.google.javascript.jscomp.NodeTraversal; //导入方法依赖的package包/类
private void checkStyleForPrivateProperties(NodeTraversal t, Node n) {
  JSDocInfo jsDoc = NodeUtil.getBestJSDocInfo(n);
  String name;
  if (n.isMemberFunctionDef() || n.isGetterDef() || n.isSetterDef()) {
    name = n.getString();
  } else {
    checkState(n.isAssign());
    Node lhs = n.getFirstChild();
    if (!lhs.isGetProp()) {
      return;
    }
    name = lhs.getLastChild().getString();
  }
  if (name.equals("constructor")) {
    return;
  }

  if (jsDoc != null && name != null) {
    if (compiler.getCodingConvention().isPrivate(name)
        && !jsDoc.getVisibility().equals(Visibility.PRIVATE)) {
      t.report(n, MUST_BE_PRIVATE, name);
    } else if (compiler.getCodingConvention().hasPrivacyConvention()
        && !compiler.getCodingConvention().isPrivate(name)
        && jsDoc.getVisibility().equals(Visibility.PRIVATE)) {
      t.report(n, MUST_HAVE_TRAILING_UNDERSCORE, name);
    }
  }
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:29,代码来源:CheckJSDocStyle.java

示例12: checkSuppressionsOnNonFunction

import com.google.javascript.jscomp.NodeTraversal; //导入方法依赖的package包/类
private void checkSuppressionsOnNonFunction(NodeTraversal t, Node n, JSDocInfo jsDoc) {
  // Suppressions that are allowed to be in places other than functions and @fileoverview blocks.
  Set<String> specialSuppressions =
      ImmutableSet.of("const", "duplicate", "extraRequire", "missingRequire");

  Set<String> suppressions = Sets.difference(jsDoc.getSuppressions(), specialSuppressions);
  if (!suppressions.isEmpty()) {
    t.report(n, INVALID_SUPPRESS);
  }
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:11,代码来源:CheckJSDocStyle.java

示例13: visitClass

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

  if (jsDoc == null) {
    return;
  }
  if (jsDoc.isConstructor()) {
    t.report(cls, CLASS_DISALLOWED_JSDOC);
  }
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:11,代码来源:CheckJSDocStyle.java

示例14: checkMissingJsDoc

import com.google.javascript.jscomp.NodeTraversal; //导入方法依赖的package包/类
private void checkMissingJsDoc(NodeTraversal t, Node function) {
  if (isFunctionThatShouldHaveJsDoc(t, function)) {
    String name = NodeUtil.getName(function);
    // Don't warn for test functions, setUp, tearDown, etc.
    if (name == null || !ExportTestFunctions.isTestFunction(name)) {
      t.report(function, MISSING_JSDOC);
    }
  }
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:10,代码来源:CheckJSDocStyle.java

示例15: checkParams

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

  if (jsDoc != null && jsDoc.getType() != null) {
    // Sometimes functions are declared with @type {function(Foo, Bar)} instead of
    //   @param {Foo} foo
    //   @param {Bar} bar
    // which is fine.
    return;
  }

  List<String> paramsFromJsDoc =
      jsDoc == null
          ? ImmutableList.<String>of()
          : ImmutableList.<String>copyOf(jsDoc.getParameterNames());
  if (paramsFromJsDoc.isEmpty()) {
    checkInlineParams(t, function);
  } else {
    Node paramList = NodeUtil.getFunctionParameters(function);
    if (paramsFromJsDoc.size() != paramList.getChildCount()) {
      t.report(paramList, WRONG_NUMBER_OF_PARAMS);
      return;
    }

    Node param = paramList.getFirstChild();
    for (int i = 0; i < paramsFromJsDoc.size(); i++) {
      if (param.getJSDocInfo() != null) {
        t.report(param, MIXED_PARAM_JSDOC_STYLES);
      }
      String name = paramsFromJsDoc.get(i);
      JSTypeExpression paramType = jsDoc.getParameterType(name);
      if (checkParam(t, param, name, paramType)) {
        return;
      }
      param = param.getNext();
    }
  }
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:41,代码来源:CheckJSDocStyle.java


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