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


Java Description.NO_MATCH属性代码示例

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


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

示例1: matchMemberSelect

@Override
public Description matchMemberSelect(MemberSelectTree tree, VisitorState state) {
  if (!matchWithinClass) {
    return Description.NO_MATCH;
  }
  Symbol symbol = ASTHelpers.getSymbol(tree);
  // some checks for cases where we know it is not
  // a null dereference
  if (symbol == null || symbol.getSimpleName().toString().equals("class") || symbol.isEnum()) {
    return Description.NO_MATCH;
  }

  Description badDeref = matchDereference(tree.getExpression(), tree, state);
  if (!badDeref.equals(Description.NO_MATCH)) {
    return badDeref;
  }
  // if we're accessing a field of this, make sure we're not reading the field before init
  if (tree.getExpression() instanceof IdentifierTree
      && ((IdentifierTree) tree.getExpression()).getName().toString().equals("this")) {
    return checkForReadBeforeInit(tree, state);
  }
  return Description.NO_MATCH;
}
 
开发者ID:uber,项目名称:NullAway,代码行数:23,代码来源:NullAway.java

示例2: checkReturnExpression

private Description checkReturnExpression(
    Tree tree, ExpressionTree retExpr, Symbol.MethodSymbol methodSymbol, VisitorState state) {
  Type returnType = methodSymbol.getReturnType();
  if (returnType.isPrimitive()) {
    // check for unboxing
    return doUnboxingCheck(state, retExpr);
  }
  if (returnType.toString().equals("java.lang.Void")) {
    return Description.NO_MATCH;
  }
  if (NullabilityUtil.fromUnannotatedPackage(methodSymbol, config)
      || Nullness.hasNullableAnnotation(methodSymbol)) {
    return Description.NO_MATCH;
  }
  if (mayBeNullExpr(state, retExpr)) {
    String message = "returning @Nullable expression from method with @NonNull return type";
    return createErrorDescriptionForNullAssignment(
        MessageTypes.RETURN_NULLABLE, tree, message, retExpr, state.getPath());
  }
  return Description.NO_MATCH;
}
 
开发者ID:uber,项目名称:NullAway,代码行数:21,代码来源:NullAway.java

示例3: matchLambdaExpression

@Override
public Description matchLambdaExpression(LambdaExpressionTree tree, VisitorState state) {
  Symbol.MethodSymbol methodSymbol =
      NullabilityUtil.getFunctionalInterfaceMethod(tree, state.getTypes());
  handler.onMatchLambdaExpression(this, tree, state, methodSymbol);
  Description description = checkParamOverriding(tree, tree.getParameters(), methodSymbol, true);
  if (description != Description.NO_MATCH) {
    return description;
  }
  if (tree.getBodyKind() == LambdaExpressionTree.BodyKind.EXPRESSION
      && methodSymbol.getReturnType().getKind() != TypeKind.VOID) {
    ExpressionTree resExpr = (ExpressionTree) tree.getBody();
    return checkReturnExpression(tree, resExpr, methodSymbol, state);
  }
  return Description.NO_MATCH;
}
 
开发者ID:uber,项目名称:NullAway,代码行数:16,代码来源:NullAway.java

示例4: checkPossibleUninitFieldRead

private Description checkPossibleUninitFieldRead(
    ExpressionTree tree,
    VisitorState state,
    Symbol symbol,
    TreePath path,
    TreePath enclosingBlockPath) {
  if (!fieldInitializedByPreviousInitializer(symbol, enclosingBlockPath, state)
      && !fieldAlwaysInitializedBeforeRead(symbol, path, state, enclosingBlockPath)) {
    return createErrorDescription(
        MessageTypes.NONNULL_FIELD_READ_BEFORE_INIT,
        tree,
        "read of @NonNull field " + symbol + " before initialization",
        path);
  } else {
    return Description.NO_MATCH;
  }
}
 
开发者ID:uber,项目名称:NullAway,代码行数:17,代码来源:NullAway.java

示例5: matchBinary

@Override
public Description matchBinary(BinaryTree tree, VisitorState state) {
  ExpressionTree leftOperand = tree.getLeftOperand();
  ExpressionTree rightOperand = tree.getRightOperand();
  Type leftType = ASTHelpers.getType(leftOperand);
  Type rightType = ASTHelpers.getType(rightOperand);
  if (leftType == null || rightType == null) {
    throw new RuntimeException();
  }
  if (leftType.isPrimitive() && !rightType.isPrimitive()) {
    return doUnboxingCheck(state, rightOperand);
  }
  if (rightType.isPrimitive() && !leftType.isPrimitive()) {
    return doUnboxingCheck(state, leftOperand);
  }
  return Description.NO_MATCH;
}
 
开发者ID:uber,项目名称:NullAway,代码行数:17,代码来源:NullAway.java

示例6: doUnboxingCheck

