com.google.errorprone.annotations.FormatMethod Java Examples

The following examples show how to use com.google.errorprone.annotations.FormatMethod. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Problems.java    From j2cl with Apache License 2.0 7 votes vote down vote up
@FormatMethod
private void problem(
    Severity severity,
    int lineNumber,
    String filePath,
    @FormatString String detailMessage,
    Object... args) {
  String message = args.length == 0 ? detailMessage : String.format(detailMessage, args);
  problemsBySeverity.put(
      severity,
      String.format(
          "%s:%s:%s: %s",
          severity.getMessagePrefix(),
          filePath.substring(filePath.lastIndexOf('/') + 1),
          lineNumber,
          message));
}
 
Example #2
Source File: SpawnAction.java    From bazel with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the progress message. The string is lazily evaluated.
 *
 * @param progressMessage The message to display
 * @param subject0 Passed to {@link String#format}
 * @param subject1 Passed to {@link String#format}
 * @param subject2 Passed to {@link String#format}
 * @param subject3 Passed to {@link String#format}
 */
@FormatMethod
public Builder setProgressMessage(
    @FormatString String progressMessage,
    Object subject0,
    Object subject1,
    Object subject2,
    Object subject3) {
  return setProgressMessage(
      new LazyString() {
        @Override
        public String toString() {
          return String.format(progressMessage, subject0, subject1, subject2, subject3);
        }
      });
}
 
Example #3
Source File: SingleToolchainResolutionFunction.java    From bazel with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to print a debugging message, if the given {@link EventHandler} is not {@code
 * null}.
 */
@FormatMethod
private static void debugMessage(
    @Nullable EventHandler eventHandler, @FormatString String template, Object... args) {
  if (eventHandler == null) {
    return;
  }

  eventHandler.handle(Event.info("ToolchainResolution: " + String.format(template, args)));
}
 
Example #4
Source File: SpawnAction.java    From bazel with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the progress message. The string is lazily evaluated.
 *
 * @param progressMessage The message to display
 * @param subject0 Passed to {@link String#format}
 * @param subject1 Passed to {@link String#format}
 * @param subject2 Passed to {@link String#format}
 */
@FormatMethod
public Builder setProgressMessage(
    @FormatString String progressMessage, Object subject0, Object subject1, Object subject2) {
  return setProgressMessage(
      new LazyString() {
        @Override
        public String toString() {
          return String.format(progressMessage, subject0, subject1, subject2);
        }
      });
}
 
Example #5
Source File: DdmlibDevice.java    From bundletool with Apache License 2.0 5 votes vote down vote up
@FormatMethod
private void executeAndPrint(String commandFormat, String... args)
    throws TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException,
        IOException {
  String command = formatCommandWithArgs(commandFormat, args);
  lastOutputLine = null;
  out.println("ADB << " + command);
  // ExecuteShellCommand would only tell us about ADB errors, and NOT the actual shell commands
  // We need another way to check exit values of the commands we run.
  // By adding " && echo OK" we can make sure "OK" is printed if the cmd executed successfully.
  device.executeShellCommand(command + " && echo OK", receiver, timeout, TimeUnit.MILLISECONDS);
  if (!"OK".equals(lastOutputLine)) {
    throw new IOException("ADB command failed.");
  }
}
 
Example #6
Source File: KLog.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@FormatMethod
private static String format(final @FormatString String message, final Object... arguments ) {
    final String messageToUse = message == null ? StringConstants.EMPTY_STRING : message;
    if (arguments == null || arguments.length == 0) {
        return messageToUse;
    }
    return String.format(messageToUse, arguments);
}
 
Example #7
Source File: Preconditions.java    From besu with Apache License 2.0 5 votes vote down vote up
@FormatMethod
public static void checkGuard(
    final boolean condition,
    final Function<String, ? extends RuntimeException> exceptionGenerator,
    final String template,
    final Object... variables) {
  if (!condition) {
    throw exceptionGenerator.apply(String.format(template, variables));
  }
}
 
Example #8
Source File: CustomCommandLine.java    From bazel with Apache License 2.0 5 votes vote down vote up
/** Calls {@link String#format} at command line expansion time. */
@FormatMethod
public Builder addFormatted(@FormatString String formatStr, Object... args) {
  Preconditions.checkNotNull(formatStr);
  FormatArg.push(arguments, formatStr, args);
  return this;
}
 
Example #9
Source File: KLog.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@FormatMethod
public void debug(@FormatString String message, Object... args) {
    if (!isDebugEnabled()) {
        return;
    }
    kLogger.debug(format(message, args));
}
 
Example #10
Source File: KLog.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@FormatMethod
public void trace(@FormatString String message, Object... args) {
    if (!isTraceEnabled()) {
        return;
    }
    kLogger.trace(format(message, args));
}
 
Example #11
Source File: KLog.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@FormatMethod
public void trace(Throwable throwable, @FormatString String message, Object... args) {
    if (!isTraceEnabled()) {
        return;
    }
    kLogger.trace(format(message, args), throwable);
}
 
Example #12
Source File: Problems.java    From j2cl with Apache License 2.0 5 votes vote down vote up
@FormatMethod
private void problem(
    Severity severity, SourcePosition sourcePosition, String detailMessage, Object... args) {
  problem(
      severity,
      // SourcePosition lines are 0 based.
      sourcePosition.getStartFilePosition().getLine() + 1,
      sourcePosition.getFilePath(),
      detailMessage,
      args);
}
 
Example #13
Source File: SkylarkUtil.java    From copybara with Apache License 2.0 5 votes vote down vote up
/** Checks a condition or throw {@link EvalException}. */
@FormatMethod
public static void check(boolean condition, @FormatString String format, Object... args)
    throws EvalException {
  if (!condition) {
    throw Starlark.errorf(format, args);
  }
}
 
Example #14
Source File: ScreenFeedbackManager.java    From talkback with Apache License 2.0 5 votes vote down vote up
@FormatMethod
protected static void logCompose(
    final int depth, String methodName, @FormatString String format, Object... args) {

  // Compute indentation.
  char[] indentChars = new char[depth * 2];
  Arrays.fill(indentChars, ' ');
  String indent = new String(indentChars);

  // Log message.
  LogUtils.v(TAG, "%s%s() %s", indent, methodName, String.format(format, args));
}
 
Example #15
Source File: AccessibilityNode.java    From talkback with Apache License 2.0 5 votes vote down vote up
@FormatMethod
private void logOrThrow(@FormatString String format, Object... parameters) {
  if (isDebug()) {
    throwError(format, parameters);
  } else {
    logError(format, parameters);
  }
}
 
Example #16
Source File: AccessibilityWindow.java    From talkback with Apache License 2.0 5 votes vote down vote up
@FormatMethod
private void logOrThrow(@FormatString String format, Object... parameters) {
  if (isDebug()) {
    throwError(format, parameters);
  } else {
    logError(format, parameters);
  }
}
 
Example #17
Source File: Caffeine.java    From caffeine with Apache License 2.0 5 votes vote down vote up
/** Ensures that the argument expression is true. */
@FormatMethod
static void requireArgument(boolean expression, String template, @Nullable Object... args) {
  if (!expression) {
    throw new IllegalArgumentException(String.format(template, args));
  }
}
 
Example #18
Source File: Caffeine.java    From caffeine with Apache License 2.0 5 votes vote down vote up
/** Ensures that the state expression is true. */
@FormatMethod
static void requireState(boolean expression, String template, @Nullable Object... args) {
  if (!expression) {
    throw new IllegalStateException(String.format(template, args));
  }
}
 
Example #19
Source File: ValidationException.java    From copybara with Apache License 2.0 5 votes vote down vote up
/**
 * Check a condition and throw {@link ValidationException} if false
 *
 * @throws ValidationException if {@code condition} is false
 */
@FormatMethod
public static void checkCondition(boolean condition, @FormatString String format, Object... args)
    throws ValidationException {
  if (!condition) {
    // Don't try to format if there is no args. This allows strings like '%Fooooo'ยก
    if (args.length == 0) {
      throw new ValidationException(format);
    }
    throw new ValidationException(String.format(format, args));
  }
}
 
Example #20
Source File: SpawnAction.java    From bazel with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the progress message. The string is lazily evaluated.
 *
 * @param progressMessage The message to display
 * @param subject0 Passed to {@link String#format}
 * @param subject1 Passed to {@link String#format}
 */
@FormatMethod
public Builder setProgressMessage(
    @FormatString String progressMessage, Object subject0, Object subject1) {
  return setProgressMessage(
      new LazyString() {
        @Override
        public String toString() {
          return String.format(progressMessage, subject0, subject1);
        }
      });
}
 
Example #21
Source File: ClassReader.java    From turbine with Apache License 2.0 5 votes vote down vote up
@FormatMethod
@CheckReturnValue
Error error(String format, Object... args) {
  StringBuilder sb = new StringBuilder();
  if (path != null) {
    sb.append(path).append(": ");
  }
  sb.append(String.format(format, args));
  return new AssertionError(sb.toString());
}
 
Example #22
Source File: LocalSpawnRunner.java    From bazel with Apache License 2.0 5 votes vote down vote up
@FormatMethod
private void stepLog(
    Level level, @Nullable Throwable cause, @FormatString String fmt, Object... args) {
  String msg = String.format(fmt, args);
  String toLog = String.format("%s (#%d %s)", msg, id, desc());
  logger.at(level).withCause(cause).log(toLog);
}
 
Example #23
Source File: Parser.java    From bazel with Apache License 2.0 5 votes vote down vote up
@FormatMethod
private void reportError(int offset, String format, Object... args) {
  errorsCount++;
  // Limit the number of reported errors to avoid spamming output.
  if (errorsCount <= 5) {
    Location location = locs.getLocation(offset);
    errors.add(new SyntaxError(location, String.format(format, args)));
  }
}
 
Example #24
Source File: Console.java    From copybara with Apache License 2.0 4 votes vote down vote up
/**
 * Print a format string as progress on the console
 */
@FormatMethod
default void progressFmt(String format, Object... args) {
  progress(String.format(format, args));
}
 
Example #25
Source File: Console.java    From copybara with Apache License 2.0 4 votes vote down vote up
/**
 * Print a format string as info on the console
 */
@FormatMethod
default void infoFmt(String format, Object... args) {
  info(String.format(format, args));
}
 
Example #26
Source File: AccessibilityNode.java    From talkback with Apache License 2.0 4 votes vote down vote up
@FormatMethod
protected void throwError(@FormatString String format, Object... parameters) {
  throw new IllegalStateException(String.format(format, parameters));
}
 
Example #27
Source File: CommandHelp.java    From bundletool with Apache License 2.0 4 votes vote down vote up
/** Same as {@link #setDescription(String)} but allowing formatted string. */
@FormatMethod
Builder setDescription(@FormatString String description, Object... args) {
  return setDescription(String.format(description, args));
}
 
Example #28
Source File: AccessibilityWindow.java    From talkback with Apache License 2.0 4 votes vote down vote up
@FormatMethod
protected void throwError(@FormatString String format, Object... parameters) {
  throw new IllegalStateException(String.format(format, parameters));
}
 
Example #29
Source File: Console.java    From copybara with Apache License 2.0 4 votes vote down vote up
/**
 * Print a format string as warn on the console
 */
@FormatMethod
default void warnFmt(String format, Object... args) {
  warn(String.format(format, args));
}
 
Example #30
Source File: ErrorMessenger.java    From bazel with Apache License 2.0 4 votes vote down vote up
@FormatMethod
ErrorMessenger addError(String recipe, Object... args) {
  errorMessages.add(String.format(recipe, args));
  return this;
}