@@ -54,27 +54,46 @@ fun readClassFile(project: Project,
54
54
file : VirtualFile ): ByteArray? {
55
55
val fqNameWithInners = jvmName.fqNameForClassNameWithoutDollars.tail(jvmName.packageFqName)
56
56
57
- when {
58
- ProjectRootsUtil .isLibrarySourceFile(project, file) -> {
59
- val classId = ClassId (jvmName.packageFqName, Name .identifier(fqNameWithInners.asString()))
57
+ fun readFromLibrary () : ByteArray? {
58
+ if (! ProjectRootsUtil .isLibrarySourceFile(project, file)) return null
60
59
61
- val fileFinder = JvmVirtualFileFinder .SERVICE .getInstance(project)
62
- val classFile = fileFinder.findVirtualFileWithHeader(classId) ? : return null
63
- return classFile.contentsToByteArray()
64
- }
60
+ val classId = ClassId (jvmName.packageFqName, Name .identifier(fqNameWithInners.asString()))
61
+
62
+ val fileFinder = JvmVirtualFileFinder .SERVICE .getInstance(project)
63
+ val classFile = fileFinder.findVirtualFileWithHeader(classId) ? : return null
64
+ return classFile.contentsToByteArray()
65
+ }
66
+
67
+ fun readFromOutput (isForTestClasses : Boolean ): ByteArray? {
68
+ if (! ProjectRootsUtil .isProjectSourceFile(project, file)) return null
69
+
70
+ val module = ProjectFileIndex .SERVICE .getInstance(project).getModuleForFile(file)
71
+ val outputDir = CompilerPaths .getModuleOutputDirectory(module, /* forTests = */ isForTestClasses) ? : return null
65
72
66
- ProjectRootsUtil .isProjectSourceFile(project, file) -> {
67
- val module = ProjectFileIndex .SERVICE .getInstance(project).getModuleForFile(file)
68
- val outputDir = CompilerPaths .getModuleOutputDirectory(module, /* forTests = */ false ) ? : return null
73
+ val className = fqNameWithInners.asString().replace(' .' , ' $' )
74
+ var classByDirectory = findClassFileByPath(jvmName.packageFqName.asString(), className, outputDir)
69
75
70
- val className = fqNameWithInners.asString().replace(' .' , ' $' )
71
- val classByDirectory = findClassFileByPath(jvmName.packageFqName.asString(), className, outputDir) ? : return null
76
+ if (classByDirectory == null ) {
77
+ if (! isForTestClasses) {
78
+ return null
79
+ }
80
+
81
+ val outputModeDirName = outputDir.name
82
+ val androidTestOutputDir = outputDir.parent?.parent?.findChild(" androidTest" )?.findChild(outputModeDirName) ? : return null
72
83
73
- return classByDirectory.readBytes()
84
+ classByDirectory = findClassFileByPath(jvmName.packageFqName.asString(), className, androidTestOutputDir) ? : return null
74
85
}
75
86
76
- else -> return null
87
+ return classByDirectory.readBytes()
77
88
}
89
+
90
+ fun readFromSourceOutput () : ByteArray? = readFromOutput(false )
91
+
92
+ fun readFromTestOutput () : ByteArray? = readFromOutput(true )
93
+
94
+ return readFromLibrary() ? :
95
+ readFromSourceOutput() ? :
96
+ readFromTestOutput()
78
97
}
79
98
80
99
private fun findClassFileByPath (packageName : String , className : String , outputDir : VirtualFile ): File ? {
0 commit comments