Fix multiple 'unresolved java classifier' errors
Use the same component (NotFoundClasses) as in loading of compiled Kotlin symbols. Some tests were changed to avoid a diagnostic that is now reported when a non-found class is encountered in a signature (e.g. staticMethod.1.java where JDK seems to be not configured) #KT-10493 Fixed #KT-10820 Fixed #KT-11368 Fixed
This commit is contained in:
+8
-8
@@ -37,6 +37,7 @@ import org.jetbrains.kotlin.name.isValidJavaFqName
|
||||
import org.jetbrains.kotlin.resolve.constants.StringValue
|
||||
import org.jetbrains.kotlin.resolve.scopes.InnerClassesScopeWrapper
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
import org.jetbrains.kotlin.serialization.deserialization.NotFoundClasses
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
import org.jetbrains.kotlin.utils.toReadOnlyList
|
||||
@@ -141,18 +142,17 @@ class LazyJavaClassDescriptor(
|
||||
val purelyImplementedSupertype: KotlinType? = getPurelyImplementedSupertype()
|
||||
|
||||
for (javaType in javaTypes) {
|
||||
val jetType = c.typeResolver.transformJavaType(javaType, TypeUsage.SUPERTYPE.toAttributes())
|
||||
if (jetType.isError) {
|
||||
val kotlinType = c.typeResolver.transformJavaType(javaType, TypeUsage.SUPERTYPE.toAttributes())
|
||||
if (kotlinType.constructor.declarationDescriptor is NotFoundClasses.MockClassDescriptor) {
|
||||
incomplete.add(javaType)
|
||||
}
|
||||
|
||||
if (kotlinType.constructor == purelyImplementedSupertype?.constructor) {
|
||||
continue
|
||||
}
|
||||
|
||||
if (jetType.constructor == purelyImplementedSupertype?.constructor) {
|
||||
continue
|
||||
}
|
||||
|
||||
if (!KotlinBuiltIns.isAnyOrNullableAny(jetType)) {
|
||||
result.add(jetType)
|
||||
if (!KotlinBuiltIns.isAnyOrNullableAny(kotlinType)) {
|
||||
result.add(kotlinType)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+11
-7
@@ -104,18 +104,13 @@ class LazyJavaTypeResolver(
|
||||
private val classifier = c.storageManager.createNullableLazyValue { javaType.classifier }
|
||||
|
||||
override fun computeTypeConstructor(): TypeConstructor {
|
||||
val classifier = classifier()
|
||||
if (classifier == null) {
|
||||
return ErrorUtils.createErrorTypeConstructor("Unresolved java classifier: " + javaType.presentableText)
|
||||
}
|
||||
val classifier = classifier() ?: return createNotFoundClass()
|
||||
return when (classifier) {
|
||||
is JavaClass -> {
|
||||
val fqName = classifier.fqName.sure { "Class type should have a FQ name: $classifier" }
|
||||
|
||||
val classData = mapKotlinClass(fqName) ?: c.components.moduleClassResolver.resolveClass(classifier)
|
||||
|
||||
classData?.typeConstructor
|
||||
?: ErrorUtils.createErrorTypeConstructor("Unresolved java classifier: " + javaType.presentableText)
|
||||
classData?.typeConstructor ?: createNotFoundClass()
|
||||
}
|
||||
is JavaTypeParameter -> {
|
||||
typeParameterResolver.resolveTypeParameter(classifier)?.typeConstructor
|
||||
@@ -125,6 +120,15 @@ class LazyJavaTypeResolver(
|
||||
}
|
||||
}
|
||||
|
||||
// There's no way to extract precise type information in PSI when the type's classifier cannot be resolved.
|
||||
// So we just take the canonical text of the type (which seems to be the only option at the moment), erase all type arguments
|
||||
// and treat the resulting qualified name as if it references a simple top-level class.
|
||||
// Note that this makes MISSING_DEPENDENCY_CLASS diagnostic messages not as precise as they could be in some corner cases.
|
||||
private fun createNotFoundClass(): TypeConstructor {
|
||||
val classId = parseCanonicalFqNameIgnoringTypeArguments(javaType.canonicalText)
|
||||
return c.components.deserializedDescriptorResolver.components.notFoundClasses.get(classId, listOf(0))
|
||||
}
|
||||
|
||||
private fun mapKotlinClass(fqName: FqName): ClassDescriptor? {
|
||||
if (attr.isForAnnotationParameter && fqName == JAVA_LANG_CLASS_FQ_NAME) {
|
||||
return c.reflectionTypes.kClass
|
||||
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2010-2016 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.java.lazy.types
|
||||
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
|
||||
/**
|
||||
* Parse the given FQ name with possible generic arguments to a **top-level** ClassId instance.
|
||||
* E.g. "test.A<B>.C<D, E>" is parsed to a ClassId "test/A/C" which represents a class named "C" declared in package "test.A".
|
||||
*/
|
||||
internal fun parseCanonicalFqNameIgnoringTypeArguments(fqName: String): ClassId {
|
||||
val nameParts = fqName.splitCanonicalFqName()
|
||||
val resultingClassFqName = FqName(nameParts.joinToString(separator = ".") { it.substringBefore('<') })
|
||||
return ClassId.topLevel(resultingClassFqName)
|
||||
}
|
||||
|
||||
// "test.A<B.C>.D<E<F.G, H>, I.J>" -> ["test", "A<B.C>", "D<E<F.G, H>, I.J>"]
|
||||
private fun String.splitCanonicalFqName(): List<String> {
|
||||
val result = arrayListOf<String>()
|
||||
var balance = 0
|
||||
var currentNameStart = 0
|
||||
for ((index, character) in this.withIndex()) {
|
||||
when (character) {
|
||||
'.' -> if (balance == 0) {
|
||||
result.add(this.substring(currentNameStart, index))
|
||||
currentNameStart = index + 1
|
||||
}
|
||||
'<' -> balance++
|
||||
'>' -> balance--
|
||||
}
|
||||
}
|
||||
result.add(this.substring(currentNameStart))
|
||||
return result
|
||||
}
|
||||
@@ -30,6 +30,7 @@ interface JavaClassifierType : JavaType, JavaAnnotationOwner {
|
||||
|
||||
val isRaw: Boolean
|
||||
|
||||
val canonicalText: String
|
||||
val presentableText: String
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user