use of org.jetbrains.uast.UExpression in project kotlin by JetBrains.
the class JavaScriptInterfaceDetector method visitMethod.
@Override
public void visitMethod(@NonNull JavaContext context, @Nullable UastVisitor visitor, @NonNull UCallExpression call, @NonNull UMethod method) {
if (context.getMainProject().getTargetSdk() < 17) {
return;
}
List<UExpression> arguments = call.getValueArguments();
if (arguments.size() != 2) {
return;
}
JavaEvaluator evaluator = context.getEvaluator();
if (!JavaEvaluator.isMemberInClass(method, WEB_VIEW_CLS)) {
return;
}
UExpression first = arguments.get(0);
PsiType evaluated = TypeEvaluator.evaluate(context, first);
if (evaluated instanceof PsiClassType) {
PsiClassType classType = (PsiClassType) evaluated;
PsiClass cls = classType.resolve();
if (cls == null) {
return;
}
if (isJavaScriptAnnotated(cls)) {
return;
}
Location location = context.getUastNameLocation(call);
String message = String.format("None of the methods in the added interface (%1$s) have been annotated " + "with `@android.webkit.JavascriptInterface`; they will not " + "be visible in API 17", cls.getName());
context.report(ISSUE, call, location, message);
}
}
use of org.jetbrains.uast.UExpression in project kotlin by JetBrains.
the class LayoutInflationDetector method visitMethod.
@Override
public void visitMethod(@NonNull JavaContext context, @Nullable UastVisitor visitor, @NonNull UCallExpression call, @NonNull UMethod method) {
assert method.getName().equals(INFLATE);
if (call.getReceiver() == null) {
return;
}
List<UExpression> arguments = call.getValueArguments();
if (arguments.size() < 2) {
return;
}
UExpression second = arguments.get(1);
if (!UastLiteralUtils.isNullLiteral(second)) {
return;
}
UExpression first = arguments.get(0);
AndroidReference androidReference = UastLintUtils.toAndroidReferenceViaResolve(first);
if (androidReference == null) {
return;
}
String layoutName = androidReference.getName();
if (context.getScope().contains(Scope.RESOURCE_FILE)) {
// incrementally
if (!context.getDriver().isSuppressed(context, ISSUE, call)) {
if (mPendingErrors == null) {
mPendingErrors = Lists.newArrayList();
}
Location location = context.getUastLocation(second);
mPendingErrors.add(Pair.of(layoutName, location));
}
} else if (hasLayoutParams(context, layoutName)) {
context.report(ISSUE, call, context.getUastLocation(second), ERROR_MESSAGE);
}
}
use of org.jetbrains.uast.UExpression in project kotlin by JetBrains.
the class NonInternationalizedSmsDetector method visitMethod.
@Override
public void visitMethod(@NonNull JavaContext context, @Nullable UastVisitor visitor, @NonNull UCallExpression call, @NonNull UMethod method) {
if (call.getReceiver() == null) {
// "sendTextMessage"/"sendMultipartTextMessage" in the code with no operand
return;
}
List<UExpression> args = call.getValueArguments();
if (args.size() != 5) {
return;
}
UExpression destinationAddress = args.get(0);
if (!(destinationAddress instanceof ULiteralExpression)) {
return;
}
Object literal = ((ULiteralExpression) destinationAddress).getValue();
if (!(literal instanceof String)) {
return;
}
String number = (String) literal;
if (number.startsWith("+")) {
//$NON-NLS-1$
return;
}
context.report(ISSUE, call, context.getUastLocation(destinationAddress), "To make sure the SMS can be sent by all users, please start the SMS number " + "with a + and a country code or restrict the code invocation to people in the " + "country you are targeting.");
}
use of org.jetbrains.uast.UExpression in project kotlin by JetBrains.
the class ReadParcelableDetector method visitMethod.
@Override
public void visitMethod(@NonNull JavaContext context, @Nullable UastVisitor visitor, @NonNull UCallExpression node, @NonNull UMethod method) {
PsiClass containingClass = method.getContainingClass();
if (containingClass == null) {
return;
}
if (!(CLASS_PARCEL.equals(containingClass.getQualifiedName()))) {
return;
}
List<UExpression> expressions = node.getValueArguments();
int argumentCount = expressions.size();
if (argumentCount == 0) {
String message = String.format("Using the default class loader " + "will not work if you are restoring your own classes. Consider " + "using for example `%1$s(getClass().getClassLoader())` instead.", node.getMethodName());
Location location = context.getUastLocation(node);
context.report(ISSUE, node, location, message);
} else if (argumentCount == 1) {
UExpression parameter = expressions.get(0);
if (UastLiteralUtils.isNullLiteral(parameter)) {
String message = "Passing null here (to use the default class loader) " + "will not work if you are restoring your own classes. Consider " + "using for example `getClass().getClassLoader()` instead.";
Location location = context.getUastLocation(node);
context.report(ISSUE, node, location, message);
}
}
}
use of org.jetbrains.uast.UExpression 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