com.google.errorprone.annotations.FormatString Java Examples

The following examples show how to use com.google.errorprone.annotations.FormatString. 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: 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 #4
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 #5
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 #6
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 #7
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 #8
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 #9
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 #10
Source File: KLog.java    From syndesis with 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 #11
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 #12
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 #13
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 #14
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 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 #15
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 #16
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 #17
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 #18
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 #19
Source File: MoeProblem.java    From MOE with Apache License 2.0 4 votes vote down vote up
@FormatMethod
public MoeProblem(Throwable cause, @FormatString String explanationFmt, Object... args) {
  super(cause); // TODO(cgruber) do we need to lazily format? Could we not just format at constr?
  this.explanationFmt = explanationFmt;
  this.args = args;
}
 
Example #20
Source File: MoeProblem.java    From MOE with Apache License 2.0 4 votes vote down vote up
@FormatMethod
public MoeProblem(@FormatString String explanationFmt, Object... args) {
  this.explanationFmt = explanationFmt;
  this.args = args;
}
 
Example #21
Source File: SymbolTableSubject.java    From js-dossier with Apache License 2.0 4 votes vote down vote up
@FormatMethod
protected void failWithMessage(@FormatString String message, Object... args) {
  failWithoutActual(
      Fact.simpleFact(
          "Not true that " + internalCustomName() + " " + String.format(message, args)));
}
 
Example #22
Source File: CodebaseCreationError.java    From MOE with Apache License 2.0 4 votes vote down vote up
@FormatMethod
public CodebaseCreationError(@FormatString String message, Object... args) {
  super(String.format(message, args));
}
 
Example #23
Source File: CodebaseCreationError.java    From MOE with Apache License 2.0 4 votes vote down vote up
@FormatMethod
public CodebaseCreationError(Throwable cause, @FormatString String message, Object... args) {
  super(String.format(message, args), cause);
}
 
Example #24
Source File: LocalSpawnRunner.java    From bazel with Apache License 2.0 4 votes vote down vote up
@FormatMethod
private void stepLog(Level level, @FormatString String fmt, Object... args) {
  stepLog(level, /*cause=*/ null, fmt, args);
}
 
Example #25
Source File: SerializationProcessorUtil.java    From bazel with Apache License 2.0 4 votes vote down vote up
@FormatMethod
SerializationProcessingFailedException(
    Element element, @FormatString String fmt, Object... args) {
  super(String.format(fmt, args));
  this.element = element;
}
 
Example #26
Source File: AssetModuleFilesValidator.java    From bundletool with 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 #27
Source File: AccessibilityNodeInfoUtils.java    From talkback with Apache License 2.0 4 votes vote down vote up
@FormatMethod
private static void logError(String functionName, @FormatString String format, Object... args) {
  LogUtils.e(TAG, functionName + "() " + String.format(format, 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: 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 #30
Source File: Problems.java    From j2cl with Apache License 2.0 4 votes vote down vote up
@FormatMethod
public void error(
    int lineNumber, String filePath, @FormatString String detailMessage, Object... args) {
  problem(Severity.ERROR, lineNumber, filePath, detailMessage, args);
}