[IDE] Move KotlinJavaScriptMetaFileDecompiler to kotlin.git
KTIJ-27752
This commit is contained in:
committed by
Space Team
parent
b41c4bc4c1
commit
645e4af8b1
@@ -0,0 +1,27 @@
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
id("jps-compatible")
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
"main" { projectDefault() }
|
||||
"test" { projectDefault() }
|
||||
}
|
||||
|
||||
projectTest {
|
||||
workingDir = rootDir
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api(project(":core:deserialization"))
|
||||
api(project(":compiler:psi"))
|
||||
api(project(":analysis:decompiled:decompiler-to-file-stubs"))
|
||||
api(project(":analysis:decompiled:decompiler-to-psi"))
|
||||
api(project(":js:js.serializer"))
|
||||
compileOnly(intellijCore())
|
||||
|
||||
testImplementation(projectTests(":compiler:tests-common"))
|
||||
testImplementation(projectTests(":compiler:tests-common-new"))
|
||||
}
|
||||
|
||||
testsJar()
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.analysis.decompiler.js
|
||||
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import org.jetbrains.kotlin.analysis.decompiler.psi.KotlinMetadataDecompiler
|
||||
import org.jetbrains.kotlin.analysis.decompiler.stub.file.KotlinMetadataStubBuilder
|
||||
import org.jetbrains.kotlin.metadata.ProtoBuf
|
||||
import org.jetbrains.kotlin.metadata.js.JsProtoBuf
|
||||
import org.jetbrains.kotlin.psi.stubs.KotlinStubVersions
|
||||
import org.jetbrains.kotlin.serialization.js.DynamicTypeDeserializer
|
||||
import org.jetbrains.kotlin.serialization.js.JsSerializerProtocol
|
||||
import org.jetbrains.kotlin.utils.JsMetadataVersion
|
||||
import java.io.ByteArrayInputStream
|
||||
|
||||
class KotlinJavaScriptMetaFileDecompiler : KotlinMetadataDecompiler<JsMetadataVersion>(
|
||||
fileType = KotlinJavaScriptMetaFileType,
|
||||
serializerProtocol = { JsSerializerProtocol },
|
||||
flexibleTypeDeserializer = DynamicTypeDeserializer,
|
||||
expectedBinaryVersion = { JsMetadataVersion.INSTANCE },
|
||||
invalidBinaryVersion = { JsMetadataVersion.INVALID_VERSION },
|
||||
stubVersion = KotlinStubVersions.JS_STUB_VERSION
|
||||
) {
|
||||
override fun readFile(bytes: ByteArray, file: VirtualFile): KotlinMetadataStubBuilder.FileWithMetadata {
|
||||
val stream = ByteArrayInputStream(bytes)
|
||||
|
||||
val version = JsMetadataVersion.readFrom(stream)
|
||||
if (!version.isCompatible()) {
|
||||
return KotlinMetadataStubBuilder.FileWithMetadata.Incompatible(version)
|
||||
}
|
||||
|
||||
JsProtoBuf.Header.parseDelimitedFrom(stream)
|
||||
|
||||
val proto = ProtoBuf.PackageFragment.parseFrom(stream, JsSerializerProtocol.extensionRegistry)
|
||||
return KotlinMetadataStubBuilder.FileWithMetadata.Compatible(proto, version, JsSerializerProtocol)
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.analysis.decompiler.js
|
||||
|
||||
import com.intellij.openapi.fileTypes.FileType
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import org.jetbrains.kotlin.analysis.decompiler.psi.KotlinLabelProviderService
|
||||
import org.jetbrains.kotlin.serialization.js.KotlinJavascriptSerializationUtil
|
||||
|
||||
object KotlinJavaScriptMetaFileType : FileType {
|
||||
override fun getName() = "KJSM"
|
||||
override fun getDescription() = KotlinLabelProviderService.getService()?.getLabelForKotlinJavaScriptMetaFileType()
|
||||
?: "Kotlin JavaScript meta file"
|
||||
|
||||
override fun getDefaultExtension() = KotlinJavascriptSerializationUtil.CLASS_METADATA_FILE_EXTENSION
|
||||
override fun getIcon() = null
|
||||
override fun isBinary() = true
|
||||
override fun isReadOnly() = true
|
||||
override fun getCharset(file: VirtualFile, content: ByteArray) = null
|
||||
}
|
||||
+1
@@ -10,6 +10,7 @@ import com.intellij.openapi.application.ApplicationManager
|
||||
abstract class KotlinLabelProviderService {
|
||||
abstract fun getLabelForBuiltInFileType(): String
|
||||
abstract fun getLabelForKlibMetaFileType(): String
|
||||
abstract fun getLabelForKotlinJavaScriptMetaFileType(): String
|
||||
|
||||
companion object {
|
||||
fun getService(): KotlinLabelProviderService? =
|
||||
|
||||
Reference in New Issue
Block a user