Package com.google.errorprone.fixes

Examples of com.google.errorprone.fixes.Fix


    }

    if (!locks.allLocks().contains(guard)) {
      String message = String.format("Expected %s to be held, instead found %s", guard, locks);
      // TODO(user) - this fix is a debugging aid, remove it before productionizing the check.
      Fix fix = SuggestedFix.prefixWith(tree, String.format("/* %s */", message));
      return Description.builder(tree, pattern)
          .setMessage(message)
          .addFix(fix)
          .build();
    }
View Full Code Here


      int begin = state.getEndPosition((JCExpression) allArgs.get(formatIndex + e.used));
      int end = state.getEndPosition((JCMethodInvocation) tree);
      if (end < 0) {
        return describeMatch(tree);
      }
      Fix fix = SuggestedFix.replace(begin, end - 1, "");
      String message = String.format(EXTRA_ARGUMENTS_MESSAGE, e.used, e.provided);
      return Description.builder(tree, pattern)
          .setMessage(message)
          .addFix(fix)
          .build();
View Full Code Here

    if (arrayArg == null) {
      return NO_MATCH;
    }

    Fix fix = SuggestedFix.builder()
        .replace(t, "Arrays.hashCode(" + arrayArg + ")")
        .addImport("java.util.Arrays")
        .build();
    return describeMatch(t, fix);
  }
View Full Code Here

     * For shift amounts in [32, 63], cast the left operand to long.  Otherwise change the shift
     * amount to whatever would actually be used.
     */
    int intValue = ((Number) ((LiteralTree) tree.getRightOperand()).getValue()).intValue();

    Fix fix;
    if (intValue >= 32 && intValue <= 63) {
      if (tree.getLeftOperand().getKind() == Kind.INT_LITERAL) {
        fix = SuggestedFix.postfixWith(tree.getLeftOperand(), "L");
      } else {
        fix = SuggestedFix.prefixWith(tree, "(long) ");
View Full Code Here

      return Description.NO_MATCH;
    }

    List<? extends ExpressionTree> arguments = methodInvocationTree.getArguments();
    ExpressionTree stringLiteralValue = arguments.get(0);
    Fix fix;
    if (arguments.size() == 2) {
      fix = SuggestedFix.swap(arguments.get(0), arguments.get(1));
    } else {
      fix = SuggestedFix.delete(state.getPath().getParentPath().getLeaf());
    }
View Full Code Here

    if (ARRAYS_AS_LIST_SINGLE_ARRAY.matches(tree, state)) {
      JCTree array = (JCTree) tree.getArguments().get(0);
      Type componentType = ((ArrayType) array.type).getComponentType();
      String guavaUtils = GUAVA_UTILS.get(componentType.getKind());
      if (guavaUtils != null) {
        Fix fix = SuggestedFix.builder()
            .addImport("com.google.common.primitives." + guavaUtils)
            .replace(tree.getMethodSelect(), guavaUtils + ".asList")
            .build();
        return describeMatch(tree, fix);
      }
View Full Code Here

      arg2 = t.getArguments().get(1).toString();
    } else {
      return NO_MATCH;
    }

    Fix fix = SuggestedFix.builder()
        .replace(t, "Arrays.equals(" + arg1 + ", " + arg2 + ")")
        .addImport("java.util.Arrays")
        .build();
    return describeMatch(t, fix);
  }
View Full Code Here

    if (!matcher.matches(literalTree, state)) {
      return Description.NO_MATCH;
    }
    StringBuilder longLiteral = new StringBuilder(getLongLiteral(literalTree, state));
    longLiteral.setCharAt(longLiteral.length() - 1, 'L');
    Fix fix = SuggestedFix.replace(literalTree, longLiteral.toString());
    return describeMatch(literalTree, fix);
  }
View Full Code Here

     */
    if (Matchers.<MethodTree>hasModifier(Modifier.STATIC).matches(methodTree, state)) {
      CharSequence methodSource = state.getSourceForNode((JCMethodDecl) methodTree);
      if (methodSource != null) {
        String methodString = "@Test\n" + methodSource.toString().replaceFirst(" static ", " ");
        Fix fix = SuggestedFix.builder()
            .addImport(JUNIT4_TEST_ANNOTATION)
            .replace(methodTree, methodString)
            .build();
        return describeMatch(methodTree, fix);
      }
    }
    Fix fix = SuggestedFix.builder()
        .addImport(JUNIT4_TEST_ANNOTATION)
        .prefixWith(methodTree, "@Test\n")
        .build();
    return describeMatch(methodTree, fix);
  }
View Full Code Here

        new Enclosing.BlockOrCase<>(lastStatement(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);
    }
View Full Code Here

TOP

Related Classes of com.google.errorprone.fixes.Fix

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.