Drop DeserializedResolverUtils and it's usages
This commit is contained in:
+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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user