Simplify getting class file path for functions from current module
This commit is contained in:
@@ -755,9 +755,6 @@ public class InlineCodegen extends CallGenerator {
|
|||||||
IncrementalCache incrementalCache = incrementalCompilationComponents.getIncrementalCache(target);
|
IncrementalCache incrementalCache = incrementalCompilationComponents.getIncrementalCache(target);
|
||||||
String sourceFile = getClassFilePath(sourceDescriptor, incrementalCache);
|
String sourceFile = getClassFilePath(sourceDescriptor, incrementalCache);
|
||||||
String targetFile = getSourceFilePath(targetDescriptor);
|
String targetFile = getSourceFilePath(targetDescriptor);
|
||||||
assert sourceFile != null: "No source file for inline fun: " + jvmSignature;
|
|
||||||
assert targetFile != null: "No target file for inline fun: " + jvmSignature;
|
|
||||||
|
|
||||||
InlineRegistering inlineRegistering = incrementalCache.getInlineRegistering();
|
InlineRegistering inlineRegistering = incrementalCache.getInlineRegistering();
|
||||||
inlineRegistering.registerInline(sourceFile, jvmSignature.toString(), targetFile);
|
inlineRegistering.registerInline(sourceFile, jvmSignature.toString(), targetFile);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,34 +20,32 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptorWithSource
|
|||||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||||
import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinarySourceElement
|
import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinarySourceElement
|
||||||
import org.jetbrains.kotlin.load.kotlin.VirtualFileKotlinClass
|
import org.jetbrains.kotlin.load.kotlin.VirtualFileKotlinClass
|
||||||
import org.jetbrains.kotlin.load.kotlin.incremental.FileSourceElement
|
|
||||||
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache
|
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache
|
||||||
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
|
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
|
||||||
import org.jetbrains.kotlin.resolve.source.PsiSourceElement
|
import org.jetbrains.kotlin.resolve.source.PsiSourceElement
|
||||||
|
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedSimpleFunctionDescriptor
|
||||||
|
|
||||||
public val FunctionDescriptor.sourceFilePath: String?
|
public val FunctionDescriptor.sourceFilePath: String
|
||||||
get() {
|
get() {
|
||||||
val source = source as? PsiSourceElement
|
val source = source as PsiSourceElement
|
||||||
val containingFile = source?.psi?.containingFile
|
val containingFile = source.psi?.containingFile
|
||||||
return containingFile?.virtualFile?.canonicalPath
|
return containingFile?.virtualFile?.canonicalPath!!
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun FunctionDescriptor.getClassFilePath(cache: IncrementalCache): String? {
|
public fun FunctionDescriptor.getClassFilePath(cache: IncrementalCache): String {
|
||||||
val container = containingDeclaration as? DeclarationDescriptorWithSource
|
val container = containingDeclaration as? DeclarationDescriptorWithSource
|
||||||
val source = container?.source
|
val source = container?.source
|
||||||
|
|
||||||
return when (source) {
|
return when (source) {
|
||||||
is FileSourceElement ->
|
|
||||||
source.file.canonicalPath
|
|
||||||
is KotlinJvmBinarySourceElement -> {
|
is KotlinJvmBinarySourceElement -> {
|
||||||
val kotlinClass = source.binaryClass as? VirtualFileKotlinClass
|
assert(this is DeserializedSimpleFunctionDescriptor) { "Expected DeserializedSimpleFunctionDescriptor, got: $this" }
|
||||||
kotlinClass?.file?.canonicalPath
|
val kotlinClass = source.binaryClass as VirtualFileKotlinClass
|
||||||
|
kotlinClass.file.canonicalPath!!
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
val classId = InlineCodegenUtil.getContainerClassId(this)
|
val classId = InlineCodegenUtil.getContainerClassId(this)!!
|
||||||
val className = classId?.let { JvmClassName.byClassId(it) }?.internalName
|
val className = JvmClassName.byClassId(classId).internalName
|
||||||
|
cache.getClassFilePath(className)
|
||||||
if (className != null) cache.getClassFilePath(className) else null
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
-22
@@ -1,22 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.load.kotlin.incremental
|
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.SourceElement
|
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
public class FileSourceElement(public val file: File) : SourceElement
|
|
||||||
-13
@@ -21,10 +21,8 @@ import org.apache.log4j.Logger
|
|||||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.PackageFragmentProvider
|
import org.jetbrains.kotlin.descriptors.PackageFragmentProvider
|
||||||
import org.jetbrains.kotlin.descriptors.SourceElement
|
|
||||||
import org.jetbrains.kotlin.descriptors.impl.PackageFragmentDescriptorImpl
|
import org.jetbrains.kotlin.descriptors.impl.PackageFragmentDescriptorImpl
|
||||||
import org.jetbrains.kotlin.load.kotlin.ModuleMapping
|
import org.jetbrains.kotlin.load.kotlin.ModuleMapping
|
||||||
import org.jetbrains.kotlin.load.kotlin.PackageClassUtils
|
|
||||||
import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils
|
import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils
|
||||||
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache
|
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache
|
||||||
import org.jetbrains.kotlin.modules.Module
|
import org.jetbrains.kotlin.modules.Module
|
||||||
@@ -44,7 +42,6 @@ import org.jetbrains.kotlin.serialization.jvm.JvmProtoBufUtil
|
|||||||
import org.jetbrains.kotlin.storage.NotNullLazyValue
|
import org.jetbrains.kotlin.storage.NotNullLazyValue
|
||||||
import org.jetbrains.kotlin.storage.StorageManager
|
import org.jetbrains.kotlin.storage.StorageManager
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.singletonOrEmptyList
|
import org.jetbrains.kotlin.utils.addToStdlib.singletonOrEmptyList
|
||||||
import java.io.File
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
public class IncrementalPackageFragmentProvider(
|
public class IncrementalPackageFragmentProvider(
|
||||||
@@ -100,14 +97,6 @@ public class IncrementalPackageFragmentProvider(
|
|||||||
public val target: Module
|
public val target: Module
|
||||||
get() = this@IncrementalPackageFragmentProvider.target
|
get() = this@IncrementalPackageFragmentProvider.target
|
||||||
|
|
||||||
private val sourceElement: SourceElement by lazy {
|
|
||||||
val incrementalCache = this@IncrementalPackageFragmentProvider.incrementalCache
|
|
||||||
val classId = PackageClassUtils.getPackageClassId(fqName)
|
|
||||||
val className = JvmClassName.byClassId(classId)
|
|
||||||
val classFilePath = incrementalCache.getClassFilePath(className.internalName)
|
|
||||||
FileSourceElement(File(classFilePath))
|
|
||||||
}
|
|
||||||
|
|
||||||
val memberScope: NotNullLazyValue<JetScope> = storageManager.createLazyValue {
|
val memberScope: NotNullLazyValue<JetScope> = storageManager.createLazyValue {
|
||||||
if (fqName !in fqNamesToLoad) {
|
if (fqName !in fqNamesToLoad) {
|
||||||
JetScope.Empty
|
JetScope.Empty
|
||||||
@@ -147,8 +136,6 @@ public class IncrementalPackageFragmentProvider(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getSource(): SourceElement = sourceElement
|
|
||||||
|
|
||||||
override fun getMemberScope(): JetScope = memberScope()
|
override fun getMemberScope(): JetScope = memberScope()
|
||||||
|
|
||||||
private inner class IncrementalPackageScope(val packageData: PackageData) : DeserializedPackageMemberScope(
|
private inner class IncrementalPackageScope(val packageData: PackageData) : DeserializedPackageMemberScope(
|
||||||
|
|||||||
Reference in New Issue
Block a user