Ejemplo n.º 1
0
 private static void ensureAtLeast(
     @NonNull JavaContext context, @NonNull UCallExpression node, int parameter, long min) {
   UExpression argument = node.getValueArguments().get(parameter);
   long value = getLongValue(context, argument);
   if (value < min) {
     String message =
         String.format(
             "Value will be forced up to %1$d as of Android 5.1; "
                 + "don't rely on this to be exact",
             min);
     context.report(ISSUE, argument, context.getUastLocation(argument), message);
   }
 }
 @Override
 public void visitReference(
     @NonNull JavaContext context,
     @Nullable UastVisitor visitor,
     @NonNull UReferenceExpression reference,
     @NonNull PsiElement resolved) {
   if (resolved instanceof PsiField
       && JavaEvaluator.isMemberInClass((PsiField) resolved, "android.view.MenuItem")) {
     if ("SHOW_AS_ACTION_ALWAYS".equals(((PsiField) resolved).getName())) {
       if (context.getDriver().isSuppressed(context, ISSUE, reference)) {
         return;
       }
       if (mAlwaysFields == null) {
         mAlwaysFields = new ArrayList<Location>();
       }
       mAlwaysFields.add(context.getUastLocation(reference));
     } else {
       mHasIfRoomRefs = true;
     }
   }
 }
Ejemplo n.º 3
0
 @Override
 public void visitMethod(
     @NonNull JavaContext context,
     @Nullable UastVisitor visitor,
     @NonNull UCallExpression node,
     @NonNull UMethod method) {
   JavaEvaluator evaluator = context.getEvaluator();
   if (evaluator.isMemberInClass(method, "android.app.AlarmManager")
       && evaluator.getParameterCount(method) == 4) {
     ensureAtLeast(context, node, 1, 5000L);
     ensureAtLeast(context, node, 2, 60000L);
   }
 }