@Override
public void visitMethod(@NonNull JavaContext context, @Nullable JavaElementVisitor visitor,
@NonNull PsiMethodCallExpression node, @NonNull PsiMethod method) {
JavaEvaluator evaluator = context.getEvaluator();
if (!evaluator.isMemberInClass(method, "android.database.sqlite.SQLiteDatabase")) {
return;
}
int parameterCount = evaluator.getParameterCount(method);
if (parameterCount == 0) {
return;
}
if (!evaluator.parameterHasType(method, 0, TYPE_STRING)) {
return;
}
PsiExpression argument = node.getArgumentList().getExpressions()[0];
String sql = ConstantEvaluator.evaluateString(context, argument, true);
if (sql != null && (sql.startsWith("CREATE TABLE") || sql.startsWith("ALTER TABLE"))
&& sql.matches(".*\\bSTRING\\b.*")) {
String message = "Using column type STRING; did you mean to use TEXT? "
+ "(STRING is a numeric type and its value can be adjusted; for example, "
+ "strings that look like integers can drop leading zeroes. See issue "
+ "explanation for details.)";
context.report(ISSUE, node, context.getLocation(node), message);
}
}
}