Drop package facades:
- getting rid of package facades in InlineCodegen & related stuff. Provide binary source element to top-level package members.
This commit is contained in:
@@ -769,9 +769,9 @@ public class InlineCodegen extends CallGenerator {
|
||||
if (incrementalCompilationComponents == null || targetId == null) return;
|
||||
|
||||
IncrementalCache incrementalCache = incrementalCompilationComponents.getIncrementalCache(targetId);
|
||||
String sourceFile = InlineCodegenUtilsKt.getClassFilePath(sourceDescriptor, incrementalCache);
|
||||
String targetFile = InlineCodegenUtilsKt.getSourceFilePath(targetDescriptor);
|
||||
incrementalCache.registerInline(sourceFile, jvmSignature.toString(), targetFile);
|
||||
String classFilePath = InlineCodegenUtilsKt.getClassFilePath(sourceDescriptor, typeMapper, incrementalCache);
|
||||
String sourceFilePath = InlineCodegenUtilsKt.getSourceFilePath(targetDescriptor);
|
||||
incrementalCache.registerInline(classFilePath, jvmSignature.toString(), sourceFilePath);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -164,26 +164,6 @@ public class InlineCodegenUtil {
|
||||
return fileFinder.findVirtualFileWithHeader(new ClassId(packageFqName, Name.identifier(classNameWithDollars)));
|
||||
}
|
||||
|
||||
//TODO: navigate to inner classes
|
||||
@Nullable
|
||||
public static ClassId getContainerClassId(@NotNull DeclarationDescriptor referencedDescriptor) {
|
||||
ClassOrPackageFragmentDescriptor
|
||||
containerDescriptor = DescriptorUtils.getParentOfType(referencedDescriptor, ClassOrPackageFragmentDescriptor.class, false);
|
||||
if (containerDescriptor instanceof PackageFragmentDescriptor) {
|
||||
return PackageClassUtils.getPackageClassId(getFqName(containerDescriptor).toSafe());
|
||||
}
|
||||
if (containerDescriptor instanceof ClassDescriptor) {
|
||||
ClassId classId = DescriptorUtilsKt.getClassId((ClassDescriptor) containerDescriptor);
|
||||
if (isInterface(containerDescriptor)) {
|
||||
FqName relativeClassName = classId.getRelativeClassName();
|
||||
//TODO test nested trait fun inlining
|
||||
classId = new ClassId(classId.getPackageFqName(), Name.identifier(relativeClassName.shortName().asString() + JvmAbi.DEFAULT_IMPLS_SUFFIX));
|
||||
}
|
||||
return classId;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getInlineName(
|
||||
@NotNull CodegenContext codegenContext,
|
||||
@NotNull JetTypeMapper typeMapper,
|
||||
|
||||
@@ -16,13 +16,15 @@
|
||||
|
||||
package org.jetbrains.kotlin.codegen.inline
|
||||
|
||||
import org.jetbrains.kotlin.codegen.state.JetTypeMapper
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptorWithSource
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinaryPackageSourceElement
|
||||
import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinarySourceElement
|
||||
import org.jetbrains.kotlin.load.kotlin.VirtualFileKotlinClass
|
||||
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache
|
||||
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
|
||||
import org.jetbrains.kotlin.resolve.source.PsiSourceElement
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedCallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedSimpleFunctionDescriptor
|
||||
|
||||
public val FunctionDescriptor.sourceFilePath: String
|
||||
@@ -32,19 +34,30 @@ public val FunctionDescriptor.sourceFilePath: String
|
||||
return containingFile?.virtualFile?.canonicalPath!!
|
||||
}
|
||||
|
||||
public fun FunctionDescriptor.getClassFilePath(cache: IncrementalCache): String {
|
||||
public fun FunctionDescriptor.getClassFilePath(typeMapper: JetTypeMapper, cache: IncrementalCache): String {
|
||||
val container = containingDeclaration as? DeclarationDescriptorWithSource
|
||||
val source = container?.source
|
||||
|
||||
return when (source) {
|
||||
is KotlinJvmBinaryPackageSourceElement -> {
|
||||
if (this !is DeserializedCallableMemberDescriptor) {
|
||||
throw AssertionError("Expected DeserializedCallableMemberDescriptor, got: $this")
|
||||
}
|
||||
val kotlinClass = source.getContainingBinaryClass(this) ?:
|
||||
throw AssertionError("Descriptor $this is not found, in: $source")
|
||||
if (kotlinClass !is VirtualFileKotlinClass) {
|
||||
throw AssertionError("Expected VirtualFileKotlinClass, got $kotlinClass")
|
||||
}
|
||||
kotlinClass.file.canonicalPath!!
|
||||
}
|
||||
is KotlinJvmBinarySourceElement -> {
|
||||
assert(this is DeserializedSimpleFunctionDescriptor) { "Expected DeserializedSimpleFunctionDescriptor, got: $this" }
|
||||
val kotlinClass = source.binaryClass as VirtualFileKotlinClass
|
||||
kotlinClass.file.canonicalPath!!
|
||||
}
|
||||
else -> {
|
||||
val classId = InlineCodegenUtil.getContainerClassId(this)!!
|
||||
val className = JvmClassName.byClassId(classId).internalName
|
||||
val implementationOwnerType = typeMapper.mapOwner(this)
|
||||
val className = implementationOwnerType.internalName
|
||||
cache.getClassFilePath(className)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@ import org.jetbrains.kotlin.codegen.*;
|
||||
import org.jetbrains.kotlin.codegen.binding.CodegenBinding;
|
||||
import org.jetbrains.kotlin.codegen.binding.MutableClosure;
|
||||
import org.jetbrains.kotlin.codegen.binding.PsiCodegenPredictor;
|
||||
import org.jetbrains.kotlin.codegen.inline.InlineCodegenUtil;
|
||||
import org.jetbrains.kotlin.codegen.signature.BothSignatureWriter;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.fileClasses.FileClasses;
|
||||
@@ -43,6 +42,7 @@ import org.jetbrains.kotlin.load.java.BuiltinMethodsWithSpecialGenericSignature.
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaCallableMemberDescriptor;
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor;
|
||||
import org.jetbrains.kotlin.load.java.lazy.descriptors.LazyJavaPackageScope;
|
||||
import org.jetbrains.kotlin.load.kotlin.PackageClassUtils;
|
||||
import org.jetbrains.kotlin.load.kotlin.incremental.IncrementalPackageFragmentProvider;
|
||||
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache;
|
||||
import org.jetbrains.kotlin.name.*;
|
||||
@@ -241,8 +241,8 @@ public class JetTypeMapper {
|
||||
if (parentDeclaration instanceof PackageFragmentDescriptor) {
|
||||
containingClassesInfo = getPackageMemberContainingClassesInfo(deserializedDescriptor);
|
||||
} else {
|
||||
containingClassesInfo = ContainingClassesInfo.forClassMemberOrNull(
|
||||
InlineCodegenUtil.getContainerClassId(deserializedDescriptor));
|
||||
ClassId classId = getContainerClassIdForClassDescriptor((ClassDescriptor) parentDeclaration);
|
||||
containingClassesInfo = ContainingClassesInfo.forClassMemberOrNull(classId);
|
||||
}
|
||||
if (containingClassesInfo == null) {
|
||||
throw new IllegalStateException("Couldn't find container for " + deserializedDescriptor.getName());
|
||||
@@ -250,6 +250,16 @@ public class JetTypeMapper {
|
||||
return containingClassesInfo;
|
||||
}
|
||||
|
||||
private static ClassId getContainerClassIdForClassDescriptor(ClassDescriptor classDescriptor) {
|
||||
ClassId classId = DescriptorUtilsKt.getClassId(classDescriptor);
|
||||
if (isInterface(classDescriptor)) {
|
||||
FqName relativeClassName = classId.getRelativeClassName();
|
||||
//TODO test nested trait fun inlining
|
||||
classId = new ClassId(classId.getPackageFqName(), Name.identifier(relativeClassName.shortName().asString() + JvmAbi.DEFAULT_IMPLS_SUFFIX));
|
||||
}
|
||||
return classId;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String getPackageMemberOwnerInternalName(@NotNull DeserializedCallableMemberDescriptor descriptor) {
|
||||
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.google.protobuf.MessageLite
|
||||
import com.intellij.psi.util.CachedValueProvider
|
||||
import com.intellij.psi.util.CachedValuesManager
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
||||
import org.jetbrains.kotlin.load.java.descriptors.getImplClassName
|
||||
import org.jetbrains.kotlin.load.kotlin.PackageClassUtils
|
||||
import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
@@ -70,24 +71,11 @@ public object JvmFileClassUtil {
|
||||
|
||||
@JvmStatic
|
||||
public fun getImplClassName(callable: DeserializedCallableMemberDescriptor): Name? =
|
||||
getImplClassName(callable.proto, callable.nameResolver)
|
||||
callable.getImplClassName()
|
||||
|
||||
@JvmStatic
|
||||
public fun getImplClassName(proto: MessageLite, nameResolver: NameResolver): Name? =
|
||||
when (proto) {
|
||||
is ProtoBuf.Constructor ->
|
||||
null
|
||||
is ProtoBuf.Function ->
|
||||
if (proto.hasExtension(JvmProtoBuf.methodImplClassName))
|
||||
proto.getExtension(JvmProtoBuf.methodImplClassName)
|
||||
else null
|
||||
is ProtoBuf.Property ->
|
||||
if (proto.hasExtension(JvmProtoBuf.propertyImplClassName))
|
||||
proto.getExtension(JvmProtoBuf.propertyImplClassName)
|
||||
else null
|
||||
else ->
|
||||
error("Unknown message: $proto")
|
||||
}?.let { nameResolver.getName(it) }
|
||||
getImplClassName(proto, nameResolver)
|
||||
|
||||
@JvmStatic
|
||||
public fun getHiddenPartFqName(file: JetFile, jvmFileClassAnnotations: ParsedJmvFileClassAnnotations): FqName =
|
||||
|
||||
+15
-8
@@ -46,14 +46,21 @@ public fun isContainedByCompiledPartOfOurModule(descriptor: DeclarationDescripto
|
||||
if (outDirectory == null || packageFragment !is LazyJavaPackageFragment) return false
|
||||
|
||||
val source = getSourceElement(descriptor)
|
||||
if (source is KotlinJvmBinarySourceElement) {
|
||||
val binaryClass = source.binaryClass
|
||||
if (binaryClass is VirtualFileKotlinClass) {
|
||||
val file = binaryClass.file
|
||||
if (file.fileSystem.protocol == StandardFileSystems.FILE_PROTOCOL) {
|
||||
val ioFile = VfsUtilCore.virtualToIoFile(file)
|
||||
return ioFile.absolutePath.startsWith(outDirectory.absolutePath + File.separator);
|
||||
}
|
||||
|
||||
val binaryClass = when (source) {
|
||||
is KotlinJvmBinarySourceElement ->
|
||||
source.binaryClass
|
||||
is KotlinJvmBinaryPackageSourceElement ->
|
||||
source.getRepresentativeBinaryClass()
|
||||
else ->
|
||||
null
|
||||
}
|
||||
|
||||
if (binaryClass is VirtualFileKotlinClass) {
|
||||
val file = binaryClass.file
|
||||
if (file.fileSystem.protocol == StandardFileSystems.FILE_PROTOCOL) {
|
||||
val ioFile = VfsUtilCore.virtualToIoFile(file)
|
||||
return ioFile.absolutePath.startsWith(outDirectory.absolutePath + File.separator);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user