Fix generated code causing warnings

This commit is contained in:
Travis Burtrum 2018-05-11 00:14:58 -04:00
parent 564df7b022
commit 3fb9559ba7
2 changed files with 17 additions and 4 deletions

View File

@ -254,11 +254,19 @@ public class CompileTimeResultSetMapper {
public void toArray(final Writer w, final String[] keys, final TypeMirror componentTypeMirror, MaxRows maxRows, String cal, final String cleaner, final ReflectionFields reflectionFields) throws IOException, ClassNotFoundException { public void toArray(final Writer w, final String[] keys, final TypeMirror componentTypeMirror, MaxRows maxRows, String cal, final String cleaner, final ReflectionFields reflectionFields) throws IOException, ClassNotFoundException {
final String returnTypeString = componentTypeMirror.toString(); final String returnTypeString = componentTypeMirror.toString();
writeCollection(w, keys, "java.util.List<" + returnTypeString + ">", "java.util.ArrayList", componentTypeMirror, maxRows, cal, cleaner, reflectionFields); writeCollection(w, keys, "java.util.List<" + returnTypeString + ">", "java.util.ArrayList", componentTypeMirror, maxRows, cal, cleaner, reflectionFields);
w.write("\t\t\treturn _colret.toArray(new "); // have to strip generics to avoid "generic array creation" compilation failure
// have to strip generics to avoid "generic array creation" compilation failure
final int indexOfGeneric = returnTypeString.indexOf('<'); final int indexOfGeneric = returnTypeString.indexOf('<');
w.write(indexOfGeneric < 0 ? returnTypeString : returnTypeString.substring(0, indexOfGeneric)); if(indexOfGeneric < 0) {
w.write("[_colret.size()]);\n"); w.write("\t\t\treturn _colret.toArray(new ");
w.write(returnTypeString);
w.write("[_colret.size()]);\n");
} else {
w.write("\t\t\t@SuppressWarnings(\"unchecked\")\n");
w.append("\t\t\tfinal ").append(returnTypeString).append("[] _warnret = _colret.toArray(new ");
w.write(returnTypeString.substring(0, indexOfGeneric));
w.write("[_colret.size()]);\n");
w.write("\t\t\treturn _warnret;\n");
}
} }
public void toListIterator(final Writer w, final String[] keys, final TypeMirror componentTypeMirror, MaxRows maxRows, String cal, final String cleaner, final ReflectionFields reflectionFields) throws IOException, ClassNotFoundException { public void toListIterator(final Writer w, final String[] keys, final TypeMirror componentTypeMirror, MaxRows maxRows, String cal, final String cleaner, final ReflectionFields reflectionFields) throws IOException, ClassNotFoundException {

View File

@ -268,6 +268,10 @@
<exclude>**/PrestoPersonDAOTest.java</exclude> <exclude>**/PrestoPersonDAOTest.java</exclude>
<exclude>**/PrestoSQLParserTest.java</exclude> <exclude>**/PrestoSQLParserTest.java</exclude>
</testExcludes> </testExcludes>
<compilerArgs>
<compilerArg>-Xlint:unchecked</compilerArg>
<compilerArg>-XDignore.symbol.file</compilerArg>
</compilerArgs>
</configuration> </configuration>
<goals> <goals>
<goal>testCompile</goal> <goal>testCompile</goal>
@ -324,6 +328,7 @@
<compilerArgs> <compilerArgs>
<compilerArg>-parameters</compilerArg> <compilerArg>-parameters</compilerArg>
<compilerArg>-Xlint:unchecked</compilerArg> <compilerArg>-Xlint:unchecked</compilerArg>
<compilerArg>-XDignore.symbol.file</compilerArg>
</compilerArgs> </compilerArgs>
</configuration> </configuration>
<goals> <goals>