Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,11 @@ private static AndroidEntryPointMetadata of(
ProcessorErrors.checkState(
hiltAnnotations.size() == 1,
element,
"Expected exactly 1 of %s. Found: %s",
HILT_ANNOTATION_NAMES.stream().map(ClassName::canonicalName).collect(toImmutableSet()),
hiltAnnotations.stream().map(XAnnotations::toStableString).collect(toImmutableSet()));
() -> String.format(
"Expected exactly 1 of %s. Found: %s",
HILT_ANNOTATION_NAMES.stream().map(ClassName::canonicalName).collect(toImmutableSet()),
hiltAnnotations.stream().map(XAnnotations::toStableString).collect(toImmutableSet())));

ClassName annotationClassName = getOnlyElement(hiltAnnotations).getClassName();

ProcessorErrors.checkState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.google.errorprone.annotations.FormatMethod;
import com.google.errorprone.annotations.FormatString;
import java.util.Collection;
import java.util.function.Supplier;
import javax.annotation.Nullable;

/** Static helper methods for throwing errors during code generation. */
Expand Down Expand Up @@ -67,6 +68,20 @@ public static void checkState(
}
}

/**
* Ensures the truth of an expression involving the state of the calling instance, but not
* involving any parameters to the calling method.
*
* @param expression a boolean expression
* @param errorMessageSupplier the supplier to construct the exception message if the check fails
* @throws BadInputException if {@code expression} is false
*/
public static void checkState(boolean expression, Supplier<String> errorMessageSupplier) {
if (!expression) {
throw new BadInputException(errorMessageSupplier.get());
}
}

/**
* Ensures the truth of an expression involving the state of the calling instance, but not
* involving any parameters to the calling method.
Expand Down Expand Up @@ -117,6 +132,23 @@ public static void checkState(
}
}

/**
* Ensures the truth of an expression involving the state of the calling instance, but not
* involving any parameters to the calling method.
*
* @param expression a boolean expression
* @param badElement the element that was at fault
* @param errorMessageSupplier the supplier to construct the exception message if the check fails
* @throws BadInputException if {@code expression} is false
*/
public static void checkState(
boolean expression, XElement badElement, Supplier<String> errorMessageSupplier) {
Preconditions.checkNotNull(badElement);
if (!expression) {
throw new BadInputException(errorMessageSupplier.get(), badElement);
}
}

/**
* Ensures the truth of an expression involving the state of the calling instance, but not
* involving any parameters to the calling method.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,12 @@ public static ImmutableList<XTypeElement> getAnnotationClassValues(
ProcessorErrors.checkState(
values.size() >= 1,
annotation.getTypeElement(),
"@%s, '%s' class is invalid or missing: %s",
annotation.getName(),
key,
XAnnotations.toStableString(annotation));
() ->
String.format(
"@%s, '%s' class is invalid or missing: %s",
annotation.getName(),
key,
XAnnotations.toStableString(annotation)));

return values;
}
Expand Down
Loading