Skip to content

Commit

Permalink
Drive-by copy edits to StrictFormatStringValidation.
Browse files Browse the repository at this point in the history
DELTA=5 (0 added, 0 deleted, 5 changed)
DELTA_BY_EXTENSION=java=5
RELNOTES: n/a

RELNOTES=n/a

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=215311238
  • Loading branch information
lowasser authored and epmjohnston committed Oct 2, 2018
1 parent a8f7aa3 commit 8f9f0b1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Expand Up @@ -79,7 +79,7 @@ public static ValidationResult validate(
return ValidationResult.create( return ValidationResult.create(
null, null,
String.format( String.format(
"Format strings must be either a literal or a variable. Other expressions" "Format strings must be either literals or variables. Other expressions"
+ " are not valid.\n" + " are not valid.\n"
+ "Invalid format string: %s", + "Invalid format string: %s",
formatStringTree)); formatStringTree));
Expand All @@ -91,7 +91,7 @@ public static ValidationResult validate(
} }


if (formatStringSymbol.getKind() == ElementKind.PARAMETER) { if (formatStringSymbol.getKind() == ElementKind.PARAMETER) {
return validateFormatStringParamter(formatStringTree, formatStringSymbol, args, state); return validateFormatStringParameter(formatStringTree, formatStringSymbol, args, state);
} else { } else {
// The format string is final but not a method parameter or compile time constant. Ensure that // The format string is final but not a method parameter or compile time constant. Ensure that
// it is only assigned to compile time constant values and ensure that any possible assignment // it is only assigned to compile time constant values and ensure that any possible assignment
Expand All @@ -101,7 +101,7 @@ public static ValidationResult validate(
} }


/** Helps {@code validate()} validate a format string that is declared as a method parameter. */ /** Helps {@code validate()} validate a format string that is declared as a method parameter. */
private static ValidationResult validateFormatStringParamter( private static ValidationResult validateFormatStringParameter(
ExpressionTree formatStringTree, ExpressionTree formatStringTree,
Symbol formatStringSymbol, Symbol formatStringSymbol,
List<? extends ExpressionTree> args, List<? extends ExpressionTree> args,
Expand All @@ -110,7 +110,7 @@ private static ValidationResult validateFormatStringParamter(
return ValidationResult.create( return ValidationResult.create(
null, null,
String.format( String.format(
"Format strings must be compile time constant or parameters annotated " "Format strings must be compile time constants or parameters annotated "
+ "@FormatString: %s", + "@FormatString: %s",
formatStringTree)); formatStringTree));
} }
Expand Down Expand Up @@ -176,7 +176,7 @@ private static ValidationResult validateFormatStringVariable(
null, null,
String.format( String.format(
"Variables used as format strings that are not local variables must be compile time" "Variables used as format strings that are not local variables must be compile time"
+ " consant.\n%s is not a local variable and is not compile time constant.", + " constants.\n%s is neither a local variable nor a compile time constant.",
formatStringTree)); formatStringTree));
} }


Expand Down
Expand Up @@ -137,9 +137,9 @@ public void testMatches_failsWhenExpressionGivenForFormatString() {
" public static String formatString() { return \"\";}", " public static String formatString() { return \"\";}",
" public static void callLog() {", " public static void callLog() {",
" String format = \"log: \";", " String format = \"log: \";",
" // BUG: Diagnostic contains: Format strings must be either a literal or a", " // BUG: Diagnostic contains: Format strings must be either literals or",
" log(format + 3);", " log(format + 3);",
" // BUG: Diagnostic contains: Format strings must be either a literal or a", " // BUG: Diagnostic contains: Format strings must be either literals or",
" log(formatString());", " log(formatString());",
" }", " }",
"}") "}")
Expand Down Expand Up @@ -178,12 +178,12 @@ public void testMatches_failsForIncorrectStringParameterUsedWithImplicitFormatSt
"public class FormatStringTestCase {", "public class FormatStringTestCase {",
" @FormatMethod public static void log(@FormatString String s, Object... args) {}", " @FormatMethod public static void log(@FormatString String s, Object... args) {}",
" @FormatMethod public static void callLog1(String format, String s, Object arg) {", " @FormatMethod public static void callLog1(String format, String s, Object arg) {",
" // BUG: Diagnostic contains: Format strings must be compile time constant or", " // BUG: Diagnostic contains: Format strings must be compile time constants or",
" log(s, arg);", " log(s, arg);",
" }", " }",
" @FormatMethod public static void callLog2(String s, @FormatString String format,", " @FormatMethod public static void callLog2(String s, @FormatString String format,",
" Object arg) {", " Object arg) {",
" // BUG: Diagnostic contains: Format strings must be compile time constant or", " // BUG: Diagnostic contains: Format strings must be compile time constants or",
" log(s, arg);", " log(s, arg);",
" }", " }",
"}") "}")
Expand Down Expand Up @@ -273,7 +273,7 @@ public void testMatches_failsForBadCallToConstructor() {
"public class FormatStringTestCase {", "public class FormatStringTestCase {",
" @FormatMethod public FormatStringTestCase(String s, Object... args) {}", " @FormatMethod public FormatStringTestCase(String s, Object... args) {}",
" public static void createTestCase(String s, Object arg) {", " public static void createTestCase(String s, Object arg) {",
" // BUG: Diagnostic contains: Format strings must be compile time constant or", " // BUG: Diagnostic contains: Format strings must be compile time constants or",
" new FormatStringTestCase(s, arg);", " new FormatStringTestCase(s, arg);",
" }", " }",
"}") "}")
Expand Down

0 comments on commit 8f9f0b1

Please sign in to comment.