Skip to content

Commit

Permalink
feature: Remove reflection and unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
bric3 committed Mar 21, 2023
1 parent b72af42 commit d6e4310
Showing 1 changed file with 2 additions and 38 deletions.
40 changes: 2 additions & 38 deletions src/main/kotlin/com/github/lppedd/cc/vcs/InternalVcsService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import com.intellij.util.Consumer
import com.intellij.util.EmptyConsumer
import com.intellij.vcs.log.*
import com.intellij.vcs.log.data.VcsLogMultiRepoJoiner
import com.intellij.vcs.log.impl.VcsLogContentUtil
import com.intellij.vcs.log.impl.VcsLogManager
import com.intellij.vcs.log.impl.VcsProjectLog
import com.intellij.vcs.log.visible.filters.VcsLogFilterObject
Expand Down Expand Up @@ -126,26 +125,9 @@ internal class InternalVcsService(private val project: Project) : VcsService {
root: VirtualFile,
commitsHashes: List<String>,
): List<VcsCommitMetadata> {
VcsLogProvider::class.java.methods.find { it.name == "readMetadata" }?.also {
it.isAccessible = true

when {
// 203.4203.26+
// (VirtualFile, List<String>, Consumer<? super VcsCommitMetadata>) -> void
it.returnType == Void.TYPE && it.parameterCount == 3 -> {
val commitsMetadata = ArrayList<VcsCommitMetadata>(100)
it.invoke(this, root, commitsHashes, Consumer(commitsMetadata::add))
return commitsMetadata
}
// (VirtualFile, List<String>) -> List<VcsCommitMetadata>
it.returnType == List::class.java && it.parameterCount == 2 -> {
@Suppress("unchecked_cast")
return it.invoke(this, root, commitsHashes) as List<VcsCommitMetadata>
}
}
return ArrayList<VcsCommitMetadata>(100).also {
readMetadata(root, commitsHashes, Consumer(it::add))
}

return emptyList()
}

private fun getVcsLogProviders(): Map<VirtualFile, VcsLogProvider> {
Expand Down Expand Up @@ -181,24 +163,6 @@ internal class InternalVcsService(private val project: Project) : VcsService {
return commitsMetadata
}

@Suppress("unused")
@Compatibility(minVersion = "203.3645.34")
private fun ensureLogCreated(): Boolean {
val method =
VcsProjectLog::class.java.getDeclaredMethod("ensureLogCreated", Project::class.java) // IDEA 203.3645.34+
?: VcsProjectLog::class.java.getDeclaredMethod("getOrCreateLog", Project::class.java) // IDEA 201.3803.32+
?: VcsLogContentUtil::class.java.getDeclaredMethod("getOrCreateLog", Project::class.java)
?: return false

return try {
method.isAccessible = true
method.invoke(null, project)
true
} catch (_: Exception) {
false
}
}

private inner class MyVcsLogRefresher : VcsLogRefresher {
override fun refresh(root: VirtualFile) {
refreshCachedValues()
Expand Down

0 comments on commit d6e4310

Please sign in to comment.