/**
 * if any expression has non-primitive type, we should check that it can't be null as it is
 * getting unboxed
 *
 * @param expressions expressions to check
 * @return error Description if an error is found, otherwise NO_MATCH
 */
private Description doUnboxingCheck(VisitorState state, ExpressionTree... expressions) {
  for (ExpressionTree tree : expressions) {
    Type type = ASTHelpers.getType(tree);
    if (type == null) {
      throw new RuntimeException("was not expecting null type");
    }
    if (!type.isPrimitive()) {
      if (mayBeNullExpr(state, tree)) {
        return createErrorDescription(
            MessageTypes.UNBOX_NULLABLE, tree, "unboxing of a @Nullable value", state.getPath());
      }
    }
  }
  return Description.NO_MATCH;
}
 
开发者ID:uber,项目名称:NullAway,代码行数:22,代码来源:NullAway.java

示例7: matchDereference

private Description matchDereference(
    ExpressionTree baseExpression, ExpressionTree derefExpression, VisitorState state) {
  Symbol dereferenced = ASTHelpers.getSymbol(baseExpression);
  if (dereferenced == null
      || dereferenced.type.isPrimitive()
      || !kindMayDeferenceNull(dereferenced.getKind())) {
    // we know we don't have a null dereference here
    return Description.NO_MATCH;
  }
  if (mayBeNullExpr(state, baseExpression)) {
    String message = "dereferenced expression " + baseExpression.toString() + " is @Nullable";
    return createErrorDescriptionForNullAssignment(
        MessageTypes.DEREFERENCE_NULLABLE,
        derefExpression,
        message,
        baseExpression,
        state.getPath());
  }
  return Description.NO_MATCH;
}
 
开发者ID:uber,项目名称:NullAway,代码行数:20,代码来源:NullAway.java

示例8: matchMethodInvocation

@Override
public Description matchMethodInvocation(
    MethodInvocationTree methodInvocationTree, VisitorState state) {
  if (!MATCHER.matches(methodInvocationTree, state)) {
    return Description.NO_MATCH;
  }
  if (methodInvocationTree.getArguments().size() % 2 == 0) {
    return Description.NO_MATCH;
  }
  JCMethodInvocation methodInvocation = (JCMethodInvocation) methodInvocationTree;
  List<JCExpression> arguments = methodInvocation.getArguments();

  Type typeVargs = methodInvocation.varargsElement;
  if (typeVargs == null) {
    return Description.NO_MATCH;
  }
  Type typeVarargsArr = state.arrayTypeForType(typeVargs);
  Type lastArgType = ASTHelpers.getType(Iterables.getLast(arguments));
  if (typeVarargsArr.equals(lastArgType)) {
    return Description.NO_MATCH;
  }
  return describeMatch(methodInvocationTree);
}
 
开发者ID:google,项目名称:error-prone,代码行数:23,代码来源:ShouldHaveEvenArgs.java

示例9: matchNewClass

@Override
public Description matchNewClass(NewClassTree newClassTree, VisitorState state) {
  if (!MATCHER.matches(newClassTree, state)) {
    return Description.NO_MATCH;
  }

  StatementTree parent = (StatementTree) state.getPath().getParentPath().getLeaf();

  boolean isLastStatement =
      anyOf(
              new ChildOfBlockOrCase<>(
                  ChildMultiMatcher.MatchType.LAST, Matchers.<StatementTree>isSame(parent)),
              // it could also be a bare if statement with no braces
              parentNode(parentNode(kindIs(IF))))
          .matches(newClassTree, state);

  Fix fix;
  if (isLastStatement) {
    fix = SuggestedFix.prefixWith(newClassTree, "throw ");
  } else {
    fix = SuggestedFix.delete(parent);
  }

  return describeMatch(newClassTree, fix);
}
 
开发者ID:google,项目名称:error-prone,代码行数:25,代码来源:DeadException.java

示例10: matchCompoundAssignment

/**
 * Matchers when a string concatenates-and-assigns an array.
 */
@Override
public Description matchCompoundAssignment(CompoundAssignmentTree t, VisitorState state) {
  if (!assignmentMatcher.matches(t, state)) {
    return Description.NO_MATCH;
  }

  /*
   * Replace instances of implicit array toString() calls due to string
   * concatenation-and-assignment with Arrays.toString(array). Also adds
   * the necessary import statement for java.util.Arrays.
   */
  String receiver = t.getVariable().toString();
  String expression = t.getExpression().toString();
  Fix fix = new SuggestedFix()
      .replace(t, receiver + " += Arrays.toString(" + expression + ")")
      .addImport("java.util.Arrays");
  return describeMatch(t, fix);
}
 
开发者ID:diy1,项目名称:error-prone-aspirator,代码行数:21,代码来源:ArrayToStringCompoundAssignment.java

示例11: matchDivZero

