Minor fixes for XML persistence generation.

The Android checkstyle configuration requires exactly the string
"CHECKSTYLE: OFF Generated Code" in its SuppressionCommentFilter.

JLS 4.12.4 says try-with-resources declaration is implicitly final,
hence drop the redundant final modifier in generated code.

Test: manual
Change-Id: Idbb703d950601c32aececfc45e480698657ef764
This commit is contained in:
Hai Zhang
2020-10-06 16:50:50 -07:00
parent 692f27bfd6
commit 785cd3105a

View File

@@ -50,7 +50,7 @@ val FILE_HEADER = """
*/
// Generated by xmlpersistence. DO NOT MODIFY!
// CHECKSTYLE:OFF
// CHECKSTYLE:OFF Generated code
// @formatter:off
""".trimIndent() + "\n\n"
@@ -128,9 +128,7 @@ private fun generateReadMethod(rootField: ClassFieldInfo): MethodSpec =
.addAnnotation(nullableType)
.addModifiers(Modifier.PUBLIC)
.returns(rootField.type)
.addControlFlow(
"try (final \$1T inputStream = mFile.openRead())", FileInputStream::class.java
) {
.addControlFlow("try (\$1T inputStream = mFile.openRead())", FileInputStream::class.java) {
addStatement("final \$1T parser = \$2T.newPullParser()", xmlPullParserType, xmlType)
addStatement("parser.setInput(inputStream, null)")
addStatement("return parse(parser)")