Android Lint: check for array initializer in SuppressLint

This commit is contained in:
Vyacheslav Gerasimov
2017-08-29 21:56:57 +03:00
parent f4da6c2cc6
commit be900a76d8
2 changed files with 24 additions and 5 deletions
+7 -1
View File
@@ -61,7 +61,13 @@ class ToastTest(context: Context) : Activity() {
private fun checkSuppress2(context: Context) {
@android.annotation.SuppressLint("ShowToast")
val toast = Toast.makeText(this, "MyToast", Toast.LENGTH_LONG)
val toast1 = Toast.makeText(this, "MyToast", Toast.LENGTH_LONG)
@android.annotation.SuppressLint("ShowToast", "Lorem ipsum")
val toast2 = Toast.makeText(this, "MyToast", Toast.LENGTH_LONG)
@android.annotation.SuppressLint(value = "ShowToast")
val toast3 = Toast.makeText(this, "MyToast", Toast.LENGTH_LONG)
}
class R {
@@ -92,6 +92,7 @@ import org.jetbrains.org.objectweb.asm.tree.FieldNode;
import org.jetbrains.org.objectweb.asm.tree.InsnList;
import org.jetbrains.org.objectweb.asm.tree.MethodInsnNode;
import org.jetbrains.org.objectweb.asm.tree.MethodNode;
import org.jetbrains.uast.util.UastExpressionUtils;
import org.w3c.dom.Attr;
import org.w3c.dom.Element;
@@ -2841,10 +2842,22 @@ public class LintDriver {
if (fqcn != null && (fqcn.equals(FQCN_SUPPRESS_LINT)
|| fqcn.equals(SUPPRESS_WARNINGS_FQCN)
|| fqcn.equals(SUPPRESS_LINT))) { // when missing imports
for (UNamedExpression attribute : annotation.getAttributeValues()) {
Object value = attribute.getExpression().evaluate();
if (value instanceof String && isSuppressed(issue, (String) value)) {
return true;
UExpression valueAttributeExpression = annotation.findAttributeValue("value");
if (valueAttributeExpression != null) {
if (UastExpressionUtils.isArrayInitializer(valueAttributeExpression)) {
UCallExpression arrayInitializer = (UCallExpression) valueAttributeExpression;
for (UExpression issueIdExpression : arrayInitializer.getValueArguments()) {
Object value = issueIdExpression.evaluate();
if (value instanceof String && isSuppressed(issue, (String) value)) {
return true;
}
}
}
else {
Object value = valueAttributeExpression.evaluate();
if (value instanceof String && isSuppressed(issue, (String) value)) {
return true;
}
}
}
}