GlobalJavaResolverContext -> JavaResolverComponents
This commit is contained in:
+1
-1
@@ -99,7 +99,7 @@ abstract class AbstractJavaAnnotationDescriptor(
|
|||||||
annotation: JavaAnnotation?,
|
annotation: JavaAnnotation?,
|
||||||
private val kotlinAnnotationClassDescriptor: ClassDescriptor
|
private val kotlinAnnotationClassDescriptor: ClassDescriptor
|
||||||
): AnnotationDescriptor {
|
): AnnotationDescriptor {
|
||||||
private val source = annotation?.let { c.sourceElementFactory.source(it) } ?: SourceElement.NO_SOURCE
|
private val source = annotation?.let { c.components.sourceElementFactory.source(it) } ?: SourceElement.NO_SOURCE
|
||||||
|
|
||||||
override fun getType() = kotlinAnnotationClassDescriptor.defaultType
|
override fun getType() = kotlinAnnotationClassDescriptor.defaultType
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -27,7 +27,7 @@ class LazyJavaAnnotations(
|
|||||||
private val c: LazyJavaResolverContext,
|
private val c: LazyJavaResolverContext,
|
||||||
private val annotationOwner: JavaAnnotationOwner
|
private val annotationOwner: JavaAnnotationOwner
|
||||||
) : Annotations {
|
) : Annotations {
|
||||||
private val annotationDescriptors = c.storageManager.createMemoizedFunctionWithNullableValues {
|
private val annotationDescriptors = c.components.storageManager.createMemoizedFunctionWithNullableValues {
|
||||||
annotation: JavaAnnotation -> JavaAnnotationMapper.mapOrResolveJavaAnnotation(annotation, c)
|
annotation: JavaAnnotation -> JavaAnnotationMapper.mapOrResolveJavaAnnotation(annotation, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,7 +36,7 @@ class LazyJavaAnnotations(
|
|||||||
?: JavaAnnotationMapper.findMappedJavaAnnotation(fqName, annotationOwner, c)
|
?: JavaAnnotationMapper.findMappedJavaAnnotation(fqName, annotationOwner, c)
|
||||||
|
|
||||||
override fun findExternalAnnotation(fqName: FqName) =
|
override fun findExternalAnnotation(fqName: FqName) =
|
||||||
c.externalAnnotationResolver.findExternalAnnotation(annotationOwner, fqName)?.let(annotationDescriptors)
|
c.components.externalAnnotationResolver.findExternalAnnotation(annotationOwner, fqName)?.let(annotationDescriptors)
|
||||||
|
|
||||||
override fun iterator() =
|
override fun iterator() =
|
||||||
(annotationOwner.annotations.asSequence().map(annotationDescriptors)
|
(annotationOwner.annotations.asSequence().map(annotationDescriptors)
|
||||||
|
|||||||
+5
-5
@@ -28,18 +28,18 @@ import org.jetbrains.kotlin.storage.MemoizedFunctionToNullable
|
|||||||
import org.jetbrains.kotlin.utils.emptyOrSingletonList
|
import org.jetbrains.kotlin.utils.emptyOrSingletonList
|
||||||
|
|
||||||
public class LazyJavaPackageFragmentProvider(
|
public class LazyJavaPackageFragmentProvider(
|
||||||
outerContext: GlobalJavaResolverContext,
|
components: JavaResolverComponents,
|
||||||
module: ModuleDescriptor,
|
module: ModuleDescriptor,
|
||||||
reflectionTypes: ReflectionTypes
|
reflectionTypes: ReflectionTypes
|
||||||
) : PackageFragmentProvider {
|
) : PackageFragmentProvider {
|
||||||
|
|
||||||
private val c =
|
private val c =
|
||||||
LazyJavaResolverContext(outerContext, this, FragmentClassResolver(), module, reflectionTypes, TypeParameterResolver.EMPTY)
|
LazyJavaResolverContext(components, this, FragmentClassResolver(), module, reflectionTypes, TypeParameterResolver.EMPTY)
|
||||||
|
|
||||||
private val packageFragments: MemoizedFunctionToNullable<FqName, LazyJavaPackageFragment> =
|
private val packageFragments: MemoizedFunctionToNullable<FqName, LazyJavaPackageFragment> =
|
||||||
c.storageManager.createMemoizedFunctionWithNullableValues {
|
c.storageManager.createMemoizedFunctionWithNullableValues {
|
||||||
fqName ->
|
fqName ->
|
||||||
val jPackage = c.finder.findPackage(fqName)
|
val jPackage = c.components.finder.findPackage(fqName)
|
||||||
if (jPackage != null) {
|
if (jPackage != null) {
|
||||||
LazyJavaPackageFragment(c, jPackage)
|
LazyJavaPackageFragment(c, jPackage)
|
||||||
}
|
}
|
||||||
@@ -59,7 +59,7 @@ public class LazyJavaPackageFragmentProvider(
|
|||||||
override fun resolveClass(javaClass: JavaClass): ClassDescriptor? {
|
override fun resolveClass(javaClass: JavaClass): ClassDescriptor? {
|
||||||
val fqName = javaClass.fqName
|
val fqName = javaClass.fqName
|
||||||
if (fqName != null && javaClass.originKind == JavaClass.OriginKind.KOTLIN_LIGHT_CLASS) {
|
if (fqName != null && javaClass.originKind == JavaClass.OriginKind.KOTLIN_LIGHT_CLASS) {
|
||||||
return c.javaResolverCache.getClassResolvedFromSource(fqName)
|
return c.components.javaResolverCache.getClassResolvedFromSource(fqName)
|
||||||
}
|
}
|
||||||
|
|
||||||
javaClass.outerClass?.let { outerClass ->
|
javaClass.outerClass?.let { outerClass ->
|
||||||
@@ -67,7 +67,7 @@ public class LazyJavaPackageFragmentProvider(
|
|||||||
return outerClassScope?.getClassifier(javaClass.name) as? ClassDescriptor
|
return outerClassScope?.getClassifier(javaClass.name) as? ClassDescriptor
|
||||||
}
|
}
|
||||||
|
|
||||||
val kotlinResult = c.resolveKotlinBinaryClass(c.kotlinClassFinder.findKotlinClass(javaClass))
|
val kotlinResult = c.resolveKotlinBinaryClass(c.components.kotlinClassFinder.findKotlinClass(javaClass))
|
||||||
if (kotlinResult is KotlinClassLookupResult.Found) return kotlinResult.descriptor
|
if (kotlinResult is KotlinClassLookupResult.Found) return kotlinResult.descriptor
|
||||||
|
|
||||||
if (fqName == null) return null
|
if (fqName == null) return null
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ import org.jetbrains.kotlin.load.kotlin.KotlinClassFinder
|
|||||||
import org.jetbrains.kotlin.serialization.deserialization.ErrorReporter
|
import org.jetbrains.kotlin.serialization.deserialization.ErrorReporter
|
||||||
import org.jetbrains.kotlin.storage.StorageManager
|
import org.jetbrains.kotlin.storage.StorageManager
|
||||||
|
|
||||||
open class GlobalJavaResolverContext(
|
class JavaResolverComponents(
|
||||||
val storageManager: StorageManager,
|
val storageManager: StorageManager,
|
||||||
val finder: JavaClassFinder,
|
val finder: JavaClassFinder,
|
||||||
val kotlinClassFinder: KotlinClassFinder,
|
val kotlinClassFinder: KotlinClassFinder,
|
||||||
@@ -49,32 +49,22 @@ open class GlobalJavaResolverContext(
|
|||||||
)
|
)
|
||||||
|
|
||||||
open class LazyJavaResolverContext(
|
open class LazyJavaResolverContext(
|
||||||
globalContext: GlobalJavaResolverContext,
|
val components: JavaResolverComponents,
|
||||||
val packageFragmentProvider: LazyJavaPackageFragmentProvider,
|
val packageFragmentProvider: LazyJavaPackageFragmentProvider,
|
||||||
val javaClassResolver: LazyJavaClassResolver,
|
val javaClassResolver: LazyJavaClassResolver,
|
||||||
val module: ModuleDescriptor,
|
val module: ModuleDescriptor,
|
||||||
val reflectionTypes: ReflectionTypes,
|
val reflectionTypes: ReflectionTypes,
|
||||||
val typeParameterResolver: TypeParameterResolver
|
val typeParameterResolver: TypeParameterResolver
|
||||||
) : GlobalJavaResolverContext(
|
|
||||||
globalContext.storageManager,
|
|
||||||
globalContext.finder,
|
|
||||||
globalContext.kotlinClassFinder,
|
|
||||||
globalContext.deserializedDescriptorResolver,
|
|
||||||
globalContext.externalAnnotationResolver,
|
|
||||||
globalContext.externalSignatureResolver,
|
|
||||||
globalContext.errorReporter,
|
|
||||||
globalContext.javaResolverCache,
|
|
||||||
globalContext.javaPropertyInitializerEvaluator,
|
|
||||||
globalContext.samConversionResolver,
|
|
||||||
globalContext.sourceElementFactory,
|
|
||||||
globalContext.moduleClassResolver
|
|
||||||
) {
|
) {
|
||||||
val typeResolver = LazyJavaTypeResolver(this, typeParameterResolver)
|
val typeResolver = LazyJavaTypeResolver(this, typeParameterResolver)
|
||||||
|
|
||||||
|
val storageManager: StorageManager
|
||||||
|
get() = components.storageManager
|
||||||
}
|
}
|
||||||
|
|
||||||
fun LazyJavaResolverContext.child(
|
fun LazyJavaResolverContext.child(
|
||||||
typeParameterResolver: TypeParameterResolver
|
typeParameterResolver: TypeParameterResolver
|
||||||
) = LazyJavaResolverContext(this, packageFragmentProvider, javaClassResolver, module, reflectionTypes, typeParameterResolver)
|
) = LazyJavaResolverContext(components, packageFragmentProvider, javaClassResolver, module, reflectionTypes, typeParameterResolver)
|
||||||
|
|
||||||
|
|
||||||
fun LazyJavaResolverContext.child(
|
fun LazyJavaResolverContext.child(
|
||||||
|
|||||||
+2
-2
@@ -56,11 +56,11 @@ class LazyJavaAnnotationDescriptor(
|
|||||||
private val type = c.storageManager.createLazyValue {
|
private val type = c.storageManager.createLazyValue {
|
||||||
val fqName = fqName() ?: return@createLazyValue ErrorUtils.createErrorType("No fqName: $javaAnnotation")
|
val fqName = fqName() ?: return@createLazyValue ErrorUtils.createErrorType("No fqName: $javaAnnotation")
|
||||||
val annotationClass = JavaToKotlinClassMap.INSTANCE.mapJavaToKotlin(fqName)
|
val annotationClass = JavaToKotlinClassMap.INSTANCE.mapJavaToKotlin(fqName)
|
||||||
?: javaAnnotation.resolve()?.let { javaClass -> c.moduleClassResolver.resolveClass(javaClass) }
|
?: javaAnnotation.resolve()?.let { javaClass -> c.components.moduleClassResolver.resolveClass(javaClass) }
|
||||||
annotationClass?.getDefaultType() ?: ErrorUtils.createErrorType(fqName.asString())
|
annotationClass?.getDefaultType() ?: ErrorUtils.createErrorType(fqName.asString())
|
||||||
}
|
}
|
||||||
|
|
||||||
private val source = c.sourceElementFactory.source(javaAnnotation)
|
private val source = c.components.sourceElementFactory.source(javaAnnotation)
|
||||||
|
|
||||||
private val factory = ConstantValueFactory(c.module.builtIns)
|
private val factory = ConstantValueFactory(c.module.builtIns)
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -47,12 +47,12 @@ class LazyJavaClassDescriptor(
|
|||||||
internal val fqName: FqName,
|
internal val fqName: FqName,
|
||||||
private val jClass: JavaClass
|
private val jClass: JavaClass
|
||||||
) : ClassDescriptorBase(outerC.storageManager, containingDeclaration, fqName.shortName(),
|
) : ClassDescriptorBase(outerC.storageManager, containingDeclaration, fqName.shortName(),
|
||||||
outerC.sourceElementFactory.source(jClass)), JavaClassDescriptor {
|
outerC.components.sourceElementFactory.source(jClass)), JavaClassDescriptor {
|
||||||
|
|
||||||
private val c: LazyJavaResolverContext = outerC.child(this, jClass)
|
private val c: LazyJavaResolverContext = outerC.child(this, jClass)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
c.javaResolverCache.recordClass(jClass, this)
|
c.components.javaResolverCache.recordClass(jClass, this)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val kind = when {
|
private val kind = when {
|
||||||
@@ -96,7 +96,7 @@ class LazyJavaClassDescriptor(
|
|||||||
override fun getAnnotations() = annotations()
|
override fun getAnnotations() = annotations()
|
||||||
|
|
||||||
private val functionTypeForSamInterface = c.storageManager.createNullableLazyValue {
|
private val functionTypeForSamInterface = c.storageManager.createNullableLazyValue {
|
||||||
c.samConversionResolver.resolveFunctionTypeIfSamInterface(this) { method ->
|
c.components.samConversionResolver.resolveFunctionTypeIfSamInterface(this) { method ->
|
||||||
unsubstitutedMemberScope.resolveMethodToFunctionDescriptor(method, false)
|
unsubstitutedMemberScope.resolveMethodToFunctionDescriptor(method, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -145,7 +145,7 @@ class LazyJavaClassDescriptor(
|
|||||||
result.addIfNotNull(purelyImplementedSupertype)
|
result.addIfNotNull(purelyImplementedSupertype)
|
||||||
|
|
||||||
if (incomplete.isNotEmpty()) {
|
if (incomplete.isNotEmpty()) {
|
||||||
c.errorReporter.reportIncompleteHierarchy(getDeclarationDescriptor(), incomplete.map { javaType ->
|
c.components.errorReporter.reportIncompleteHierarchy(getDeclarationDescriptor(), incomplete.map { javaType ->
|
||||||
(javaType as JavaClassifierType).getPresentableText()
|
(javaType as JavaClassifierType).getPresentableText()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-14
@@ -68,7 +68,7 @@ public class LazyJavaClassMemberScope(
|
|||||||
for (constructor in constructors) {
|
for (constructor in constructors) {
|
||||||
val descriptor = resolveConstructor(constructor)
|
val descriptor = resolveConstructor(constructor)
|
||||||
result.add(descriptor)
|
result.add(descriptor)
|
||||||
result.addIfNotNull(c.samConversionResolver.resolveSamAdapter(descriptor))
|
result.addIfNotNull(c.components.samConversionResolver.resolveSamAdapter(descriptor))
|
||||||
}
|
}
|
||||||
|
|
||||||
enhanceSignatures(
|
enhanceSignatures(
|
||||||
@@ -78,7 +78,7 @@ public class LazyJavaClassMemberScope(
|
|||||||
|
|
||||||
override fun computeNonDeclaredFunctions(result: MutableCollection<SimpleFunctionDescriptor>, name: Name) {
|
override fun computeNonDeclaredFunctions(result: MutableCollection<SimpleFunctionDescriptor>, name: Name) {
|
||||||
val functionsFromSupertypes = getFunctionsFromSupertypes(name, getContainingDeclaration())
|
val functionsFromSupertypes = getFunctionsFromSupertypes(name, getContainingDeclaration())
|
||||||
result.addAll(DescriptorResolverUtils.resolveOverrides(name, functionsFromSupertypes, result, getContainingDeclaration(), c.errorReporter))
|
result.addAll(DescriptorResolverUtils.resolveOverrides(name, functionsFromSupertypes, result, getContainingDeclaration(), c.components.errorReporter))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getFunctionsFromSupertypes(name: Name, descriptor: ClassDescriptor): Set<SimpleFunctionDescriptor> {
|
private fun getFunctionsFromSupertypes(name: Name, descriptor: ClassDescriptor): Set<SimpleFunctionDescriptor> {
|
||||||
@@ -95,7 +95,7 @@ public class LazyJavaClassMemberScope(
|
|||||||
val propertiesFromSupertypes = getPropertiesFromSupertypes(name, getContainingDeclaration())
|
val propertiesFromSupertypes = getPropertiesFromSupertypes(name, getContainingDeclaration())
|
||||||
|
|
||||||
result.addAll(DescriptorResolverUtils.resolveOverrides(name, propertiesFromSupertypes, result, getContainingDeclaration(),
|
result.addAll(DescriptorResolverUtils.resolveOverrides(name, propertiesFromSupertypes, result, getContainingDeclaration(),
|
||||||
c.errorReporter))
|
c.components.errorReporter))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun computeAnnotationProperties(name: Name, result: MutableCollection<PropertyDescriptor>) {
|
private fun computeAnnotationProperties(name: Name, result: MutableCollection<PropertyDescriptor>) {
|
||||||
@@ -104,7 +104,7 @@ public class LazyJavaClassMemberScope(
|
|||||||
|
|
||||||
val propertyDescriptor = JavaPropertyDescriptor(
|
val propertyDescriptor = JavaPropertyDescriptor(
|
||||||
getContainingDeclaration(), annotations, method.getVisibility(),
|
getContainingDeclaration(), annotations, method.getVisibility(),
|
||||||
/* isVar = */ false, method.getName(), c.sourceElementFactory.source(method), /* original */ null
|
/* isVar = */ false, method.getName(), c.components.sourceElementFactory.source(method), /* original */ null
|
||||||
)
|
)
|
||||||
|
|
||||||
// default getter is necessary because there is no real field in annotation
|
// default getter is necessary because there is no real field in annotation
|
||||||
@@ -128,10 +128,10 @@ public class LazyJavaClassMemberScope(
|
|||||||
method: JavaMethod, methodTypeParameters: List<TypeParameterDescriptor>, returnType: JetType,
|
method: JavaMethod, methodTypeParameters: List<TypeParameterDescriptor>, returnType: JetType,
|
||||||
valueParameters: LazyJavaScope.ResolvedValueParameters
|
valueParameters: LazyJavaScope.ResolvedValueParameters
|
||||||
): LazyJavaScope.MethodSignatureData {
|
): LazyJavaScope.MethodSignatureData {
|
||||||
val propagated = c.externalSignatureResolver.resolvePropagatedSignature(
|
val propagated = c.components.externalSignatureResolver.resolvePropagatedSignature(
|
||||||
method, getContainingDeclaration(), returnType, null, valueParameters.descriptors, methodTypeParameters
|
method, getContainingDeclaration(), returnType, null, valueParameters.descriptors, methodTypeParameters
|
||||||
)
|
)
|
||||||
val effectiveSignature = c.externalSignatureResolver.resolveAlternativeMethodSignature(
|
val effectiveSignature = c.components.externalSignatureResolver.resolveAlternativeMethodSignature(
|
||||||
method, !propagated.getSuperMethods().isEmpty(), propagated.getReturnType(),
|
method, !propagated.getSuperMethods().isEmpty(), propagated.getReturnType(),
|
||||||
propagated.getReceiverType(), propagated.getValueParameters(), propagated.getTypeParameters(),
|
propagated.getReceiverType(), propagated.getValueParameters(), propagated.getTypeParameters(),
|
||||||
propagated.hasStableParameterNames()
|
propagated.hasStableParameterNames()
|
||||||
@@ -144,11 +144,11 @@ public class LazyJavaClassMemberScope(
|
|||||||
val classDescriptor = getContainingDeclaration()
|
val classDescriptor = getContainingDeclaration()
|
||||||
|
|
||||||
val constructorDescriptor = JavaConstructorDescriptor.createJavaConstructor(
|
val constructorDescriptor = JavaConstructorDescriptor.createJavaConstructor(
|
||||||
classDescriptor, c.resolveAnnotations(constructor), /* isPrimary = */ false, c.sourceElementFactory.source(constructor)
|
classDescriptor, c.resolveAnnotations(constructor), /* isPrimary = */ false, c.components.sourceElementFactory.source(constructor)
|
||||||
)
|
)
|
||||||
|
|
||||||
val valueParameters = resolveValueParameters(c, constructorDescriptor, constructor.getValueParameters())
|
val valueParameters = resolveValueParameters(c, constructorDescriptor, constructor.getValueParameters())
|
||||||
val effectiveSignature = c.externalSignatureResolver.resolveAlternativeMethodSignature(
|
val effectiveSignature = c.components.externalSignatureResolver.resolveAlternativeMethodSignature(
|
||||||
constructor, false, null, null, valueParameters.descriptors, Collections.emptyList(), false)
|
constructor, false, null, null, valueParameters.descriptors, Collections.emptyList(), false)
|
||||||
|
|
||||||
constructorDescriptor.initialize(
|
constructorDescriptor.initialize(
|
||||||
@@ -163,10 +163,10 @@ public class LazyJavaClassMemberScope(
|
|||||||
|
|
||||||
val signatureErrors = effectiveSignature.getErrors()
|
val signatureErrors = effectiveSignature.getErrors()
|
||||||
if (!signatureErrors.isEmpty()) {
|
if (!signatureErrors.isEmpty()) {
|
||||||
c.externalSignatureResolver.reportSignatureErrors(constructorDescriptor, signatureErrors)
|
c.components.externalSignatureResolver.reportSignatureErrors(constructorDescriptor, signatureErrors)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.javaResolverCache.recordConstructor(constructor, constructorDescriptor)
|
c.components.javaResolverCache.recordConstructor(constructor, constructorDescriptor)
|
||||||
|
|
||||||
return constructorDescriptor
|
return constructorDescriptor
|
||||||
}
|
}
|
||||||
@@ -178,7 +178,7 @@ public class LazyJavaClassMemberScope(
|
|||||||
|
|
||||||
val classDescriptor = getContainingDeclaration()
|
val classDescriptor = getContainingDeclaration()
|
||||||
val constructorDescriptor = JavaConstructorDescriptor.createJavaConstructor(
|
val constructorDescriptor = JavaConstructorDescriptor.createJavaConstructor(
|
||||||
classDescriptor, Annotations.EMPTY, /* isPrimary = */ true, c.sourceElementFactory.source(jClass)
|
classDescriptor, Annotations.EMPTY, /* isPrimary = */ true, c.components.sourceElementFactory.source(jClass)
|
||||||
)
|
)
|
||||||
val typeParameters = classDescriptor.getTypeConstructor().getParameters()
|
val typeParameters = classDescriptor.getTypeConstructor().getParameters()
|
||||||
val valueParameters = if (isAnnotation) createAnnotationConstructorParameters(constructorDescriptor)
|
val valueParameters = if (isAnnotation) createAnnotationConstructorParameters(constructorDescriptor)
|
||||||
@@ -188,7 +188,7 @@ public class LazyJavaClassMemberScope(
|
|||||||
constructorDescriptor.initialize(typeParameters, valueParameters, getConstructorVisibility(classDescriptor))
|
constructorDescriptor.initialize(typeParameters, valueParameters, getConstructorVisibility(classDescriptor))
|
||||||
constructorDescriptor.setHasStableParameterNames(true)
|
constructorDescriptor.setHasStableParameterNames(true)
|
||||||
constructorDescriptor.setReturnType(classDescriptor.getDefaultType())
|
constructorDescriptor.setReturnType(classDescriptor.getDefaultType())
|
||||||
c.javaResolverCache.recordConstructor(jClass, constructorDescriptor);
|
c.components.javaResolverCache.recordConstructor(jClass, constructorDescriptor);
|
||||||
return constructorDescriptor
|
return constructorDescriptor
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -250,7 +250,7 @@ public class LazyJavaClassMemberScope(
|
|||||||
method.hasAnnotationParameterDefaultValue(),
|
method.hasAnnotationParameterDefaultValue(),
|
||||||
// Nulls are not allowed in annotation arguments in Java
|
// Nulls are not allowed in annotation arguments in Java
|
||||||
varargElementType?.let { TypeUtils.makeNotNullable(it) },
|
varargElementType?.let { TypeUtils.makeNotNullable(it) },
|
||||||
c.sourceElementFactory.source(method)
|
c.components.sourceElementFactory.source(method)
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -271,7 +271,7 @@ public class LazyJavaClassMemberScope(
|
|||||||
EnumEntrySyntheticClassDescriptor.create(c.storageManager, getContainingDeclaration(), name,
|
EnumEntrySyntheticClassDescriptor.create(c.storageManager, getContainingDeclaration(), name,
|
||||||
c.storageManager.createLazyValue {
|
c.storageManager.createLazyValue {
|
||||||
memberIndex().getAllFieldNames() + memberIndex().getMethodNames({true})
|
memberIndex().getAllFieldNames() + memberIndex().getMethodNames({true})
|
||||||
}, c.sourceElementFactory.source(field))
|
}, c.components.sourceElementFactory.source(field))
|
||||||
}
|
}
|
||||||
else null
|
else null
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-5
@@ -45,14 +45,14 @@ public class LazyJavaPackageScope(
|
|||||||
// TODO: Storing references is a temporary hack until modules infrastructure is implemented.
|
// TODO: Storing references is a temporary hack until modules infrastructure is implemented.
|
||||||
// See JetTypeMapperWithOutDirectories for details
|
// See JetTypeMapperWithOutDirectories for details
|
||||||
public val kotlinBinaryClass: KotlinJvmBinaryClass?
|
public val kotlinBinaryClass: KotlinJvmBinaryClass?
|
||||||
= c.kotlinClassFinder.findKotlinClass(PackageClassUtils.getPackageClassId(packageFragment.fqName))
|
= c.components.kotlinClassFinder.findKotlinClass(PackageClassUtils.getPackageClassId(packageFragment.fqName))
|
||||||
|
|
||||||
private val deserializedPackageScope = c.storageManager.createLazyValue {
|
private val deserializedPackageScope = c.storageManager.createLazyValue {
|
||||||
val kotlinBinaryClass = kotlinBinaryClass
|
val kotlinBinaryClass = kotlinBinaryClass
|
||||||
if (kotlinBinaryClass == null)
|
if (kotlinBinaryClass == null)
|
||||||
JetScope.Empty
|
JetScope.Empty
|
||||||
else
|
else
|
||||||
c.deserializedDescriptorResolver.createKotlinPackageScope(packageFragment, kotlinBinaryClass) ?: JetScope.Empty
|
c.components.deserializedDescriptorResolver.createKotlinPackageScope(packageFragment, kotlinBinaryClass) ?: JetScope.Empty
|
||||||
}
|
}
|
||||||
|
|
||||||
private val packageFragment: LazyJavaPackageFragment get() = getContainingDeclaration() as LazyJavaPackageFragment
|
private val packageFragment: LazyJavaPackageFragment get() = getContainingDeclaration() as LazyJavaPackageFragment
|
||||||
@@ -60,12 +60,12 @@ public class LazyJavaPackageScope(
|
|||||||
private val classes = c.storageManager.createMemoizedFunctionWithNullableValues<Name, ClassDescriptor> { name ->
|
private val classes = c.storageManager.createMemoizedFunctionWithNullableValues<Name, ClassDescriptor> { name ->
|
||||||
val classId = ClassId(packageFragment.fqName, name)
|
val classId = ClassId(packageFragment.fqName, name)
|
||||||
|
|
||||||
val kotlinResult = c.resolveKotlinBinaryClass(c.kotlinClassFinder.findKotlinClass(classId))
|
val kotlinResult = c.resolveKotlinBinaryClass(c.components.kotlinClassFinder.findKotlinClass(classId))
|
||||||
when (kotlinResult) {
|
when (kotlinResult) {
|
||||||
is KotlinClassLookupResult.Found -> kotlinResult.descriptor
|
is KotlinClassLookupResult.Found -> kotlinResult.descriptor
|
||||||
is KotlinClassLookupResult.SyntheticClass -> null
|
is KotlinClassLookupResult.SyntheticClass -> null
|
||||||
is KotlinClassLookupResult.NotFound -> {
|
is KotlinClassLookupResult.NotFound -> {
|
||||||
c.finder.findClass(classId)?.let { javaClass ->
|
c.components.finder.findClass(classId)?.let { javaClass ->
|
||||||
c.javaClassResolver.resolveClass(javaClass).apply {
|
c.javaClassResolver.resolveClass(javaClass).apply {
|
||||||
assert(this == null || this.containingDeclaration == packageFragment) {
|
assert(this == null || this.containingDeclaration == packageFragment) {
|
||||||
"Wrong package fragment for $this, expected $packageFragment"
|
"Wrong package fragment for $this, expected $packageFragment"
|
||||||
@@ -118,7 +118,7 @@ public class LazyJavaPackageScope(
|
|||||||
)
|
)
|
||||||
|
|
||||||
override fun computeNonDeclaredFunctions(result: MutableCollection<SimpleFunctionDescriptor>, name: Name) {
|
override fun computeNonDeclaredFunctions(result: MutableCollection<SimpleFunctionDescriptor>, name: Name) {
|
||||||
result.addIfNotNull(c.samConversionResolver.resolveSamConstructor(name, this))
|
result.addIfNotNull(c.components.samConversionResolver.resolveSamConstructor(name, this))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getSubPackages() = subPackages()
|
override fun getSubPackages() = subPackages()
|
||||||
|
|||||||
+11
-11
@@ -84,7 +84,7 @@ public abstract class LazyJavaScope(
|
|||||||
val descriptor = resolveMethodToFunctionDescriptor(method, true)
|
val descriptor = resolveMethodToFunctionDescriptor(method, true)
|
||||||
result.add(descriptor)
|
result.add(descriptor)
|
||||||
if (method.isStatic) {
|
if (method.isStatic) {
|
||||||
result.addIfNotNull(c.samConversionResolver.resolveSamAdapter(descriptor))
|
result.addIfNotNull(c.components.samConversionResolver.resolveSamAdapter(descriptor))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,7 +107,7 @@ public abstract class LazyJavaScope(
|
|||||||
fun resolveMethodToFunctionDescriptor(method: JavaMethod, record: Boolean = true): JavaMethodDescriptor {
|
fun resolveMethodToFunctionDescriptor(method: JavaMethod, record: Boolean = true): JavaMethodDescriptor {
|
||||||
val annotations = c.resolveAnnotations(method)
|
val annotations = c.resolveAnnotations(method)
|
||||||
val functionDescriptorImpl = JavaMethodDescriptor.createJavaMethod(
|
val functionDescriptorImpl = JavaMethodDescriptor.createJavaMethod(
|
||||||
containingDeclaration, annotations, method.getName(), c.sourceElementFactory.source(method)
|
containingDeclaration, annotations, method.getName(), c.components.sourceElementFactory.source(method)
|
||||||
)
|
)
|
||||||
|
|
||||||
val c = c.child(functionDescriptorImpl, method)
|
val c = c.child(functionDescriptorImpl, method)
|
||||||
@@ -132,11 +132,11 @@ public abstract class LazyJavaScope(
|
|||||||
functionDescriptorImpl.setParameterNamesStatus(effectiveSignature.hasStableParameterNames(), valueParameters.hasSynthesizedNames)
|
functionDescriptorImpl.setParameterNamesStatus(effectiveSignature.hasStableParameterNames(), valueParameters.hasSynthesizedNames)
|
||||||
|
|
||||||
if (record) {
|
if (record) {
|
||||||
c.javaResolverCache.recordMethod(method, functionDescriptorImpl)
|
c.components.javaResolverCache.recordMethod(method, functionDescriptorImpl)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (signatureErrors.isNotEmpty()) {
|
if (signatureErrors.isNotEmpty()) {
|
||||||
c.externalSignatureResolver.reportSignatureErrors(functionDescriptorImpl, signatureErrors)
|
c.components.externalSignatureResolver.reportSignatureErrors(functionDescriptorImpl, signatureErrors)
|
||||||
}
|
}
|
||||||
|
|
||||||
return functionDescriptorImpl
|
return functionDescriptorImpl
|
||||||
@@ -204,7 +204,7 @@ public abstract class LazyJavaScope(
|
|||||||
outType,
|
outType,
|
||||||
false,
|
false,
|
||||||
varargElementType,
|
varargElementType,
|
||||||
c.sourceElementFactory.source(javaParameter)
|
c.components.sourceElementFactory.source(javaParameter)
|
||||||
)
|
)
|
||||||
}.toList()
|
}.toList()
|
||||||
return ResolvedValueParameters(descriptors, synthesizedNames)
|
return ResolvedValueParameters(descriptors, synthesizedNames)
|
||||||
@@ -242,10 +242,10 @@ public abstract class LazyJavaScope(
|
|||||||
propertyDescriptor.initialize(null, null)
|
propertyDescriptor.initialize(null, null)
|
||||||
|
|
||||||
val propertyType = getPropertyType(field, propertyDescriptor.getAnnotations())
|
val propertyType = getPropertyType(field, propertyDescriptor.getAnnotations())
|
||||||
val effectiveSignature = c.externalSignatureResolver.resolveAlternativeFieldSignature(field, propertyType, isVar)
|
val effectiveSignature = c.components.externalSignatureResolver.resolveAlternativeFieldSignature(field, propertyType, isVar)
|
||||||
val signatureErrors = effectiveSignature.getErrors()
|
val signatureErrors = effectiveSignature.getErrors()
|
||||||
if (!signatureErrors.isEmpty()) {
|
if (!signatureErrors.isEmpty()) {
|
||||||
c.externalSignatureResolver.reportSignatureErrors(propertyDescriptor, signatureErrors)
|
c.components.externalSignatureResolver.reportSignatureErrors(propertyDescriptor, signatureErrors)
|
||||||
}
|
}
|
||||||
|
|
||||||
propertyDescriptor.setType(effectiveSignature.getReturnType(), listOf(), getDispatchReceiverParameter(), null : JetType?)
|
propertyDescriptor.setType(effectiveSignature.getReturnType(), listOf(), getDispatchReceiverParameter(), null : JetType?)
|
||||||
@@ -253,11 +253,11 @@ public abstract class LazyJavaScope(
|
|||||||
if (DescriptorUtils.shouldRecordInitializerForProperty(propertyDescriptor, propertyDescriptor.getType())) {
|
if (DescriptorUtils.shouldRecordInitializerForProperty(propertyDescriptor, propertyDescriptor.getType())) {
|
||||||
propertyDescriptor.setCompileTimeInitializer(
|
propertyDescriptor.setCompileTimeInitializer(
|
||||||
c.storageManager.createNullableLazyValue {
|
c.storageManager.createNullableLazyValue {
|
||||||
c.javaPropertyInitializerEvaluator.getInitializerConstant(field, propertyDescriptor)
|
c.components.javaPropertyInitializerEvaluator.getInitializerConstant(field, propertyDescriptor)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
c.javaResolverCache.recordField(field, propertyDescriptor);
|
c.components.javaResolverCache.recordField(field, propertyDescriptor);
|
||||||
|
|
||||||
return propertyDescriptor
|
return propertyDescriptor
|
||||||
}
|
}
|
||||||
@@ -269,7 +269,7 @@ public abstract class LazyJavaScope(
|
|||||||
val propertyName = field.getName()
|
val propertyName = field.getName()
|
||||||
|
|
||||||
return JavaPropertyDescriptor(containingDeclaration, annotations, visibility, isVar, propertyName,
|
return JavaPropertyDescriptor(containingDeclaration, annotations, visibility, isVar, propertyName,
|
||||||
c.sourceElementFactory.source(field), /* original = */ null)
|
c.components.sourceElementFactory.source(field), /* original = */ null)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getPropertyType(field: JavaField, annotations: Annotations): JetType {
|
private fun getPropertyType(field: JavaField, annotations: Annotations): JetType {
|
||||||
@@ -277,7 +277,7 @@ public abstract class LazyJavaScope(
|
|||||||
val finalStatic = field.isFinal() && field.isStatic()
|
val finalStatic = field.isFinal() && field.isStatic()
|
||||||
|
|
||||||
// simple static constants should not have flexible types:
|
// simple static constants should not have flexible types:
|
||||||
val allowFlexible = PLATFORM_TYPES && !(finalStatic && c.javaPropertyInitializerEvaluator.isNotNullCompileTimeConstant(field))
|
val allowFlexible = PLATFORM_TYPES && !(finalStatic && c.components.javaPropertyInitializerEvaluator.isNotNullCompileTimeConstant(field))
|
||||||
val propertyType = c.typeResolver.transformJavaType(
|
val propertyType = c.typeResolver.transformJavaType(
|
||||||
field.getType(),
|
field.getType(),
|
||||||
LazyJavaTypeAttributes(TypeUsage.MEMBER_SIGNATURE_INVARIANT, annotations, allowFlexible)
|
LazyJavaTypeAttributes(TypeUsage.MEMBER_SIGNATURE_INVARIANT, annotations, allowFlexible)
|
||||||
|
|||||||
+1
-1
@@ -64,7 +64,7 @@ public class LazyJavaStaticClassScope(
|
|||||||
|
|
||||||
override fun computeNonDeclaredFunctions(result: MutableCollection<SimpleFunctionDescriptor>, name: Name) {
|
override fun computeNonDeclaredFunctions(result: MutableCollection<SimpleFunctionDescriptor>, name: Name) {
|
||||||
val nestedClassesScope = getContainingDeclaration().getUnsubstitutedInnerClassesScope()
|
val nestedClassesScope = getContainingDeclaration().getUnsubstitutedInnerClassesScope()
|
||||||
result.addIfNotNull(c.samConversionResolver.resolveSamConstructor(name, nestedClassesScope))
|
result.addIfNotNull(c.components.samConversionResolver.resolveSamConstructor(name, nestedClassesScope))
|
||||||
|
|
||||||
if (jClass.isEnum()) {
|
if (jClass.isEnum()) {
|
||||||
when (name) {
|
when (name) {
|
||||||
|
|||||||
+1
-1
@@ -43,7 +43,7 @@ public abstract class LazyJavaStaticScope(
|
|||||||
method: JavaMethod, methodTypeParameters: List<TypeParameterDescriptor>, returnType: JetType,
|
method: JavaMethod, methodTypeParameters: List<TypeParameterDescriptor>, returnType: JetType,
|
||||||
valueParameters: LazyJavaScope.ResolvedValueParameters
|
valueParameters: LazyJavaScope.ResolvedValueParameters
|
||||||
): LazyJavaScope.MethodSignatureData {
|
): LazyJavaScope.MethodSignatureData {
|
||||||
val effectiveSignature = c.externalSignatureResolver.resolveAlternativeMethodSignature(
|
val effectiveSignature = c.components.externalSignatureResolver.resolveAlternativeMethodSignature(
|
||||||
method, false, returnType, null, valueParameters.descriptors, methodTypeParameters, false)
|
method, false, returnType, null, valueParameters.descriptors, methodTypeParameters, false)
|
||||||
return LazyJavaScope.MethodSignatureData(effectiveSignature, effectiveSignature.getErrors())
|
return LazyJavaScope.MethodSignatureData(effectiveSignature, effectiveSignature.getErrors())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,11 +71,11 @@ fun LazyJavaResolverContext.resolveKotlinBinaryClass(kotlinClass: KotlinJvmBinar
|
|||||||
val header = kotlinClass.classHeader
|
val header = kotlinClass.classHeader
|
||||||
return when {
|
return when {
|
||||||
!header.isCompatibleAbiVersion -> {
|
!header.isCompatibleAbiVersion -> {
|
||||||
errorReporter.reportIncompatibleAbiVersion(kotlinClass.classId, kotlinClass.location, header.version)
|
components.errorReporter.reportIncompatibleAbiVersion(kotlinClass.classId, kotlinClass.location, header.version)
|
||||||
KotlinClassLookupResult.NotFound
|
KotlinClassLookupResult.NotFound
|
||||||
}
|
}
|
||||||
header.kind == KotlinClassHeader.Kind.CLASS -> {
|
header.kind == KotlinClassHeader.Kind.CLASS -> {
|
||||||
val descriptor = deserializedDescriptorResolver.resolveClass(kotlinClass)
|
val descriptor = components.deserializedDescriptorResolver.resolveClass(kotlinClass)
|
||||||
if (descriptor != null) KotlinClassLookupResult.Found(descriptor) else KotlinClassLookupResult.NotFound
|
if (descriptor != null) KotlinClassLookupResult.Found(descriptor) else KotlinClassLookupResult.NotFound
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
|
|||||||
+1
-1
@@ -116,7 +116,7 @@ class LazyJavaTypeResolver(
|
|||||||
is JavaClass -> {
|
is JavaClass -> {
|
||||||
val fqName = classifier.getFqName().sure { "Class type should have a FQ name: $classifier" }
|
val fqName = classifier.getFqName().sure { "Class type should have a FQ name: $classifier" }
|
||||||
|
|
||||||
val classData = mapKotlinClass(fqName) ?: c.moduleClassResolver.resolveClass(classifier)
|
val classData = mapKotlinClass(fqName) ?: c.components.moduleClassResolver.resolveClass(classifier)
|
||||||
|
|
||||||
classData?.getTypeConstructor()
|
classData?.getTypeConstructor()
|
||||||
?: ErrorUtils.createErrorTypeConstructor("Unresolved java classifier: " + javaType.getPresentableText())
|
?: ErrorUtils.createErrorTypeConstructor("Unresolved java classifier: " + javaType.getPresentableText())
|
||||||
|
|||||||
+2
-2
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
|||||||
import org.jetbrains.kotlin.descriptors.ModuleParameters
|
import org.jetbrains.kotlin.descriptors.ModuleParameters
|
||||||
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
|
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
|
||||||
import org.jetbrains.kotlin.load.java.components.*
|
import org.jetbrains.kotlin.load.java.components.*
|
||||||
import org.jetbrains.kotlin.load.java.lazy.GlobalJavaResolverContext
|
import org.jetbrains.kotlin.load.java.lazy.JavaResolverComponents
|
||||||
import org.jetbrains.kotlin.load.java.lazy.LazyJavaPackageFragmentProvider
|
import org.jetbrains.kotlin.load.java.lazy.LazyJavaPackageFragmentProvider
|
||||||
import org.jetbrains.kotlin.load.java.lazy.SingleModuleClassResolver
|
import org.jetbrains.kotlin.load.java.lazy.SingleModuleClassResolver
|
||||||
import org.jetbrains.kotlin.load.java.reflect.ReflectJavaClassFinder
|
import org.jetbrains.kotlin.load.java.reflect.ReflectJavaClassFinder
|
||||||
@@ -47,7 +47,7 @@ public class RuntimeModuleData private constructor(public val module: ModuleDesc
|
|||||||
val reflectKotlinClassFinder = ReflectKotlinClassFinder(classLoader)
|
val reflectKotlinClassFinder = ReflectKotlinClassFinder(classLoader)
|
||||||
val deserializedDescriptorResolver = DeserializedDescriptorResolver(RuntimeErrorReporter)
|
val deserializedDescriptorResolver = DeserializedDescriptorResolver(RuntimeErrorReporter)
|
||||||
val singleModuleClassResolver = SingleModuleClassResolver()
|
val singleModuleClassResolver = SingleModuleClassResolver()
|
||||||
val globalJavaResolverContext = GlobalJavaResolverContext(
|
val globalJavaResolverContext = JavaResolverComponents(
|
||||||
storageManager, ReflectJavaClassFinder(classLoader), reflectKotlinClassFinder, deserializedDescriptorResolver,
|
storageManager, ReflectJavaClassFinder(classLoader), reflectKotlinClassFinder, deserializedDescriptorResolver,
|
||||||
ExternalAnnotationResolver.EMPTY, ExternalSignatureResolver.DO_NOTHING, RuntimeErrorReporter, JavaResolverCache.EMPTY,
|
ExternalAnnotationResolver.EMPTY, ExternalSignatureResolver.DO_NOTHING, RuntimeErrorReporter, JavaResolverCache.EMPTY,
|
||||||
JavaPropertyInitializerEvaluator.DoNothing, SamConversionResolver, RuntimeSourceElementFactory, singleModuleClassResolver
|
JavaPropertyInitializerEvaluator.DoNothing, SamConversionResolver, RuntimeSourceElementFactory, singleModuleClassResolver
|
||||||
|
|||||||
Reference in New Issue
Block a user