Drop DeserializedResolverUtils and it's usages
This commit is contained in:
@@ -31,7 +31,6 @@ import org.jetbrains.kotlin.codegen.state.GenerationState;
|
||||
import org.jetbrains.kotlin.codegen.state.JetTypeMapper;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.load.java.JvmAbi;
|
||||
import org.jetbrains.kotlin.load.kotlin.DeserializedResolverUtils;
|
||||
import org.jetbrains.kotlin.load.kotlin.PackageClassUtils;
|
||||
import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils;
|
||||
import org.jetbrains.kotlin.load.kotlin.VirtualFileFinder;
|
||||
@@ -56,8 +55,7 @@ import java.io.StringWriter;
|
||||
import java.util.Arrays;
|
||||
import java.util.ListIterator;
|
||||
|
||||
import static org.jetbrains.kotlin.resolve.DescriptorUtils.getFqName;
|
||||
import static org.jetbrains.kotlin.resolve.DescriptorUtils.isTrait;
|
||||
import static org.jetbrains.kotlin.resolve.DescriptorUtils.*;
|
||||
|
||||
public class InlineCodegenUtil {
|
||||
public static final int API = Opcodes.ASM5;
|
||||
@@ -146,7 +144,7 @@ public class InlineCodegenUtil {
|
||||
return PackageClassUtils.getPackageClassFqName(getFqName(containerDescriptor).toSafe());
|
||||
}
|
||||
if (containerDescriptor instanceof ClassDescriptor) {
|
||||
FqName fqName = DeserializedResolverUtils.kotlinFqNameToJavaFqName(getFqName(containerDescriptor));
|
||||
FqName fqName = getFqNameSafe(containerDescriptor);
|
||||
if (isTrait(containerDescriptor)) {
|
||||
return fqName.parent().child(Name.identifier(fqName.shortName() + JvmAbi.TRAIT_IMPL_SUFFIX));
|
||||
}
|
||||
|
||||
@@ -37,12 +37,13 @@ import org.jetbrains.kotlin.context.GlobalContext
|
||||
import org.jetbrains.kotlin.analyzer.ModuleInfo
|
||||
import org.jetbrains.kotlin.resolve.jvm.JvmPlatformParameters
|
||||
import org.jetbrains.kotlin.analyzer.ModuleContent
|
||||
import org.jetbrains.kotlin.load.kotlin.DeserializedResolverUtils
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
|
||||
import org.jetbrains.kotlin.cli.jvm.JVMConfigurationKeys
|
||||
import org.jetbrains.kotlin.resolve.constants.NullValue
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.classId
|
||||
|
||||
private object BuiltInsSerializerExtension : SerializerExtension() {
|
||||
override fun serializeClass(descriptor: ClassDescriptor, proto: ProtoBuf.Class.Builder, stringTable: StringTable) {
|
||||
@@ -216,6 +217,6 @@ public class BuiltInsSerializer(private val dependOnOldBuiltIns: Boolean) {
|
||||
}
|
||||
|
||||
private fun getFileName(classDescriptor: ClassDescriptor): String {
|
||||
return BuiltInsSerializationUtil.getClassMetadataPath(DeserializedResolverUtils.getClassId(classDescriptor))!!
|
||||
return BuiltInsSerializationUtil.getClassMetadataPath(classDescriptor.classId)
|
||||
}
|
||||
}
|
||||
|
||||
+3
-4
@@ -34,7 +34,6 @@ import org.jetbrains.kotlin.load.java.lazy.types.toAttributes
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
import org.jetbrains.kotlin.platform.JavaToKotlinClassMap
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.resolveTopLevelClass
|
||||
import org.jetbrains.kotlin.load.kotlin.DeserializedResolverUtils.kotlinFqNameToJavaFqName
|
||||
import org.jetbrains.kotlin.resolve.jvm.PLATFORM_TYPES
|
||||
|
||||
private object DEPRECATED_IN_JAVA : JavaLiteralAnnotationArgument {
|
||||
@@ -54,9 +53,9 @@ class LazyJavaAnnotationDescriptor(
|
||||
) : AnnotationDescriptor {
|
||||
|
||||
private val fqName = c.storageManager.createNullableLazyValue {
|
||||
val classId = javaAnnotation.getClassId()
|
||||
if (classId == null) null
|
||||
else kotlinFqNameToJavaFqName(classId.asSingleFqName())
|
||||
javaAnnotation.getClassId().asSingleFqName().let {
|
||||
if (it.isSafe()) it.toSafe() else null
|
||||
}
|
||||
}
|
||||
|
||||
private val type = c.storageManager.createLazyValue {(): JetType ->
|
||||
|
||||
+5
-9
@@ -62,7 +62,7 @@ public abstract class AbstractBinaryClassAnnotationAndConstantLoader<A : Any, C
|
||||
|
||||
override fun loadClassAnnotations(classProto: ProtoBuf.Class, nameResolver: NameResolver): List<A> {
|
||||
val classId = nameResolver.getClassId(classProto.getFqName())
|
||||
val kotlinClass = findKotlinClassById(classId)
|
||||
val kotlinClass = kotlinClassFinder.findKotlinClass(classId)
|
||||
if (kotlinClass == null) {
|
||||
// This means that the resource we're constructing the descriptor from is no longer present: KotlinClassFinder had found the
|
||||
// class earlier, but it can't now
|
||||
@@ -160,19 +160,19 @@ public abstract class AbstractBinaryClassAnnotationAndConstantLoader<A : Any, C
|
||||
val classId = nameResolver.getClassId(classProto.getFqName())
|
||||
if (classKind == ProtoBuf.Class.Kind.CLASS_OBJECT && isStaticFieldInOuter(proto)) {
|
||||
// Backing fields of properties of a class object are generated in the outer class
|
||||
return findKotlinClassById(classId.getOuterClassId())
|
||||
return kotlinClassFinder.findKotlinClass(classId.getOuterClassId())
|
||||
}
|
||||
else if (classKind == ProtoBuf.Class.Kind.TRAIT && annotatedCallableKind == AnnotatedCallableKind.PROPERTY) {
|
||||
if (proto.hasExtension(implClassName)) {
|
||||
val parentPackageFqName = classId.getPackageFqName()
|
||||
val tImplName = nameResolver.getName(proto.getExtension(implClassName))
|
||||
// TODO: store accurate name for nested traits
|
||||
return findKotlinClassById(ClassId(parentPackageFqName, tImplName))
|
||||
return kotlinClassFinder.findKotlinClass(ClassId(parentPackageFqName, tImplName))
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
return findKotlinClassById(classId)
|
||||
return kotlinClassFinder.findKotlinClass(classId)
|
||||
}
|
||||
|
||||
private fun findPackagePartClass(
|
||||
@@ -181,15 +181,11 @@ public abstract class AbstractBinaryClassAnnotationAndConstantLoader<A : Any, C
|
||||
nameResolver: NameResolver
|
||||
): KotlinJvmBinaryClass? {
|
||||
if (proto.hasExtension(implClassName)) {
|
||||
return findKotlinClassById(ClassId(packageFqName, nameResolver.getName(proto.getExtension(implClassName))))
|
||||
return kotlinClassFinder.findKotlinClass(ClassId(packageFqName, nameResolver.getName(proto.getExtension(implClassName))))
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
private fun findKotlinClassById(classId: ClassId): KotlinJvmBinaryClass? {
|
||||
return kotlinClassFinder.findKotlinClass(DeserializedResolverUtils.kotlinClassIdToJavaClassId(classId))
|
||||
}
|
||||
|
||||
private fun isStaticFieldInOuter(proto: ProtoBuf.Callable): Boolean {
|
||||
if (!proto.hasExtension(propertySignature)) return false
|
||||
val propertySignature = proto.getExtension(propertySignature)
|
||||
|
||||
+1
-3
@@ -20,7 +20,6 @@ import org.jetbrains.kotlin.load.java.components.DescriptorResolverUtils
|
||||
import org.jetbrains.kotlin.load.java.components.ErrorReporter
|
||||
import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinaryClass.AnnotationArrayArgumentVisitor
|
||||
import org.jetbrains.kotlin.types.ErrorUtils
|
||||
import org.jetbrains.kotlin.load.kotlin.DeserializedResolverUtils.javaClassIdToKotlinClassId
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import java.util.*
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
@@ -139,8 +138,7 @@ public class BinaryClassAnnotationAndConstantLoaderImpl(
|
||||
}
|
||||
}
|
||||
|
||||
private fun resolveClass(javaClassId: ClassId): ClassDescriptor {
|
||||
val classId = javaClassIdToKotlinClassId(javaClassId)
|
||||
private fun resolveClass(classId: ClassId): ClassDescriptor {
|
||||
return module.findClassAcrossModuleDependencies(classId)
|
||||
?: ErrorUtils.createErrorClass(classId.asSingleFqName().asString())
|
||||
}
|
||||
|
||||
-85
@@ -1,85 +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;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor;
|
||||
import org.jetbrains.kotlin.name.ClassId;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
import org.jetbrains.kotlin.name.FqNameUnsafe;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DeserializedResolverUtils {
|
||||
private DeserializedResolverUtils() {
|
||||
}
|
||||
|
||||
//TODO_R: remove usages
|
||||
@NotNull
|
||||
public static FqName kotlinFqNameToJavaFqName(@NotNull FqNameUnsafe kotlinFqName) {
|
||||
List<Name> segments = kotlinFqName.pathSegments();
|
||||
List<String> correctedSegments = new ArrayList<String>(segments.size());
|
||||
for (Name segment : segments) {
|
||||
correctedSegments.add(segment.getIdentifier());
|
||||
}
|
||||
return FqName.fromSegments(correctedSegments);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ClassId kotlinClassIdToJavaClassId(@NotNull ClassId kotlinClassId) {
|
||||
return new ClassId(kotlinClassId.getPackageFqName(), kotlinFqNameToJavaFqName(kotlinClassId.getRelativeClassName()).toUnsafe());
|
||||
}
|
||||
|
||||
//TODO_R: remove usages
|
||||
@NotNull
|
||||
public static FqNameUnsafe javaFqNameToKotlinFqName(@NotNull FqName javaFqName) {
|
||||
if (javaFqName.isRoot()) {
|
||||
return javaFqName.toUnsafe();
|
||||
}
|
||||
List<Name> segments = javaFqName.pathSegments();
|
||||
List<Name> correctedSegments = new ArrayList<Name>(segments.size());
|
||||
correctedSegments.add(segments.get(0));
|
||||
for (int i = 1; i < segments.size(); i++) {
|
||||
correctedSegments.add(segments.get(i));
|
||||
}
|
||||
return FqNameUnsafe.fromSegments(correctedSegments);
|
||||
}
|
||||
|
||||
//TODO_R: remove usages
|
||||
@NotNull
|
||||
public static ClassId javaClassIdToKotlinClassId(@NotNull ClassId javaClassId) {
|
||||
return new ClassId(javaClassId.getPackageFqName(), javaFqNameToKotlinFqName(javaClassId.getRelativeClassName().toSafe()));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ClassId getClassId(@NotNull ClassDescriptor descriptor) {
|
||||
DeclarationDescriptor owner = descriptor.getContainingDeclaration();
|
||||
if (owner instanceof PackageFragmentDescriptor) {
|
||||
return new ClassId(((PackageFragmentDescriptor) owner).getFqName(), descriptor.getName());
|
||||
}
|
||||
else if (owner instanceof ClassDescriptor) {
|
||||
return getClassId((ClassDescriptor) owner).createNestedClassId(descriptor.getName());
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException("Illegal container: " + descriptor);
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-2
@@ -27,8 +27,7 @@ public class JavaClassDataFinder(
|
||||
private val deserializedDescriptorResolver: DeserializedDescriptorResolver
|
||||
) : ClassDataFinder {
|
||||
override fun findClassData(classId: ClassId): ClassData? {
|
||||
val javaClassId = DeserializedResolverUtils.kotlinClassIdToJavaClassId(classId)
|
||||
val kotlinJvmBinaryClass = kotlinClassFinder.findKotlinClass(javaClassId) ?: return null
|
||||
val kotlinJvmBinaryClass = kotlinClassFinder.findKotlinClass(classId) ?: return null
|
||||
val data = deserializedDescriptorResolver.readData(kotlinJvmBinaryClass, KotlinClassHeader.Kind.CLASS) ?: return null
|
||||
return JvmProtoBufUtil.readClassDataFrom(data)
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ public object BuiltInsSerializationUtil {
|
||||
private val STRING_TABLE_FILE_NAME = ".kotlin_string_table"
|
||||
private val CLASS_NAMES_FILE_NAME = ".kotlin_class_names"
|
||||
|
||||
platformStatic public fun getClassMetadataPath(classId: ClassId): String? {
|
||||
platformStatic public fun getClassMetadataPath(classId: ClassId): String {
|
||||
return packageFqNameToPath(classId.getPackageFqName()) + "/" + classId.getRelativeClassName().asString() +
|
||||
"." + CLASS_METADATA_FILE_EXTENSION
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind.*
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
|
||||
public fun ClassDescriptor.getClassObjectReferenceTarget(): ClassDescriptor {
|
||||
val classObjectDescriptor = getClassObjectDescriptor()
|
||||
@@ -46,4 +47,16 @@ public fun ModuleDescriptor.resolveTopLevelClass(topLevelClassFqName: FqName): C
|
||||
assert(!topLevelClassFqName.isRoot())
|
||||
return getPackage(topLevelClassFqName.parent())?.getMemberScope()
|
||||
?.getClassifier(topLevelClassFqName.shortName()) as? ClassDescriptor
|
||||
}
|
||||
}
|
||||
|
||||
public val ClassDescriptor.classId: ClassId
|
||||
get() {
|
||||
val owner = getContainingDeclaration()
|
||||
if (owner is PackageFragmentDescriptor) {
|
||||
return ClassId(owner.fqName, getName())
|
||||
}
|
||||
else if (owner is ClassDescriptor) {
|
||||
return owner.classId.createNestedClassId(getName())
|
||||
}
|
||||
throw IllegalStateException("Illegal container: $owner")
|
||||
}
|
||||
+1
-3
@@ -20,7 +20,6 @@ import org.jetbrains.kotlin.load.kotlin.KotlinClassFinder
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaClass
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinaryClass
|
||||
import org.jetbrains.kotlin.load.kotlin.DeserializedResolverUtils
|
||||
import org.jetbrains.kotlin.idea.decompiler.isKotlinWithCompatibleAbiVersion
|
||||
import org.jetbrains.kotlin.load.kotlin.KotlinBinaryClassCache
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
@@ -40,8 +39,7 @@ class LocalClassFinder(
|
||||
if (classId.getPackageFqName() != directoryPackageFqName) {
|
||||
return null
|
||||
}
|
||||
val segments = DeserializedResolverUtils.kotlinFqNameToJavaFqName(classId.getRelativeClassName()).pathSegments()
|
||||
val targetName = segments.joinToString("$", postfix = ".class")
|
||||
val targetName = classId.getRelativeClassName().pathSegments().joinToString("$", postfix = ".class")
|
||||
val virtualFile = packageDirectory.findChild(targetName)
|
||||
if (virtualFile != null && isKotlinWithCompatibleAbiVersion(virtualFile)) {
|
||||
return KotlinBinaryClassCache.getKotlinBinaryClass(virtualFile)
|
||||
|
||||
+1
-1
@@ -57,8 +57,8 @@ import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
|
||||
import static org.jetbrains.kotlin.load.kotlin.DeserializedResolverUtils.getClassId;
|
||||
import static org.jetbrains.kotlin.resolve.DescriptorUtils.unwrapFakeOverride;
|
||||
import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilPackage.getClassId;
|
||||
import static org.jetbrains.kotlin.serialization.deserialization.DeserializationPackage.findClassAcrossModuleDependencies;
|
||||
|
||||
public class BuiltInsReferenceResolver extends AbstractProjectComponent {
|
||||
|
||||
Reference in New Issue
Block a user