Java Code Examples for com.google.errorprone.annotations.FormatString

The following examples show how to use com.google.errorprone.annotations.FormatString. These examples are extracted from open source projects. 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 Project: j2cl   Source File: Problems.java    License: Apache License 2.0 6 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 Project: bazel   Source File: SpawnAction.java    License: 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 Project: syndesis   Source File: KLog.java    License: 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 4
Source Project: syndesis   Source File: KLog.java    License: 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 5
Source Project: syndesis   Source File: KLog.java    License: Apache License 2.0 5 votes vote down vote up
@FormatMethod
public void debug(Throwable throwable, @FormatString String message, Object... args) {
    if (!isDebugEnabled()) {
        return;
    }
    kLogger.debug(format(message, args), throwable);
}
 
Example 6
Source Project: syndesis   Source File: KLog.java    License: 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 7
Source Project: syndesis   Source File: KLog.java    License: 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 8
Source Project: copybara   Source File: ValidationException.java    License: 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 9
Source Project: copybara   Source File: SkylarkUtil.java    License: 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 10
Source Project: talkback   Source File: ScreenFeedbackManager.java    License: 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 11
Source Project: talkback   Source File: AccessibilityNode.java    License: 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 12
Source Project: talkback   Source File: AccessibilityWindow.java    License: 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 13
Source Project: bazel   Source File: LocalSpawnRunner.java    License: 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 14
Source Project: bazel   Source File: SingleToolchainResolutionFunction.java    License: 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 15
Source Project: bazel   Source File: SpawnAction.java    License: 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 subject Passed to {@link String#format}
 */
@FormatMethod
public Builder setProgressMessage(@FormatString String progressMessage, Object subject) {
  return setProgressMessage(
      new LazyString() {
        @Override
        public String toString() {
          return String.format(progressMessage, subject);
        }
      });
}
 
Example 16
Source Project: bazel   Source File: SpawnAction.java    License: 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 17
Source Project: bazel   Source File: SpawnAction.java    License: 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 18
Source Project: bazel   Source File: CustomCommandLine.java    License: 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 19
Source Project: bundletool   Source File: AssetModuleFilesValidator.java    License: Apache License 2.0 4 votes vote down vote up
@FormatMethod
private void validate(boolean condition, @FormatString String message, Object... args) {
  if (!condition) {
    throw InvalidBundleException.builder().withUserMessage(message, args).build();
  }
}
 
Example 20
Source Project: bundletool   Source File: CommandHelp.java    License: 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 21
Source Project: bundletool   Source File: InternalExceptionBuilder.java    License: Apache License 2.0 4 votes vote down vote up
@FormatMethod
public InternalExceptionBuilder<T> withInternalMessage(
    @FormatString String message, Object... args) {
  this.internalMessage = String.format(checkNotNull(message), args);
  return this;
}
 
Example 22
Source Project: bundletool   Source File: UserExceptionBuilder.java    License: Apache License 2.0 4 votes vote down vote up
@FormatMethod
public UserExceptionBuilder<T> withUserMessage(@FormatString String message, Object... args) {
  this.userMessage = String.format(checkNotNull(message), args);
  return this;
}
 
Example 23
Source Project: bundletool   Source File: DeviceNotFoundException.java    License: Apache License 2.0 4 votes vote down vote up
@FormatMethod
public DeviceNotFoundException(@FormatString String message, Object... args) {
  super(String.format(checkNotNull(message), args));
}
 
Example 24
Source Project: syndesis   Source File: KLog.java    License: Apache License 2.0 4 votes vote down vote up
@FormatMethod
public void info(@FormatString String message, Object... args) {
    kLogger.info(format(message, args));
}
 
Example 25
Source Project: syndesis   Source File: KLog.java    License: Apache License 2.0 4 votes vote down vote up
@FormatMethod
public void info(Throwable throwable, @FormatString String message, Object... args) {
    kLogger.info(format(message, args), throwable);
}
 
Example 26
Source Project: syndesis   Source File: KLog.java    License: Apache License 2.0 4 votes vote down vote up
@FormatMethod
public void warn(@FormatString String message, Object... args) {
    kLogger.warn(format(message, args));
}
 
Example 27
Source Project: syndesis   Source File: KLog.java    License: Apache License 2.0 4 votes vote down vote up
@FormatMethod
public void warn(Throwable throwable, @FormatString String message, Object... args) {
    kLogger.warn(format(message, args), throwable);
}
 
Example 28
Source Project: syndesis   Source File: KLog.java    License: Apache License 2.0 4 votes vote down vote up
@FormatMethod
public void error(@FormatString String message, Object... args) {
    kLogger.error(format(message, args));
}
 
Example 29
Source Project: syndesis   Source File: KLog.java    License: Apache License 2.0 4 votes vote down vote up
@FormatMethod
public void error(Throwable throwable, @FormatString String message, Object... args) {
    kLogger.error(format(message, args), throwable);
}
 
Example 30
Source Project: j2cl   Source File: Problems.java    License: Apache License 2.0 4 votes vote down vote up
@FormatMethod
public void error(
    SourcePosition sourcePosition, @FormatString String detailMessage, Object... args) {
  problem(Severity.ERROR, sourcePosition, detailMessage, args);
}