private static String getExplanationId(Issue issue) { return "explanation" + issue.getId(); }
/** * Sorts the detectors alphabetically by id. This is intended to make it * convenient to store settings for detectors in a fixed order. It is not * intended as the order to be shown to the user; for that, a tool embedding * lint might consider the priorities, categories, severities etc of the * various detectors. * * @param other the {@link Issue} to compare this issue to */ public int compareTo(Issue other) { return getId().compareTo(other.getId()); }
/** * Sorts the detectors alphabetically by id. This is intended to make it * convenient to store settings for detectors in a fixed order. It is not * intended as the order to be shown to the user; for that, a tool embedding * lint might consider the priorities, categories, severities etc of the * various detectors. * * @param other the {@link Issue} to compare this issue to */ @Override public int compareTo(@NonNull Issue other) { return getId().compareTo(other.getId()); }
@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; }
/** Returns true if the given issue has been explicitly disabled */ boolean isSuppressed(Issue issue) { return flags.getSuppressedIds().contains(issue.getId()); }
/** * 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 static boolean matches(@Nullable Issue issue, @NonNull String id) { if (id.equalsIgnoreCase(SUPPRESS_ALL)) { return true; } if (issue != null) { String issueId = issue.getId(); if (id.equalsIgnoreCase(issueId)) { return true; } if (id.startsWith(STUDIO_ID_PREFIX) && id.regionMatches(true, STUDIO_ID_PREFIX.length(), issueId, 0, issueId.length()) && id.substring(STUDIO_ID_PREFIX.length()).equalsIgnoreCase(issueId)) { return true; } } return false; }
@Override public void setSeverity(Issue issue, Severity severity) { ensureInitialized(); String id = issue.getId(); if (severity == null) { mSeverity.remove(id); } else { mSeverity.put(id, severity); } if (!mBulkEditing) { writeConfig(); } }
/** * Marks the given issue and file combination as being ignored. * * @param issue the issue to be ignored in the given file * @param file the file to ignore the issue in */ public void ignore(Issue issue, File file) { ensureInitialized(); String path = mProject != null ? mProject.getRelativePath(file) : file.getPath(); List<String> paths = mSuppressed.get(issue.getId()); if (paths == null) { paths = new ArrayList<String>(); mSuppressed.put(issue.getId(), paths); } paths.add(path); // Keep paths sorted alphabetically; makes XML output stable Collections.sort(paths); if (!mBulkEditing) { writeConfig(); } }
private static void listIssue(PrintStream out, Issue issue) { out.print(wrapArg("\"" + issue.getId() + "\": " + issue.getBriefDescription(TEXT))); }
@Override public boolean isEnabled(@NonNull Issue issue) { if (issue == IssueRegistry.LINT_ERROR) { return !task.allowCompilationErrors; } else if (issue == IssueRegistry.PARSER_ERROR) { return !task.allowSystemErrors; } if (task.issueIds != null) { for (String id : task.issueIds) { if (issue.getId().equals(id)) { return true; } } } return task.getCheckedIssues().contains(issue); }
@Override public void ignore(@NonNull Issue issue, @NonNull File file) { ensureInitialized(); String path = project != null ? project.getRelativePath(file) : file.getPath(); List<String> paths = suppressed.get(issue.getId()); if (paths == null) { paths = new ArrayList<>(); suppressed.put(issue.getId(), paths); } paths.add(path); // Keep paths sorted alphabetically; makes XML output stable Collections.sort(paths); if (!bulkEditing) { writeConfig(); } }
@Override public Severity getSeverity(Issue issue) { ensureInitialized(); Severity severity = mSeverity.get(issue.getId()); if (severity != null) { return severity; } if (mParent != null) { return mParent.getSeverity(issue); } return getDefaultSeverity(issue); }
@Override public void setSeverity(@NonNull Issue issue, @Nullable Severity severity) { ensureInitialized(); String id = issue.getId(); if (severity == null) { this.severity.remove(id); } else { this.severity.put(id, severity); } if (!bulkEditing) { writeConfig(); } }
@Override @NonNull public Severity getSeverity(@NonNull Issue issue) { ensureInitialized(); Severity severity = this.severity.get(issue.getId()); if (severity == null) { severity = this.severity.get(VALUE_ALL); } if (severity != null) { return severity; } if (parent != null) { return parent.getSeverity(issue); } return getDefaultSeverity(issue); }
@NonNull @Override public Severity getSeverity(@NonNull Issue issue) { Integer optionSeverity = overrides.get(issue.getId()); if (optionSeverity != null) { Severity severity = Severity.fromLintOptionSeverity(optionSeverity); if (flags.isFatalOnly() && severity != Severity.FATAL) { return Severity.IGNORE; } return severity; } return super.getSeverity(issue); } };
/** * Test that an invalid AndroidManifest.xml has a warning. */ public void testInvalidManifest() throws Exception { String warningMessage = MinSdkDetectorTest.class.getSimpleName() + "_" + Thread.currentThread().getStackTrace()[1].getMethodName() + ": Warning: " + MinSdkDetector.ISSUE.getBriefDescription(TextFormat.TEXT) + " [" + MinSdkDetector.ISSUE.getId() + "]\n" + "0 errors, 1 warnings\n"; assertEquals( warningMessage, lintFiles("InvalidAndroidManifest.xml=>AndroidManifest.xml") ); }
/** * Test that a java file where a subscription is not bound using RxLifecycle */ public void testRxLifecycleNotBound() throws Exception { String file = "bin/classes/LifecycleNotBoundKotlin.kt.class"; String warningMessage = file + ": Error: " + RxLifecycleDetector.ISSUE.getBriefDescription(TextFormat.TEXT) + " [" + RxLifecycleDetector.ISSUE.getId() + "]\n" + "1 errors, 0 warnings\n"; assertEquals(warningMessage, lintClassFile(file)); }
/** * Test that a java file with an enum has a warning. */ public void testEnumCase() throws Exception { String file = "EnumTestCase.java"; String warningMessage = file + ": Warning: " + EnumDetector.ISSUE.getBriefDescription(TextFormat.TEXT) + " [" + EnumDetector.ISSUE.getId() + "]\n" + "0 errors, 1 warnings\n"; assertEquals( warningMessage, lintFiles(file) ); }
/** * Test that a java file with a to-do has a warning. */ public void testTodoCase() throws Exception { String file = "TodoTestCase.java"; String warningMessage = file + ":5: Warning: " + TodoDetector.ISSUE.getBriefDescription(TextFormat.TEXT) + " [" + TodoDetector.ISSUE.getId() + "]\n" + " // TODO\n" + " ~~~~\n" + "0 errors, 1 warnings\n"; assertEquals( warningMessage, lintFiles(file) ); }