Class PreconditionExcerpts
java.lang.Object
org.inferred.freebuilder.processor.source.PreconditionExcerpts
Code snippets that call or emulate Guava's
Preconditions methods.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ExcerptcheckArgument(String conditionTemplate, String messageTemplate, Object... args) Returns an excerpt equivalent to Guava'sPreconditions.checkArgument(boolean, String, Object...).static ExcerptcheckState(String conditionTemplate, String messageTemplate, Object... args) Returns an excerpt equivalent to Guava'sPreconditions.checkState(boolean, String, Object...).private static StringNegatesconditionTemplate, removing unnecessary brackets and double-negatives if possible.
-
Field Details
-
ANY_OPERATOR
Matches all operators with a lower precedence than unary negation (!).False positives are acceptable, as the only downside is putting unnecessary brackets around the condition when Guava is not available, so a simple check for offending characters is fine, even though they might actually be in a string.
-
BOOLEAN_BINARY_OPERATOR
-
-
Constructor Details
-
PreconditionExcerpts
private PreconditionExcerpts()
-
-
Method Details
-
checkArgument
public static Excerpt checkArgument(String conditionTemplate, String messageTemplate, Object... args) Returns an excerpt equivalent to Guava'sPreconditions.checkArgument(boolean, String, Object...).- If Guava is available, Preconditions.checkArgument will be used.
- Otherwise, the check will be done with an if block.
code.add(checkArgument("%1$s >= 0", "age must be >= 0 (got %1$s)", "age"));- Parameters:
args- excerpts containing the error message arguments to pass to the checkArgument methodcondition- a code template to pass to the checkArgument methodmessage- the error message template to pass to the checkArgument method
-
checkState
Returns an excerpt equivalent to Guava'sPreconditions.checkState(boolean, String, Object...).- If Guava is available, Preconditions.checkState will be used.
- Otherwise, the check will be done with an if block.
code.add(checkState("%1$s < %2$s", "start must be before end (got %1$s and %2$s)", "start", "end"));- Parameters:
args- excerpts containing the error message arguments to pass to the checkState methodcondition- an excerpt containing the expression to pass to the checkState methodmessage- the error message template to pass to the checkState method
-
negate
-