Search in sources :

Example 1 with BuiltinIssueRegistry

use of com.android.tools.lint.checks.BuiltinIssueRegistry in project android by JetBrains.

the class TemplateTest method assertLintsCleanly.

private static void assertLintsCleanly(@NotNull Project project, @NotNull Severity maxSeverity, @NotNull Set<Issue> ignored) throws Exception {
    BuiltinIssueRegistry registry = new LintIdeIssueRegistry();
    Map<Issue, Map<File, List<ProblemData>>> map = new HashMap<>();
    LintIdeClient client = LintIdeClient.forBatch(project, map, new AnalysisScope(project), registry.getIssues());
    LintDriver driver = new LintDriver(registry, client);
    List<Module> modules = Arrays.asList(ModuleManager.getInstance(project).getModules());
    LintRequest request = new LintIdeRequest(client, project, null, modules, false);
    EnumSet<Scope> scope = EnumSet.allOf(Scope.class);
    scope.remove(Scope.CLASS_FILE);
    scope.remove(Scope.ALL_CLASS_FILES);
    scope.remove(Scope.JAVA_LIBRARIES);
    request.setScope(scope);
    driver.analyze(request);
    if (!map.isEmpty()) {
        for (Map<File, List<ProblemData>> fileListMap : map.values()) {
            for (Map.Entry<File, List<ProblemData>> entry : fileListMap.entrySet()) {
                File file = entry.getKey();
                List<ProblemData> problems = entry.getValue();
                for (ProblemData problem : problems) {
                    Issue issue = problem.getIssue();
                    if (ignored.contains(issue)) {
                        continue;
                    }
                    if (issue.getDefaultSeverity().compareTo(maxSeverity) < 0) {
                        fail("Found lint issue " + issue.getId() + " with severity " + issue.getDefaultSeverity() + " in " + file + " at " + problem.getTextRange() + ": " + problem.getMessage());
                    }
                }
            }
        }
    }
}
Also used : Issue(com.android.tools.lint.detector.api.Issue) LintIdeClient(com.android.tools.idea.lint.LintIdeClient) ProblemData(org.jetbrains.android.inspections.lint.ProblemData) AnalysisScope(com.intellij.analysis.AnalysisScope) LintRequest(com.android.tools.lint.client.api.LintRequest) Scope(com.android.tools.lint.detector.api.Scope) AnalysisScope(com.intellij.analysis.AnalysisScope) BuiltinIssueRegistry(com.android.tools.lint.checks.BuiltinIssueRegistry) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile) File(java.io.File) LintIdeIssueRegistry(com.android.tools.idea.lint.LintIdeIssueRegistry) LintIdeRequest(com.android.tools.idea.lint.LintIdeRequest) LintDriver(com.android.tools.lint.client.api.LintDriver)

Example 2 with BuiltinIssueRegistry

use of com.android.tools.lint.checks.BuiltinIssueRegistry in project android by JetBrains.

the class LintInspectionDescriptionLinkHandler method getDescription.

@Override
public String getDescription(@NotNull final String refSuffix, @NotNull final Editor editor) {
    final Project project = editor.getProject();
    if (project == null) {
        LOG.error(editor);
        return null;
    }
    final PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
    if (file == null) {
        return null;
    }
    Issue issue = new BuiltinIssueRegistry().getIssue(refSuffix);
    if (issue != null) {
        String html = issue.getExplanation(TextFormat.HTML);
        // IntelliJ seems to treat newlines in the HTML as needing to also be converted to <br> (whereas
        // Lint includes these for HTML readability but they shouldn't add additional lines since it has
        // already added <br> as well) so strip these out
        html = html.replace("\n", "");
        return html;
    }
    // TODO: What about custom registries for custom rules, AARs etc?
    LOG.warn("No description for inspection '" + refSuffix + "'");
    return InspectionsBundle.message("inspection.tool.description.under.construction.text");
}
Also used : Project(com.intellij.openapi.project.Project) Issue(com.android.tools.lint.detector.api.Issue) PsiFile(com.intellij.psi.PsiFile) BuiltinIssueRegistry(com.android.tools.lint.checks.BuiltinIssueRegistry)

Example 3 with BuiltinIssueRegistry

use of com.android.tools.lint.checks.BuiltinIssueRegistry in project android by JetBrains.

the class IssueIdConverter method getIdSet.

@NotNull
public static ImmutableMap<String, Issue> getIdSet() {
    if (ourIssues == null) {
        final ImmutableMap.Builder<String, Issue> builder = ImmutableMap.builder();
        for (Issue issue : new BuiltinIssueRegistry().getIssues()) {
            builder.put(issue.getId(), issue);
        }
        ourIssues = builder.build();
    }
    return ourIssues;
}
Also used : Issue(com.android.tools.lint.detector.api.Issue) BuiltinIssueRegistry(com.android.tools.lint.checks.BuiltinIssueRegistry) ImmutableMap(com.google.common.collect.ImmutableMap) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

BuiltinIssueRegistry (com.android.tools.lint.checks.BuiltinIssueRegistry)3 Issue (com.android.tools.lint.detector.api.Issue)3 LintIdeClient (com.android.tools.idea.lint.LintIdeClient)1 LintIdeIssueRegistry (com.android.tools.idea.lint.LintIdeIssueRegistry)1 LintIdeRequest (com.android.tools.idea.lint.LintIdeRequest)1 LintDriver (com.android.tools.lint.client.api.LintDriver)1 LintRequest (com.android.tools.lint.client.api.LintRequest)1 Scope (com.android.tools.lint.detector.api.Scope)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 AnalysisScope (com.intellij.analysis.AnalysisScope)1 Module (com.intellij.openapi.module.Module)1 Project (com.intellij.openapi.project.Project)1 VfsUtilCore.virtualToIoFile (com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiFile (com.intellij.psi.PsiFile)1 File (java.io.File)1 ProblemData (org.jetbrains.android.inspections.lint.ProblemData)1 NotNull (org.jetbrains.annotations.NotNull)1