Minor, refactor BuiltInDefinitionFile.read to get rid of isInternalBuiltInFile
This commit is contained in:
committed by
Alexander Udalov
parent
5f39f628c9
commit
63db41a712
+12
-13
@@ -48,7 +48,7 @@ class KotlinBuiltInDecompiler : ClassFileDecompilers.Full() {
|
|||||||
|
|
||||||
override fun createFileViewProvider(file: VirtualFile, manager: PsiManager, physical: Boolean): FileViewProvider {
|
override fun createFileViewProvider(file: VirtualFile, manager: PsiManager, physical: Boolean): FileViewProvider {
|
||||||
return KotlinDecompiledFileViewProvider(manager, file, physical) { provider ->
|
return KotlinDecompiledFileViewProvider(manager, file, physical) { provider ->
|
||||||
if (isInternalBuiltInFile(BuiltInDefinitionFile.read(provider.virtualFile))) {
|
if (BuiltInDefinitionFile.read(provider.virtualFile) == null) {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -68,6 +68,8 @@ fun buildDecompiledTextForBuiltIns(builtInFile: VirtualFile): DecompiledText {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val file = BuiltInDefinitionFile.read(builtInFile)
|
val file = BuiltInDefinitionFile.read(builtInFile)
|
||||||
|
?: error("Unexpectedly empty built-in file: $builtInFile")
|
||||||
|
|
||||||
when (file) {
|
when (file) {
|
||||||
is BuiltInDefinitionFile.Incompatible -> {
|
is BuiltInDefinitionFile.Incompatible -> {
|
||||||
return createIncompatibleAbiVersionDecompiledText(BuiltInsBinaryVersion.INSTANCE, file.version)
|
return createIncompatibleAbiVersionDecompiledText(BuiltInsBinaryVersion.INSTANCE, file.version)
|
||||||
@@ -111,7 +113,7 @@ sealed class BuiltInDefinitionFile {
|
|||||||
var FILTER_OUT_CLASSES_EXISTING_AS_JVM_CLASS_FILES = true
|
var FILTER_OUT_CLASSES_EXISTING_AS_JVM_CLASS_FILES = true
|
||||||
@TestOnly set
|
@TestOnly set
|
||||||
|
|
||||||
fun read(file: VirtualFile): BuiltInDefinitionFile {
|
fun read(file: VirtualFile): BuiltInDefinitionFile? {
|
||||||
val stream = ByteArrayInputStream(file.contentsToByteArray())
|
val stream = ByteArrayInputStream(file.contentsToByteArray())
|
||||||
|
|
||||||
val version = BuiltInsBinaryVersion.readFrom(stream)
|
val version = BuiltInsBinaryVersion.readFrom(stream)
|
||||||
@@ -120,18 +122,15 @@ sealed class BuiltInDefinitionFile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val proto = BuiltInsProtoBuf.BuiltIns.parseFrom(stream, BuiltInSerializerProtocol.extensionRegistry)
|
val proto = BuiltInsProtoBuf.BuiltIns.parseFrom(stream, BuiltInSerializerProtocol.extensionRegistry)
|
||||||
return BuiltInDefinitionFile.Compatible(proto, file.parent)
|
val result = BuiltInDefinitionFile.Compatible(proto, file.parent)
|
||||||
}
|
if (result.classesToDecompile.isEmpty() &&
|
||||||
}
|
result.proto.`package`.functionCount == 0 &&
|
||||||
}
|
result.proto.`package`.propertyCount == 0) {
|
||||||
|
// No callables or top-level classes to decompile: should skip this file
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
internal fun isInternalBuiltInFile(file: BuiltInDefinitionFile): Boolean {
|
return result
|
||||||
when (file) {
|
|
||||||
is BuiltInDefinitionFile.Incompatible -> return false
|
|
||||||
is BuiltInDefinitionFile.Compatible -> {
|
|
||||||
return file.classesToDecompile.isEmpty() &&
|
|
||||||
file.proto.`package`.functionCount == 0 &&
|
|
||||||
file.proto.`package`.propertyCount == 0
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-3
@@ -33,9 +33,7 @@ class KotlinBuiltInStubBuilder : ClsStubBuilder() {
|
|||||||
override fun buildFileStub(content: FileContent): PsiFileStub<*>? {
|
override fun buildFileStub(content: FileContent): PsiFileStub<*>? {
|
||||||
val virtualFile = content.file
|
val virtualFile = content.file
|
||||||
assert(virtualFile.fileType == KotlinBuiltInFileType) { "Unexpected file type ${virtualFile.fileType}" }
|
assert(virtualFile.fileType == KotlinBuiltInFileType) { "Unexpected file type ${virtualFile.fileType}" }
|
||||||
val file = BuiltInDefinitionFile.read(virtualFile)
|
val file = BuiltInDefinitionFile.read(virtualFile) ?: return null
|
||||||
|
|
||||||
if (isInternalBuiltInFile(file)) return null
|
|
||||||
|
|
||||||
when (file) {
|
when (file) {
|
||||||
is BuiltInDefinitionFile.Incompatible -> {
|
is BuiltInDefinitionFile.Incompatible -> {
|
||||||
|
|||||||
Reference in New Issue
Block a user