Java Code Examples for com.android.tools.lint.detector.api.Severity#ERROR

The following examples show how to use com.android.tools.lint.detector.api.Severity#ERROR . 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: LintCliClient.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@NonNull
@Override
public Severity getSeverity(@NonNull Issue issue) {
    Severity severity = computeSeverity(issue);

    if (mFatalOnly && severity != Severity.FATAL) {
        return Severity.IGNORE;
    }

    if (mFlags.isWarningsAsErrors() && severity == Severity.WARNING) {
        severity = Severity.ERROR;
    }

    if (mFlags.isIgnoreWarnings() && severity == Severity.WARNING) {
        severity = Severity.IGNORE;
    }

    return severity;
}
 
Example 2
Source File: HtmlReporter.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
private void writeIssueMetadata(Issue issue, Severity severity, String disabledBy)
        throws IOException {
    mWriter.write("<div class=\"metadata\">");               //$NON-NLS-1$

    if (mClient.getRegistry() instanceof BuiltinIssueRegistry) {
        boolean adtHasFix = QuickfixHandler.ADT.hasAutoFix(issue);
        boolean studioHasFix = QuickfixHandler.STUDIO.hasAutoFix(issue);
        if (adtHasFix || studioHasFix) {
            String adt = "Eclipse/ADT";
            String studio = "Android Studio/IntelliJ";
            String tools = adtHasFix && studioHasFix
                    ? (adt + " & " + studio) : studioHasFix ? studio : adt;
            mWriter.write("Note: This issue has an associated quickfix operation in " + tools);
            if (mFixUrl != null) {
                mWriter.write("&nbsp;<img alt=\"Fix\" border=\"0\" align=\"top\" src=\""); //$NON-NLS-1$
                mWriter.write(mFixUrl);
                mWriter.write("\" />\n");                            //$NON-NLS-1$
            }

            mWriter.write("<br>\n");
        }
    }

    if (disabledBy != null) {
        mWriter.write(String.format("Disabled By: %1$s<br/>\n", disabledBy));
    }

    mWriter.write("Priority: ");
    mWriter.write(String.format("%1$d / 10", issue.getPriority()));
    mWriter.write("<br/>\n");                                //$NON-NLS-1$
    mWriter.write("Category: ");
    mWriter.write(issue.getCategory().getFullName());
    mWriter.write("</div>\n");                               //$NON-NLS-1$

    mWriter.write("Severity: ");
    if (severity == Severity.ERROR || severity == Severity.FATAL) {
        mWriter.write("<span class=\"error\">");             //$NON-NLS-1$
    } else if (severity == Severity.WARNING) {
        mWriter.write("<span class=\"warning\">");           //$NON-NLS-1$
    } else {
        mWriter.write("<span>");                             //$NON-NLS-1$
    }
    appendEscapedText(severity.getDescription());
    mWriter.write("</span>");                                //$NON-NLS-1$

    mWriter.write("<div class=\"summary\">\n");              //$NON-NLS-1$
    mWriter.write("Explanation: ");
    String description = issue.getBriefDescription(HTML);
    mWriter.write(description);
    if (!description.isEmpty()
            && Character.isLetter(description.charAt(description.length() - 1))) {
        mWriter.write('.');
    }
    mWriter.write("</div>\n");                               //$NON-NLS-1$
    mWriter.write("<div class=\"explanation\">\n");          //$NON-NLS-1$
    String explanationHtml = issue.getExplanation(HTML);
    mWriter.write(explanationHtml);
    mWriter.write("\n</div>\n");                             //$NON-NLS-1$;
    List<String> moreInfo = issue.getMoreInfo();
    mWriter.write("<br/>");                                  //$NON-NLS-1$
    mWriter.write("<div class=\"moreinfo\">");               //$NON-NLS-1$
    mWriter.write("More info: ");
    int count = moreInfo.size();
    if (count > 1) {
        mWriter.write("<ul>");                               //$NON-NLS-1$
    }
    for (String uri : moreInfo) {
        if (count > 1) {
            mWriter.write("<li>");                           //$NON-NLS-1$
        }
        mWriter.write("<a href=\"");                         //$NON-NLS-1$
        mWriter.write(uri);
        mWriter.write("\">"    );                            //$NON-NLS-1$
        mWriter.write(uri);
        mWriter.write("</a>\n");                             //$NON-NLS-1$
    }
    if (count > 1) {
        mWriter.write("</ul>");                              //$NON-NLS-1$
    }
    mWriter.write("</div>");                                 //$NON-NLS-1$

    mWriter.write("<br/>");                                  //$NON-NLS-1$
    mWriter.write(String.format(
            "To suppress this error, use the issue id \"%1$s\" as explained in the " +
            "%2$sSuppressing Warnings and Errors%3$s section.",
            issue.getId(),
            "<a href=\"#SuppressInfo\">", "</a>"));          //$NON-NLS-1$ //$NON-NLS-2$
    mWriter.write("<br/>\n");
}
 
Example 3
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$
}