com.android.tools.lint.detector.api.Category Java Examples

The following examples show how to use com.android.tools.lint.detector.api.Category. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IssueRegistry.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #2
Source File: IssueRegistry.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the available categories
 *
 * @return an iterator for all the categories, never null
 */
@NonNull
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;
}
 
Example #3
Source File: Main.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
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);
    }
}
 
Example #4
Source File: Main.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
private static void showIssues(IssueRegistry registry) {
    List<Issue> issues = registry.getIssues();
    List<Issue> sorted = new ArrayList<Issue>(issues);
    Collections.sort(sorted, new Comparator<Issue>() {
        @Override
        public int compare(Issue issue1, Issue issue2) {
            int d = issue1.getCategory().compareTo(issue2.getCategory());
            if (d != 0) {
                return d;
            }
            d = issue2.getPriority() - issue1.getPriority();
            if (d != 0) {
                return d;
            }

            return issue1.getId().compareTo(issue2.getId());
        }
    });

    System.out.println("Available issues:\n");
    Category previousCategory = null;
    for (Issue issue : sorted) {
        Category category = issue.getCategory();
        if (!category.equals(previousCategory)) {
            String name = category.getFullName();
            System.out.println(name);
            for (int i = 0, n = name.length(); i < n; i++) {
                System.out.print('=');
            }
            System.out.println('\n');
            previousCategory = category;
        }

        describeIssue(issue);
        System.out.println();
    }
}
 
Example #5
Source File: IssueDetector.java    From aircon with MIT License 4 votes vote down vote up
private static Issue createIssue(String id, String briefDesc, String explanation, Severity severity) {
	return Issue.create(id, briefDesc, explanation, Category.CORRECTNESS, 6, severity, new Implementation(AirConUsageDetector.class, Scope.JAVA_FILE_SCOPE));
}
 
Example #6
Source File: HtmlReporter.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
private void writeOverview(List<List<Warning>> related, int missingCount)
        throws IOException {
    // Write issue id summary
    mWriter.write("<table class=\"overview\">\n");                          //$NON-NLS-1$

    String errorUrl = null;
    String warningUrl = null;
    if (!mSimpleFormat) {
        errorUrl = addLocalResources(getErrorIconUrl());
        warningUrl = addLocalResources(getWarningIconUrl());
        mFixUrl = addLocalResources(HtmlReporter.class.getResource("lint-run.png")); //$NON-NLS-1$)
    }

    Category previousCategory = null;
    for (List<Warning> warnings : related) {
        Issue issue = warnings.get(0).issue;

        boolean isError = false;
        for (Warning warning : warnings) {
            if (warning.severity == Severity.ERROR || warning.severity == Severity.FATAL) {
                isError = true;
                break;
            }
        }

        if (issue.getCategory() != previousCategory) {
            mWriter.write("<tr><td></td><td class=\"categoryColumn\">");
            previousCategory = issue.getCategory();
            String categoryName = issue.getCategory().getFullName();
            mWriter.write("<a href=\"#");                        //$NON-NLS-1$
            mWriter.write(categoryName);
            mWriter.write("\">");                                //$NON-NLS-1$
            mWriter.write(categoryName);
            mWriter.write("</a>\n");                             //$NON-NLS-1$
            mWriter.write("</td></tr>");                         //$NON-NLS-1$
            mWriter.write("\n");                                 //$NON-NLS-1$
        }
        mWriter.write("<tr>\n");                                 //$NON-NLS-1$

        // Count column
        mWriter.write("<td class=\"countColumn\">");             //$NON-NLS-1$
        mWriter.write(Integer.toString(warnings.size()));
        mWriter.write("</td>");                                  //$NON-NLS-1$

        mWriter.write("<td class=\"issueColumn\">");             //$NON-NLS-1$

        String imageUrl = isError ? errorUrl : warningUrl;
        if (imageUrl != null) {
            mWriter.write("<img border=\"0\" align=\"top\" src=\""); //$NON-NLS-1$
            mWriter.write(imageUrl);
            mWriter.write("\" alt=\"");
            mWriter.write(isError ? "Error" : "Warning");
            mWriter.write("\" />\n");                            //$NON-NLS-1$
        }

        mWriter.write("<a href=\"#");                            //$NON-NLS-1$
        mWriter.write(issue.getId());
        mWriter.write("\">");                                    //$NON-NLS-1$
        mWriter.write(issue.getId());
        mWriter.write(": ");                                     //$NON-NLS-1$
        mWriter.write(issue.getBriefDescription(HTML));
        mWriter.write("</a>\n");                                 //$NON-NLS-1$

        mWriter.write("</td></tr>\n");
    }

    if (missingCount > 0 && !mClient.isCheckingSpecificIssues()) {
        mWriter.write("<tr><td></td>");                          //$NON-NLS-1$
        mWriter.write("<td class=\"categoryColumn\">");          //$NON-NLS-1$
        mWriter.write("<a href=\"#MissingIssues\">");            //$NON-NLS-1$
        mWriter.write(String.format("Disabled Checks (%1$d)",
                missingCount));

        mWriter.write("</a>\n");                                 //$NON-NLS-1$
        mWriter.write("</td></tr>");                             //$NON-NLS-1$
    }

    mWriter.write("</table>\n");                                 //$NON-NLS-1$
    mWriter.write("<br/>");                                      //$NON-NLS-1$
}