boolean flag = annotation.getValue(TYPE_DEF_FLAG_ATTRIBUTE) == Boolean.TRUE; checkTypeDefConstant(context, annotation, argument, null, flag); } else if (signature.equals(STRING_DEF_ANNOTATION)) {
private static void checkResult(@NonNull JavaContext context, @NonNull MethodInvocation node, @NonNull ResolvedAnnotation annotation) { if (node.getParent() instanceof ExpressionStatement) { String methodName = node.astName().astValue(); Object suggested = annotation.getValue(ATTR_SUGGEST); // Failing to check permissions is a potential security issue (and had an existing // dedicated issue id before which people may already have configured with a // custom severity in their LintOptions etc) so continue to use that issue // (which also has category Security rather than Correctness) for these: Issue issue = CHECK_RESULT; if (methodName.startsWith("check") && methodName.contains("Permission")) { issue = CHECK_PERMISSION; } String message = String.format("The result of `%1$s` is not used", methodName); if (suggested != null) { // TODO: Resolve suggest attribute (e.g. prefix annotation class if it starts // with "#" etc? message = String.format( "The result of `%1$s` is not used; did you mean to call `%2$s`?", methodName, suggested.toString()); } context.report(issue, node, context.getLocation(node), message); } }
private static long getLongAttribute(@NonNull ResolvedAnnotation annotation, @NonNull String name, long defaultValue) { Object value = annotation.getValue(name); if (value instanceof Number) { return ((Number) value).longValue(); } return defaultValue; }
@Nullable Context context, @NonNull ResolvedAnnotation annotation) { String value = (String)annotation.getValue(ATTR_VALUE); if (value != null && !value.isEmpty()) { for (int i = 0, n = value.length(); i < n; i++) { Object v = annotation.getValue(ATTR_ANY_OF); if (v != null) { if (v instanceof String[]) { v = annotation.getValue(ATTR_ALL_OF); if (v != null) { if (v instanceof String[]) {
/** * Returns whether this requirement is conditional, meaning that there are * some circumstances in which the requirement is not necessary. For * example, consider * {@code android.app.backup.BackupManager.dataChanged(java.lang.String)} . * Here the {@code android.permission.BACKUP} is required but only if the * argument is not your own package. * <p> * This is used to handle permissions differently between the "missing" and * "unused" checks. When checking for missing permissions, we err on the * side of caution: if you are missing a permission, but the permission is * conditional, you may not need it so we may not want to complain. However, * when looking for unused permissions, we don't want to flag the * conditional permissions as unused since they may be required. * * @return true if this requirement is conditional */ public boolean isConditional() { Object o = annotation.getValue(ATTR_CONDITIONAL); if (o instanceof Boolean) { return (Boolean)o; } return false; }
@Nullable public Object getValue() { return getValue(ATTR_VALUE); }
private static void checkTypeDefConstant(@NonNull JavaContext context, @NonNull ResolvedAnnotation annotation, @NonNull Node argument, @Nullable Node errorNode, boolean flag, Object value) { Object allowed = annotation.getValue(); if (allowed instanceof Object[]) { Object[] allowedValues = (Object[]) allowed; for (Object o : allowedValues) { if (o.equals(value)) { return; } } reportTypeDef(context, argument, errorNode, flag, allowedValues); } }
private static double getDoubleAttribute(@NonNull ResolvedAnnotation annotation, @NonNull String name, double defaultValue) { Object value = annotation.getValue(name); if (value instanceof Number) { return ((Number) value).doubleValue(); } return defaultValue; }
private static void reportTypeDef(@NonNull JavaContext context, @NonNull ResolvedAnnotation annotation, @NonNull Node argument, @Nullable Node errorNode) { Object allowed = annotation.getValue(); if (allowed instanceof Object[]) { Object[] allowedValues = (Object[]) allowed; reportTypeDef(context, argument, errorNode, false, allowedValues); } }
private static boolean getBoolean(@NonNull ResolvedAnnotation annotation, @NonNull String name, boolean defaultValue) { Object value = annotation.getValue(name); if (value instanceof Boolean) { return ((Boolean) value); } return defaultValue; }