/** * Returns true if the given id represents a valid issue id * * @param id the id to be checked * @return true if the given id is valid */ public final boolean isIssueId(String id) { return getIssue(id) != null; }
@NonNull @Override public List<Issue> getIssues() { if (issues == null) { List<Issue> issues = Lists.newArrayListWithExpectedSize(200); for (IssueRegistry registry : registries) { issues.addAll(registry.getIssues()); } this.issues = issues; } return issues; } }
private static void displayValidIds(IssueRegistry registry, PrintStream out) { List<Category> categories = registry.getCategories(); out.println("Valid issue categories:"); for (Category category : categories) { out.println(" " + category.getFullName()); } out.println(); List<Issue> issues = registry.getIssues(); out.println("Valid issue id's:"); for (Issue issue : issues) { listIssue(out, issue); } }
String[] ids = args[++index].split(","); for (String id : ids) { if (registry.isCategoryName(id)) { for (Issue issue : registry.getIssues()) { String[] ids = args[++index].split(","); for (String id : ids) { if (registry.isCategoryName(id)) { for (Issue issue : registry.getIssues()) { } else if (registry.isIssueId(id)) { describeIssue(registry.getIssue(id)); System.out.println(); } else { String[] ids = args[++index].split(","); for (String id : ids) { if (registry.isCategoryName(id)) { for (Issue issue : registry.getIssues()) { } else if (!registry.isIssueId(id)) { System.err.println("Invalid id or category \"" + id + "\".\n"); displayValidIds(registry, System.err); String[] ids = args[++index].split(","); for (String id : ids) {
/** * Returns all available issues of a given scope (regardless of whether * they are actually enabled for a given configuration etc) * * @param scope the applicable scope set * @return a list of issues */ @NonNull protected List<Issue> getIssuesForScope(@NonNull EnumSet<Scope> scope) { List<Issue> list = scopeIssues.get(scope); if (list == null) { List<Issue> issues = getIssues(); if (scope.equals(Scope.ALL)) { list = issues; } else { list = new ArrayList<>(getIssueCapacity(scope)); for (Issue issue : issues) { // Determine if the scope matches if (issue.getImplementation().isAdequate(scope)) { list.add(issue); } } } scopeIssues.put(scope, list); } return list; }
/** * Returns true if the given category is a valid category * * @param name the category name to be checked * @return true if the given string is a valid category */ public final boolean isCategoryName(String name) { for (Category c : getCategories()) { if (c.getName().equals(name) || c.getFullName().equals(name)) { return true; } } return false; }
/** * Reset the registry such that it recomputes its available issues. * <p> * NOTE: This is only intended for testing purposes. */ @VisibleForTesting public static void reset() { IssueRegistry.reset(); } }
private void computeDetectors(Project project) { // Ensure that the current visitor is recomputed mCurrentFolderType = null; mCurrentVisitor = null; Configuration configuration = project.getConfiguration(); mScopeDetectors = new HashMap<Scope, List<Detector>>(); mApplicableDetectors = mRegistry.createDetectors(mClient, configuration, mScope, mScopeDetectors); validateScopeList(); }
/** * Returns the available categories * * @return an iterator for all the categories, never null */ @SuppressWarnings("AssignmentToStaticFieldFromInstanceMethod") @NonNull public List<Category> getCategories() { List<Category> categories = IssueRegistry.categories; if (categories == null) { synchronized (IssueRegistry.class) { categories = IssueRegistry.categories; if (categories == null) { IssueRegistry.categories = categories = Collections.unmodifiableList(createCategoryList()); } } } return categories; }
/** * Returns true if the given category is a valid category * * @param name the category name to be checked * @return true if the given string is a valid category */ public final boolean isCategoryName(@NonNull String name) { for (Category category : getCategories()) { if (category.getName().equals(name) || category.getFullName().equals(name)) { return true; } } return false; }
/** * Reset the registry such that it recomputes its available issues. * <p> * NOTE: This is only intended for testing purposes. */ @VisibleForTesting public static void reset() { IssueRegistry.reset(); } }
private void computeDetectors(@NonNull Project project) { // Ensure that the current visitor is recomputed currentFolderType = null; currentVisitor = null; Configuration configuration = project.getConfiguration(this); scopeDetectors = new EnumMap<>(Scope.class); applicableDetectors = registry.createDetectors(client, configuration, scope, scopeDetectors); validateScopeList(); }
@NonNull private List<Category> createCategoryList() { Set<Category> categorySet = Sets.newHashSetWithExpectedSize(20); for (Issue issue : getIssues()) { categorySet.add(issue.getCategory()); } List<Category> sorted = new ArrayList<>(categorySet); Collections.sort(sorted); return sorted; }
/** * Returns true if the given id represents a valid issue id * * @param id the id to be checked * @return true if the given id is valid */ public final boolean isIssueId(@NonNull String id) { return getIssue(id) != null; }
@NonNull public static JarFileIssueRegistry get(@NonNull LintClient client, @NonNull File jarFile) throws IOException, ClassNotFoundException, IllegalAccessException, InstantiationException { if (cache == null) { cache = new HashMap<>(); } else { SoftReference<JarFileIssueRegistry> reference = cache.get(jarFile); if (reference != null) { JarFileIssueRegistry registry = reference.get(); if (registry != null) { return registry; } } } // Ensure that the scope-to-detector map doesn't return stale results IssueRegistry.reset(); JarFileIssueRegistry registry = new JarFileIssueRegistry(client, jarFile); cache.put(jarFile, new SoftReference<>(registry)); return registry; }
/** * Returns the issue for the given id, or null if it's not a valid id * * @param id the id to be checked * @return the corresponding issue, or null */ public final Issue getIssue(String id) { if (sIdToIssue == null) { List<Issue> issues = getIssues(); sIdToIssue = new HashMap<String, Issue>(issues.size()); for (Issue issue : issues) { sIdToIssue.put(issue.getId(), issue); } } return sIdToIssue.get(id); } }
private void validateIssueIds(@Nullable Project project, @NonNull IssueRegistry registry, @Nullable Collection<String> ids) { if (ids != null) { for (String id : ids) { if (registry.getIssue(id) == null) { reportNonExistingIssueId(project, id); } } } }
/** * Returns the available categories * * @return an iterator for all the categories, never null */ public List<Category> getCategories() { if (sCategories == null) { final Set<Category> categories = new HashSet<Category>(); for (Issue issue : getIssues()) { categories.add(issue.getCategory()); } List<Category> sorted = new ArrayList<Category>(categories); Collections.sort(sorted); sCategories = Collections.unmodifiableList(sorted); } return sCategories; }
private boolean checkSuppressLint(@NonNull PsiAnnotation node, @NonNull String id) { IssueRegistry registry = mContext.getDriver().getRegistry(); Issue issue = registry.getIssue(id); // Special-case the ApiDetector issue, since it does both source file analysis // only on field references, and class file analysis on the rest, so we allow // annotations outside of methods only on fields if (issue != null && !issue.getImplementation().getScope().contains(Scope.JAVA_FILE) || issue == ApiDetector.UNSUPPORTED) { // This issue doesn't have AST access: annotations are not // available for local variables or parameters PsiElement scope = getAnnotationScope(node); mContext.report(INSIDE_METHOD, scope, mContext.getLocation(node), String.format( "The `@SuppressLint` annotation cannot be used on a local " + "variable with the lint check '%1$s': move out to the " + "surrounding method", id)); return false; } return true; } }
@NonNull private Map<String, Issue> createIdToIssueMap() { List<Issue> issues = getIssues(); Map<String, Issue> map = Maps.newHashMapWithExpectedSize(issues.size() + 2); for (Issue issue : issues) { map.put(issue.getId(), issue); } map.put(PARSER_ERROR.getId(), PARSER_ERROR); map.put(LINT_ERROR.getId(), LINT_ERROR); map.put(BASELINE.getId(), BASELINE); return map; }