Skip to content

Commit

Permalink
Support sig files processing
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhael Bogdanov authored and Space committed Dec 23, 2021
1 parent 1e378ed commit 22b3688
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ class CliVirtualFileFinder(
private val scope: GlobalSearchScope
) : VirtualFileFinder() {
override fun findVirtualFileWithHeader(classId: ClassId): VirtualFile? =
findBinaryClass(classId, classId.relativeClassName.asString().replace('.', '$') + ".class")
findBinaryOrSigClass(classId)

override fun findSourceOrBinaryVirtualFile(classId: ClassId) =
findBinaryClass(classId, classId.relativeClassName.asString().replace('.', '$') + ".class")
findBinaryOrSigClass(classId)
?: findSourceClass(classId, classId.relativeClassName.asString() + ".java")

override fun findMetadata(classId: ClassId): InputStream? {
Expand Down Expand Up @@ -70,6 +70,14 @@ class CliVirtualFileFinder(
dir.findChild(fileName)?.takeIf(VirtualFile::isValid)
}?.takeIf { it in scope }

private fun findBinaryOrSigClass(classId: ClassId, simpleName: String, rootType: Set<JavaRoot.RootType>) =
index.findClass(classId, acceptedRootTypes = rootType) { dir, _ ->
(dir.findChild("$simpleName.class") ?: dir.findChild("$simpleName.sig"))?.takeIf(VirtualFile::isValid)
}?.takeIf { it in scope }

private fun findBinaryOrSigClass(classId: ClassId) =
findBinaryOrSigClass(classId, classId.relativeClassName.asString().replace('.', '$'), JavaRoot.OnlyBinary)

private fun findBinaryClass(classId: ClassId, fileName: String) = findClass(classId, fileName, JavaRoot.OnlyBinary)
private fun findSourceClass(classId: ClassId, fileName: String) = findClass(classId, fileName, JavaRoot.OnlySource)
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class KotlinCliJavaFileManagerImpl(private val myPsiManager: PsiManager) : CoreJ
val (classId, classFileContentFromRequest, outerClassFromRequest) = request
val virtualFile = findVirtualFileForTopLevelClass(classId, searchScope) ?: return null

if (!usePsiClassFilesReading && virtualFile.extension == "class") {
if (!usePsiClassFilesReading && (virtualFile.extension == "class" || virtualFile.extension == "sig")) {
// We return all class files' names in the directory in knownClassNamesInPackage method, so one may request an inner class
return binaryCache.getOrPut(classId) {
// Note that currently we implicitly suppose that searchScope for binary classes is constant and we do not use it
Expand Down Expand Up @@ -218,6 +218,7 @@ class KotlinCliJavaFileManagerImpl(private val myPsiManager: PsiManager) : CoreJ

val vFile = when (rootType) {
JavaRoot.RootType.BINARY -> packageDir.findChild("$topLevelClassName.class")
JavaRoot.RootType.BINARY_SIG -> packageDir.findChild("$topLevelClassName.sig")
JavaRoot.RootType.SOURCE -> packageDir.findChild("$topLevelClassName.java")
} ?: return null

Expand All @@ -238,7 +239,7 @@ class KotlinCliJavaFileManagerImpl(private val myPsiManager: PsiManager) : CoreJ
val result = THashSet<String>()
index.traverseDirectoriesInPackage(packageFqName, continueSearch = { dir, _ ->
for (child in dir.children) {
if (child.extension == "class" || child.extension == "java") {
if (child.extension == "class" || child.extension == "java" || child.extension == "sig") {
result.add(child.nameWithoutExtension)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ interface JvmDependenciesIndex {
data class JavaRoot(val file: VirtualFile, val type: RootType, val prefixFqName: FqName? = null) {
enum class RootType {
SOURCE,
BINARY
BINARY,
BINARY_SIG
}

companion object RootTypes {
val OnlyBinary: Set<RootType> = EnumSet.of(RootType.BINARY)
val OnlyBinary: Set<RootType> = EnumSet.of(RootType.BINARY, RootType.BINARY_SIG)
val OnlySource: Set<RootType> = EnumSet.of(RootType.SOURCE)
val SourceAndBinary: Set<RootType> = EnumSet.of(RootType.BINARY, RootType.SOURCE)
val SourceAndBinary: Set<RootType> = EnumSet.of(RootType.BINARY, RootType.BINARY_SIG, RootType.SOURCE)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ class JvmDependenciesIndexImpl(_roots: List<JavaRoot>) : JvmDependenciesIndex {

val fileExtension = when (rootType) {
JavaRoot.RootType.BINARY -> JavaClassFileType.INSTANCE.defaultExtension
JavaRoot.RootType.BINARY_SIG -> "sig"
JavaRoot.RootType.SOURCE -> JavaFileType.INSTANCE.defaultExtension
}

Expand Down

0 comments on commit 22b3688

Please sign in to comment.