Support sig files processing
This commit is contained in:
@@ -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? {
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
+3
-2
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user