use of com.android.tools.lint.detector.api.Issue 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());
}
}
}
}
}
}
use of com.android.tools.lint.detector.api.Issue 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");
}
use of com.android.tools.lint.detector.api.Issue 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;
}
use of com.android.tools.lint.detector.api.Issue in project android by JetBrains.
the class IssueIdDocumentationProvider method generateDoc.
@Nullable
@Override
public String generateDoc(PsiElement element, @Nullable PsiElement originalElement) {
// Check whether the element is attribute value
if (!(element instanceof XmlAttributeValue)) {
return null;
}
final PsiFile file = element.getContainingFile();
if (!(file instanceof XmlFile)) {
return null;
}
// Check whether the current XML file is lint.xml file
final DomFileElement<LintDomElement> fileElement = DomManager.getDomManager(element.getProject()).getFileElement((XmlFile) file, LintDomElement.class);
if (fileElement == null) {
return null;
}
final Issue issue = IssueIdConverter.getIdSet().get(((XmlAttributeValue) element).getValue());
if (issue == null) {
return null;
}
return issue.getExplanation(TextFormat.HTML);
}
use of com.android.tools.lint.detector.api.Issue in project android by JetBrains.
the class UnusedResourcesProcessor method computeUnusedMap.
@NotNull
private Map<Issue, Map<File, List<ProblemData>>> computeUnusedMap() {
Map<Issue, Map<File, List<ProblemData>>> map = Maps.newHashMap();
List<Issue> issues = Lists.newArrayListWithExpectedSize(2);
issues.add(UnusedResourceDetector.ISSUE);
if (myIncludeIds) {
issues.add(UnusedResourceDetector.ISSUE_IDS);
}
AnalysisScope scope = new AnalysisScope(myProject);
boolean unusedWasEnabled = UnusedResourceDetector.ISSUE.isEnabledByDefault();
boolean unusedIdsWasEnabled = UnusedResourceDetector.ISSUE_IDS.isEnabledByDefault();
UnusedResourceDetector.ISSUE.setEnabledByDefault(true);
UnusedResourceDetector.ISSUE_IDS.setEnabledByDefault(myIncludeIds);
try {
LintIdeClient client = LintIdeClient.forBatch(myProject, map, scope, issues);
LintRequest request = new LintIdeRequest(client, myProject, null, Arrays.asList(myModules), false);
request.setScope(Scope.ALL);
LintDriver lint = new LintDriver(new LintIdeIssueRegistry(), client);
lint.analyze(request);
} finally {
UnusedResourceDetector.ISSUE.setEnabledByDefault(unusedWasEnabled);
UnusedResourceDetector.ISSUE_IDS.setEnabledByDefault(unusedIdsWasEnabled);
}
return map;
}
Aggregations