in src/main/kotlin/mobi/hsz/idea/gitignore/codeInspection/IgnoreCoverEntryInspection.kt [36:102]
override fun checkFile(file: PsiFile, manager: InspectionManager, isOnTheFly: Boolean): Array<ProblemDescriptor>? {
val virtualFile = file.virtualFile
if (file !is IgnoreFile || !Utils.isInProject(virtualFile, file.getProject())) {
return null
}
val contextDirectory = virtualFile.parent ?: return null
val problemsHolder = ProblemsHolder(manager, file, isOnTheFly)
val ignored = mutableSetOf<String>()
val unignored = mutableSetOf<String>()
val result = mutableListOf<Pair<IgnoreEntry, IgnoreEntry>>()
val map = mutableMapOf<IgnoreEntry, Set<String>>()
val entries = file.findChildrenByClass(IgnoreEntry::class.java)
val matcher = file.project.service<IgnoreMatcher>()
val matchedMap = getPathsSet(contextDirectory, entries, matcher)
entries.forEach entries@{ entry ->
ProgressManager.checkCanceled()
val matched = matchedMap[entry] ?: return@entries
val intersection: Collection<String>
if (!entry.isNegated) {
ignored.addAll(matched)
intersection = unignored.intersect(matched)
if (unignored.removeAll(intersection.toSet())) {
return@entries
}
} else {
unignored.addAll(matched)
intersection = ignored.intersect(matched)
if (ignored.removeAll(intersection.toSet())) {
return@entries
}
}
map.keys.forEach recent@{ recent ->
ProgressManager.checkCanceled()
val recentValues = map[recent] ?: return@recent
if (recentValues.isEmpty() || matched.isEmpty()) {
return@recent
}
if (entry.isNegated == recent.isNegated) {
if (recentValues.containsAll(matched)) {
result.add(Pair.create(recent, entry))
} else if (matched.containsAll(recentValues)) {
result.add(Pair.create(entry, recent))
}
} else if (intersection.containsAll(recentValues)) {
result.add(Pair.create(entry, recent))
}
}
map[entry] = matched
}
result.forEach { pair ->
problemsHolder.registerProblem(
pair.second,
message(pair.first, virtualFile, isOnTheFly),
IgnoreRemoveEntryFix(pair.second)
)
}
return problemsHolder.resultsArray
}