mirror of
https://github.com/moparisthebest/JdbcMapper
synced 2024-11-25 18:32:18 -05:00
In JdbcMapper, error out on unused parameters
This commit is contained in:
parent
f14b87203a
commit
c1139447e4
@ -216,6 +216,7 @@ public class JdbcMapperProcessor extends AbstractProcessor {
|
|||||||
if (++count != numParams)
|
if (++count != numParams)
|
||||||
w.write(", ");
|
w.write(", ");
|
||||||
}
|
}
|
||||||
|
final Map<String, VariableElement> unusedParams = new HashMap<String, VariableElement>(paramMap);
|
||||||
|
|
||||||
// throws?
|
// throws?
|
||||||
w.write(")");
|
w.write(")");
|
||||||
@ -242,6 +243,7 @@ public class JdbcMapperProcessor extends AbstractProcessor {
|
|||||||
processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, String.format("@JdbcMapper.SQL sql has bind param '%s' not in method parameter list", paramName), methodElement);
|
processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, String.format("@JdbcMapper.SQL sql has bind param '%s' not in method parameter list", paramName), methodElement);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
unusedParams.remove(paramName);
|
||||||
final String inColumnName = bindParamMatcher.group(2);
|
final String inColumnName = bindParamMatcher.group(2);
|
||||||
if(inColumnName == null) {
|
if(inColumnName == null) {
|
||||||
bindParams.add(bindParam);
|
bindParams.add(bindParam);
|
||||||
@ -270,6 +272,10 @@ public class JdbcMapperProcessor extends AbstractProcessor {
|
|||||||
}
|
}
|
||||||
bindParamMatcher.appendTail(sb);
|
bindParamMatcher.appendTail(sb);
|
||||||
sqlStatement = sb.toString();
|
sqlStatement = sb.toString();
|
||||||
|
|
||||||
|
for(final Map.Entry<String, VariableElement> unusedParam : unusedParams.entrySet()) {
|
||||||
|
processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, String.format("@JdbcMapper.SQL method has unused parameter '%s'", unusedParam.getKey()), unusedParam.getValue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final SQLParser parsedSQl = parser.parse(sqlStatement);
|
final SQLParser parsedSQl = parser.parse(sqlStatement);
|
||||||
|
Loading…
Reference in New Issue
Block a user