use of com.android.tools.lint.detector.api.LintFix in project Signal-Android by WhisperSystems.
the class AlertDialogBuilderDetector method visitConstructor.
@Override
public void visitConstructor(JavaContext context, @NotNull UCallExpression call, @NotNull PsiMethod method) {
JavaEvaluator evaluator = context.getEvaluator();
if (evaluator.isMemberInClass(method, "android.app.AlertDialog.Builder")) {
LintFix fix = quickFixIssueAlertDialogBuilder(call);
context.report(ALERT_DIALOG_BUILDER_USAGE, call, context.getLocation(call), "Using 'android.app.AlertDialog.Builder' instead of com.google.android.material.dialog.MaterialAlertDialogBuilder", fix);
}
if (evaluator.isMemberInClass(method, "androidx.appcompat.app.AlertDialog.Builder")) {
LintFix fix = quickFixIssueAlertDialogBuilder(call);
context.report(ALERT_DIALOG_BUILDER_USAGE, call, context.getLocation(call), "Using 'androidx.appcompat.app.AlertDialog.Builder' instead of com.google.android.material.dialog.MaterialAlertDialogBuilder", fix);
}
}
use of com.android.tools.lint.detector.api.LintFix in project Signal-Android by WhisperSystems.
the class AlertDialogBuilderDetector method quickFixIssueAlertDialogBuilder.
private LintFix quickFixIssueAlertDialogBuilder(@NotNull UCallExpression alertBuilderCall) {
List<UExpression> arguments = alertBuilderCall.getValueArguments();
UExpression context = arguments.get(0);
String fixSource = "new com.google.android.material.dialog.MaterialAlertDialogBuilder";
switch(arguments.size()) {
case 1:
fixSource += String.format("(%s)", context);
break;
case 2:
UExpression themeOverride = arguments.get(1);
fixSource += String.format("(%s, %s)", context, themeOverride);
break;
default:
throw new IllegalStateException("MaterialAlertDialogBuilder overloads should have 1 or 2 arguments");
}
String builderCallSource = alertBuilderCall.asSourceString();
LintFix.GroupBuilder fixGrouper = fix().group();
fixGrouper.add(fix().replace().text(builderCallSource).shortenNames().reformat(true).with(fixSource).build());
return fixGrouper.build();
}
use of com.android.tools.lint.detector.api.LintFix in project Signal-Android by WhisperSystems.
the class SignalLogDetector method visitMethodCall.
@Override
public void visitMethodCall(JavaContext context, @NotNull UCallExpression call, @NotNull PsiMethod method) {
JavaEvaluator evaluator = context.getEvaluator();
if (evaluator.isMemberInClass(method, "android.util.Log")) {
LintFix fix = quickFixIssueLog(call);
context.report(LOG_NOT_SIGNAL, call, context.getLocation(call), "Using 'android.util.Log' instead of a Signal Logger", fix);
}
if (evaluator.isMemberInClass(method, "org.signal.glide.Log")) {
LintFix fix = quickFixIssueLog(call);
context.report(LOG_NOT_SIGNAL, call, context.getLocation(call), "Using 'org.signal.glide.Log' instead of a Signal Logger", fix);
}
if (evaluator.isMemberInClass(method, "org.whispersystems.libsignal.logging.Log")) {
LintFix fix = quickFixIssueLog(call);
context.report(LOG_NOT_APP, call, context.getLocation(call), "Using Signal server logger instead of app level Logger", fix);
}
if (evaluator.isMemberInClass(method, "org.signal.core.util.logging.Log")) {
List<UExpression> arguments = call.getValueArguments();
UExpression tag = arguments.get(0);
if (!(tag instanceof JavaUSimpleNameReferenceExpression || tag instanceof KotlinUSimpleReferenceExpression || tag instanceof KotlinUQualifiedReferenceExpression)) {
context.report(INLINE_TAG, call, context.getLocation(call), "Not using a tag constant");
}
}
}
use of com.android.tools.lint.detector.api.LintFix in project Signal-Android by WhisperSystems.
the class SignalLogDetector method quickFixIssueLog.
private LintFix quickFixIssueLog(@NotNull UCallExpression logCall) {
List<UExpression> arguments = logCall.getValueArguments();
String methodName = logCall.getMethodName();
UExpression tag = arguments.get(0);
String fixSource = "org.signal.core.util.logging.Log.";
switch(arguments.size()) {
case 2:
UExpression msgOrThrowable = arguments.get(1);
fixSource += String.format("%s(%s, %s)", methodName, tag, msgOrThrowable.asSourceString());
break;
case 3:
UExpression msg = arguments.get(1);
UExpression throwable = arguments.get(2);
fixSource += String.format("%s(%s, %s, %s)", methodName, tag, msg.asSourceString(), throwable.asSourceString());
break;
default:
throw new IllegalStateException("Log overloads should have 2 or 3 arguments");
}
String logCallSource = logCall.asSourceString();
LintFix.GroupBuilder fixGrouper = fix().group();
fixGrouper.add(fix().replace().text(logCallSource).shortenNames().reformat(true).with(fixSource).build());
return fixGrouper.build();
}
Aggregations