private Description matchDivZero(Tree tree, ExpressionTree operand, VisitorState state) {
  if (!anyOf(kindIs(Kind.DIVIDE), kindIs(Kind.DIVIDE_ASSIGNMENT)).matches(tree, state)) {
    return Description.NO_MATCH;
  }

  if (!kindIs(Kind.INT_LITERAL).matches(operand, state)) {
    return Description.NO_MATCH;
  }

  LiteralTree rightOperand = (LiteralTree) operand;
  if (((Integer) rightOperand.getValue()) != 0) {
    return Description.NO_MATCH;
  }

  // Find and replace enclosing Statement.
  StatementTree enclosingStmt =
      ASTHelpers.findEnclosingNode(state.getPath(), StatementTree.class);
  return (enclosingStmt != null)
      ? describeMatch(
          tree,
          SuggestedFix.replace(enclosingStmt, "throw new ArithmeticException(\"/ by zero\");"))
      : describeMatch(tree);
}
 
开发者ID:google,项目名称:error-prone,代码行数:23,代码来源:DivZero.java

示例12: matchReturn

/**
 * We are trying to see if (1) we are in a method guaranteed to return something non-null, and (2)
 * this return statement can return something null.
 */
@Override
public Description matchReturn(ReturnTree tree, VisitorState state) {
  if (!matchWithinClass) {
    return Description.NO_MATCH;
  }
  handler.onMatchReturn(this, tree, state);
  ExpressionTree retExpr = tree.getExpression();
  // let's do quick checks on returned expression first
  if (retExpr == null) {
    return Description.NO_MATCH;
  }
  // now let's check the enclosing method
  TreePath enclosingMethodOrLambda =
      NullabilityUtil.findEnclosingMethodOrLambdaOrInitializer(state.getPath());
  if (enclosingMethodOrLambda == null) {
    throw new RuntimeException("no enclosing method, lambda or initializer!");
  }
  if (!(enclosingMethodOrLambda.getLeaf() instanceof MethodTree
      || enclosingMethodOrLambda.getLeaf() instanceof LambdaExpressionTree)) {
    throw new RuntimeException(
        "return statement outside of a method or lambda! (e.g. in an initializer block)");
  }
  Tree leaf = enclosingMethodOrLambda.getLeaf();
  Symbol.MethodSymbol methodSymbol;
  if (leaf instanceof MethodTree) {
    MethodTree enclosingMethod = (MethodTree) leaf;
    methodSymbol = ASTHelpers.getSymbol(enclosingMethod);
  } else {
    // we have a lambda
    methodSymbol =
        NullabilityUtil.getFunctionalInterfaceMethod(
            (LambdaExpressionTree) leaf, state.getTypes());
  }
  return checkReturnExpression(tree, retExpr, methodSymbol, state);
}
 
开发者ID:uber,项目名称:NullAway,代码行数:39,代码来源:NullAway.java

示例13: matchMemberSelect

@Override
public final Description matchMemberSelect(MemberSelectTree tree, VisitorState state) {
  if (ASTHelpers.findEnclosingNode(state.getPath(), ImportTree.class) != null) {
    return Description.NO_MATCH;
  }
  return matchTree(tree);
}
 
开发者ID:google,项目名称:guava-beta-checker,代码行数:7,代码来源:AnnotatedApiUsageChecker.java

示例14: matchMethodInvocation

@Override
public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) {
  if (MATCHER.matches(tree, state)) {
    return buildDescription(tree).build();
  } else {
    return Description.NO_MATCH;
  }
}
 
开发者ID:uber,项目名称:RIBs,代码行数:8,代码来源:RxJavaMissingAutodisposeErrorChecker.java

示例15: matchAssignment

@Override
public Description matchAssignment(AssignmentTree tree, VisitorState state) {
  if (!matchWithinClass) {
    return Description.NO_MATCH;
  }
  Type lhsType = ASTHelpers.getType(tree.getVariable());
  if (lhsType != null && lhsType.isPrimitive()) {
    return doUnboxingCheck(state, tree.getExpression());
  }
  Symbol assigned = ASTHelpers.getSymbol(tree.getVariable());
  if (assigned == null || assigned.getKind() != ElementKind.FIELD) {
    // not a field of nullable type
    return Description.NO_MATCH;
  }

  if (Nullness.hasNullableAnnotation(assigned)) {
    // field already annotated
    return Description.NO_MATCH;
  }
  ExpressionTree expression = tree.getExpression();
  if (mayBeNullExpr(state, expression)) {
    String message = "assigning @Nullable expression to @NonNull field";
    return createErrorDescriptionForNullAssignment(
        MessageTypes.ASSIGN_FIELD_NULLABLE, tree, message, expression, state.getPath());
  }
  return Description.NO_MATCH;
}
 
开发者ID:uber,项目名称:NullAway,代码行数:27,代码来源:NullAway.java


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