[low level fir] use correct FirModuleData for declarations provided by FirJavaFacade
This commit is contained in:
+40
@@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.analysis.low.level.api.fir.sessions
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.analysis.utils.errors.requireIsInstance
|
||||||
|
import org.jetbrains.kotlin.fir.BuiltinTypes
|
||||||
|
import org.jetbrains.kotlin.fir.FirModuleData
|
||||||
|
import org.jetbrains.kotlin.fir.FirSession
|
||||||
|
import org.jetbrains.kotlin.fir.deserialization.ModuleDataProvider
|
||||||
|
import org.jetbrains.kotlin.fir.java.FirJavaFacade
|
||||||
|
import org.jetbrains.kotlin.load.java.JavaClassFinder
|
||||||
|
import org.jetbrains.kotlin.load.java.structure.JavaClass
|
||||||
|
import org.jetbrains.kotlin.load.java.structure.classId
|
||||||
|
import org.jetbrains.kotlin.load.java.structure.impl.VirtualFileBoundJavaClass
|
||||||
|
import java.nio.file.Path
|
||||||
|
import java.nio.file.Paths
|
||||||
|
|
||||||
|
internal class LLFirJavaFacadeForBinaries(
|
||||||
|
session: FirSession,
|
||||||
|
builtinTypes: BuiltinTypes,
|
||||||
|
classFinder: JavaClassFinder,
|
||||||
|
private val binaryDependenciesModuleDataProvider: ModuleDataProvider,
|
||||||
|
) : FirJavaFacade(session, builtinTypes, classFinder) {
|
||||||
|
override fun getModuleDataForClass(javaClass: JavaClass): FirModuleData {
|
||||||
|
requireIsInstance<VirtualFileBoundJavaClass>(javaClass)
|
||||||
|
val path = getBinaryPath(javaClass)
|
||||||
|
return binaryDependenciesModuleDataProvider.getModuleData(path)
|
||||||
|
?: error("No module data found for ${javaClass.classId} with path $path")
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getBinaryPath(javaClass: VirtualFileBoundJavaClass): Path {
|
||||||
|
val virtualFile = javaClass.virtualFile
|
||||||
|
?: error("no virtual file for ${javaClass.classId}")
|
||||||
|
val path = virtualFile.path
|
||||||
|
return Paths.get(path)
|
||||||
|
}
|
||||||
|
}
|
||||||
+17
-18
@@ -41,7 +41,7 @@ import org.jetbrains.kotlin.fir.extensions.FirPredicateBasedProvider
|
|||||||
import org.jetbrains.kotlin.fir.extensions.FirRegisteredPluginAnnotations
|
import org.jetbrains.kotlin.fir.extensions.FirRegisteredPluginAnnotations
|
||||||
import org.jetbrains.kotlin.fir.extensions.FirSwitchableExtensionDeclarationsSymbolProvider
|
import org.jetbrains.kotlin.fir.extensions.FirSwitchableExtensionDeclarationsSymbolProvider
|
||||||
import org.jetbrains.kotlin.fir.extensions.predicate.DeclarationPredicate
|
import org.jetbrains.kotlin.fir.extensions.predicate.DeclarationPredicate
|
||||||
import org.jetbrains.kotlin.fir.java.FirJavaFacade
|
import org.jetbrains.kotlin.fir.java.FirJavaFacadeForSource
|
||||||
import org.jetbrains.kotlin.fir.java.JavaSymbolProvider
|
import org.jetbrains.kotlin.fir.java.JavaSymbolProvider
|
||||||
import org.jetbrains.kotlin.fir.java.deserialization.JvmClassFileBasedSymbolProvider
|
import org.jetbrains.kotlin.fir.java.deserialization.JvmClassFileBasedSymbolProvider
|
||||||
import org.jetbrains.kotlin.fir.resolve.providers.FirDependenciesSymbolProvider
|
import org.jetbrains.kotlin.fir.resolve.providers.FirDependenciesSymbolProvider
|
||||||
@@ -188,7 +188,7 @@ internal object LLFirSessionFactory {
|
|||||||
switchableExtensionDeclarationsSymbolProvider,
|
switchableExtensionDeclarationsSymbolProvider,
|
||||||
JavaSymbolProvider(
|
JavaSymbolProvider(
|
||||||
this,
|
this,
|
||||||
FirJavaFacade(
|
FirJavaFacadeForSource(
|
||||||
this, moduleData, project.createJavaClassFinder(contentScope)
|
this, moduleData, project.createJavaClassFinder(contentScope)
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
@@ -226,8 +226,6 @@ internal object LLFirSessionFactory {
|
|||||||
val kotlinScopeProvider = FirKotlinScopeProvider(::wrapScopeWithJvmMapped)
|
val kotlinScopeProvider = FirKotlinScopeProvider(::wrapScopeWithJvmMapped)
|
||||||
register(FirKotlinScopeProvider::class, kotlinScopeProvider)
|
register(FirKotlinScopeProvider::class, kotlinScopeProvider)
|
||||||
|
|
||||||
val mainModuleData = KtModuleBasedModuleData(sourceModule).apply { bindSession(this@session) }
|
|
||||||
|
|
||||||
val moduleDataProvider = createModuleDataProviderWithLibraryDependencies(sourceModule, this)
|
val moduleDataProvider = createModuleDataProviderWithLibraryDependencies(sourceModule, this)
|
||||||
val classFileBasedSymbolProvider = JvmClassFileBasedSymbolProvider(
|
val classFileBasedSymbolProvider = JvmClassFileBasedSymbolProvider(
|
||||||
this@session,
|
this@session,
|
||||||
@@ -235,8 +233,11 @@ internal object LLFirSessionFactory {
|
|||||||
kotlinScopeProvider = kotlinScopeProvider,
|
kotlinScopeProvider = kotlinScopeProvider,
|
||||||
packagePartProvider = project.createPackagePartProviderForLibrary(searchScope),
|
packagePartProvider = project.createPackagePartProviderForLibrary(searchScope),
|
||||||
kotlinClassFinder = VirtualFileFinderFactory.getInstance(project).create(searchScope),
|
kotlinClassFinder = VirtualFileFinderFactory.getInstance(project).create(searchScope),
|
||||||
javaFacade = FirJavaFacade(
|
javaFacade = LLFirJavaFacadeForBinaries(
|
||||||
this@session, mainModuleData, project.createJavaClassFinder(searchScope)
|
this@session,
|
||||||
|
builtinTypes,
|
||||||
|
project.createJavaClassFinder(searchScope),
|
||||||
|
moduleDataProvider
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
val symbolProvider =
|
val symbolProvider =
|
||||||
@@ -281,18 +282,12 @@ internal object LLFirSessionFactory {
|
|||||||
fun createBuiltinsAndCloneableSession(
|
fun createBuiltinsAndCloneableSession(
|
||||||
project: Project,
|
project: Project,
|
||||||
builtinTypes: BuiltinTypes,
|
builtinTypes: BuiltinTypes,
|
||||||
|
stdlibModule: KtModule,
|
||||||
languageVersionSettings: LanguageVersionSettings = LanguageVersionSettingsImpl.DEFAULT,
|
languageVersionSettings: LanguageVersionSettings = LanguageVersionSettingsImpl.DEFAULT,
|
||||||
configureSession: (LLFirSession.() -> Unit)? = null,
|
configureSession: (LLFirSession.() -> Unit)? = null,
|
||||||
): LLFirBuiltinsAndCloneableSession {
|
): LLFirBuiltinsAndCloneableSession {
|
||||||
return LLFirBuiltinsAndCloneableSession(project, builtinTypes).apply session@{
|
return LLFirBuiltinsAndCloneableSession(project, builtinTypes).apply session@{
|
||||||
val moduleData = FirModuleDataImpl(
|
val moduleData = KtModuleBasedModuleData(stdlibModule).apply {
|
||||||
Name.special("<builtins module>"),
|
|
||||||
emptyList(),
|
|
||||||
emptyList(),
|
|
||||||
emptyList(),
|
|
||||||
JvmPlatforms.unspecifiedJvmPlatform,
|
|
||||||
JvmPlatformAnalyzerServices
|
|
||||||
).apply {
|
|
||||||
bindSession(this@session)
|
bindSession(this@session)
|
||||||
}
|
}
|
||||||
registerIdeComponents(project)
|
registerIdeComponents(project)
|
||||||
@@ -376,15 +371,19 @@ internal object LLFirSessionFactory {
|
|||||||
val librariesSearchScope = ProjectScope.getLibrariesScope(project)
|
val librariesSearchScope = ProjectScope.getLibrariesScope(project)
|
||||||
.intersectWith(GlobalSearchScope.notScope(libraryModule.contentScope)) // <all libraries scope> - <current library scope>
|
.intersectWith(GlobalSearchScope.notScope(libraryModule.contentScope)) // <all libraries scope> - <current library scope>
|
||||||
add(builtinsAndCloneableSession.symbolProvider)
|
add(builtinsAndCloneableSession.symbolProvider)
|
||||||
|
val libraryDependenciesModuleDataProvider = createModuleDataProviderWithLibraryDependencies(module, this@session)
|
||||||
add(
|
add(
|
||||||
JvmClassFileBasedSymbolProvider(
|
JvmClassFileBasedSymbolProvider(
|
||||||
this@session,
|
this@session,
|
||||||
moduleDataProvider = createModuleDataProviderWithLibraryDependencies(module, this@session),
|
moduleDataProvider = libraryDependenciesModuleDataProvider,
|
||||||
kotlinScopeProvider = scopeProvider,
|
kotlinScopeProvider = scopeProvider,
|
||||||
packagePartProvider = project.createPackagePartProviderForLibrary(librariesSearchScope),
|
packagePartProvider = project.createPackagePartProviderForLibrary(librariesSearchScope),
|
||||||
kotlinClassFinder = VirtualFileFinderFactory.getInstance(project).create(librariesSearchScope),
|
kotlinClassFinder = VirtualFileFinderFactory.getInstance(project).create(librariesSearchScope),
|
||||||
javaFacade = FirJavaFacade(
|
javaFacade = LLFirJavaFacadeForBinaries(
|
||||||
this@session, moduleData, project.createJavaClassFinder(librariesSearchScope)
|
this@session,
|
||||||
|
builtinTypes,
|
||||||
|
project.createJavaClassFinder(librariesSearchScope),
|
||||||
|
libraryDependenciesModuleDataProvider
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -422,7 +421,7 @@ internal object LLFirSessionFactory {
|
|||||||
provider.symbolProvider,
|
provider.symbolProvider,
|
||||||
JavaSymbolProvider(
|
JavaSymbolProvider(
|
||||||
this,
|
this,
|
||||||
FirJavaFacade(
|
FirJavaFacadeForSource(
|
||||||
this, moduleData, project.createJavaClassFinder(contentScope)
|
this, moduleData, project.createJavaClassFinder(contentScope)
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
|
|||||||
+2
-2
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.asJava.finder.JavaElementFinder
|
|||||||
import org.jetbrains.kotlin.fir.FirModuleData
|
import org.jetbrains.kotlin.fir.FirModuleData
|
||||||
import org.jetbrains.kotlin.fir.FirSession
|
import org.jetbrains.kotlin.fir.FirSession
|
||||||
import org.jetbrains.kotlin.fir.java.FirJavaElementFinder
|
import org.jetbrains.kotlin.fir.java.FirJavaElementFinder
|
||||||
import org.jetbrains.kotlin.fir.java.FirJavaFacade
|
import org.jetbrains.kotlin.fir.java.FirJavaFacadeForSource
|
||||||
import org.jetbrains.kotlin.fir.session.environment.AbstractProjectEnvironment
|
import org.jetbrains.kotlin.fir.session.environment.AbstractProjectEnvironment
|
||||||
import org.jetbrains.kotlin.fir.session.environment.AbstractProjectFileSearchScope
|
import org.jetbrains.kotlin.fir.session.environment.AbstractProjectFileSearchScope
|
||||||
import org.jetbrains.kotlin.load.java.createJavaClassFinder
|
import org.jetbrains.kotlin.load.java.createJavaClassFinder
|
||||||
@@ -128,7 +128,7 @@ open class VfsBasedProjectEnvironment(
|
|||||||
firSession: FirSession,
|
firSession: FirSession,
|
||||||
baseModuleData: FirModuleData,
|
baseModuleData: FirModuleData,
|
||||||
fileSearchScope: AbstractProjectFileSearchScope
|
fileSearchScope: AbstractProjectFileSearchScope
|
||||||
) = FirJavaFacade(firSession, baseModuleData, project.createJavaClassFinder(fileSearchScope.asPsiSearchScope()))
|
) = FirJavaFacadeForSource(firSession, baseModuleData, project.createJavaClassFinder(fileSearchScope.asPsiSearchScope()))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.fir.declarations.builder.buildTypeParameter
|
|||||||
import org.jetbrains.kotlin.fir.declarations.impl.FirResolvedDeclarationStatusImpl
|
import org.jetbrains.kotlin.fir.declarations.impl.FirResolvedDeclarationStatusImpl
|
||||||
import org.jetbrains.kotlin.fir.declarations.utils.effectiveVisibility
|
import org.jetbrains.kotlin.fir.declarations.utils.effectiveVisibility
|
||||||
import org.jetbrains.kotlin.fir.declarations.utils.modality
|
import org.jetbrains.kotlin.fir.declarations.utils.modality
|
||||||
|
import org.jetbrains.kotlin.fir.deserialization.ModuleDataProvider
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirConstExpression
|
import org.jetbrains.kotlin.fir.expressions.FirConstExpression
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||||
import org.jetbrains.kotlin.fir.expressions.classId
|
import org.jetbrains.kotlin.fir.expressions.classId
|
||||||
@@ -46,15 +47,26 @@ import org.jetbrains.kotlin.load.java.JavaClassFinder
|
|||||||
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
|
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
|
||||||
import org.jetbrains.kotlin.load.java.structure.*
|
import org.jetbrains.kotlin.load.java.structure.*
|
||||||
import org.jetbrains.kotlin.load.java.structure.impl.JavaElementImpl
|
import org.jetbrains.kotlin.load.java.structure.impl.JavaElementImpl
|
||||||
|
import org.jetbrains.kotlin.load.java.structure.impl.classFiles.BinaryJavaClass
|
||||||
import org.jetbrains.kotlin.name.*
|
import org.jetbrains.kotlin.name.*
|
||||||
import org.jetbrains.kotlin.toKtPsiSourceElement
|
import org.jetbrains.kotlin.toKtPsiSourceElement
|
||||||
import org.jetbrains.kotlin.types.Variance.INVARIANT
|
import org.jetbrains.kotlin.types.Variance.INVARIANT
|
||||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||||
|
|
||||||
|
class FirJavaFacadeForSource(
|
||||||
|
session: FirSession,
|
||||||
|
private val sourceModuleData: FirModuleData,
|
||||||
|
classFinder: JavaClassFinder
|
||||||
|
) : FirJavaFacade(session, sourceModuleData.session.builtinTypes, classFinder) {
|
||||||
|
override fun getModuleDataForClass(javaClass: JavaClass): FirModuleData {
|
||||||
|
return sourceModuleData
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@ThreadSafeMutableState
|
@ThreadSafeMutableState
|
||||||
class FirJavaFacade(
|
abstract class FirJavaFacade(
|
||||||
private val session: FirSession,
|
private val session: FirSession,
|
||||||
private val baseModuleData: FirModuleData,
|
private val builtinTypes: BuiltinTypes,
|
||||||
private val classFinder: JavaClassFinder
|
private val classFinder: JavaClassFinder
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
@@ -90,12 +102,15 @@ class FirJavaFacade(
|
|||||||
return classId.relativeClassName.topLevelName() in knownNames
|
return classId.relativeClassName.topLevelName() in knownNames
|
||||||
}
|
}
|
||||||
|
|
||||||
|
abstract fun getModuleDataForClass(javaClass: JavaClass): FirModuleData
|
||||||
|
|
||||||
private fun JavaTypeParameter.toFirTypeParameter(
|
private fun JavaTypeParameter.toFirTypeParameter(
|
||||||
javaTypeParameterStack: JavaTypeParameterStack,
|
javaTypeParameterStack: JavaTypeParameterStack,
|
||||||
containingDeclarationSymbol: FirBasedSymbol<*>
|
containingDeclarationSymbol: FirBasedSymbol<*>,
|
||||||
|
moduleData: FirModuleData,
|
||||||
): FirTypeParameter {
|
): FirTypeParameter {
|
||||||
return buildTypeParameter {
|
return buildTypeParameter {
|
||||||
moduleData = baseModuleData
|
this.moduleData = moduleData
|
||||||
origin = FirDeclarationOrigin.Java
|
origin = FirDeclarationOrigin.Java
|
||||||
resolvePhase = FirResolvePhase.ANALYZED_DEPENDENCIES
|
resolvePhase = FirResolvePhase.ANALYZED_DEPENDENCIES
|
||||||
name = this@toFirTypeParameter.name
|
name = this@toFirTypeParameter.name
|
||||||
@@ -110,7 +125,6 @@ class FirJavaFacade(
|
|||||||
bounds += upperBound.toFirJavaTypeRef(session, javaTypeParameterStack)
|
bounds += upperBound.toFirJavaTypeRef(session, javaTypeParameterStack)
|
||||||
}
|
}
|
||||||
if (bounds.isEmpty()) {
|
if (bounds.isEmpty()) {
|
||||||
val builtinTypes = baseModuleData.session.builtinTypes
|
|
||||||
bounds += buildResolvedTypeRef {
|
bounds += buildResolvedTypeRef {
|
||||||
type = ConeFlexibleType(builtinTypes.anyType.type, builtinTypes.nullableAnyType.type)
|
type = ConeFlexibleType(builtinTypes.anyType.type, builtinTypes.nullableAnyType.type)
|
||||||
}
|
}
|
||||||
@@ -120,9 +134,10 @@ class FirJavaFacade(
|
|||||||
|
|
||||||
private fun List<JavaTypeParameter>.convertTypeParameters(
|
private fun List<JavaTypeParameter>.convertTypeParameters(
|
||||||
stack: JavaTypeParameterStack,
|
stack: JavaTypeParameterStack,
|
||||||
containingDeclarationSymbol: FirBasedSymbol<*>
|
containingDeclarationSymbol: FirBasedSymbol<*>,
|
||||||
|
moduleData: FirModuleData,
|
||||||
): List<FirTypeParameter> {
|
): List<FirTypeParameter> {
|
||||||
return map { it.toFirTypeParameter(stack, containingDeclarationSymbol) }
|
return map { it.toFirTypeParameter(stack, containingDeclarationSymbol, moduleData) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun JavaClass.hasMetadataAnnotation(): Boolean =
|
private fun JavaClass.hasMetadataAnnotation(): Boolean =
|
||||||
@@ -221,9 +236,10 @@ class FirJavaFacade(
|
|||||||
): FirJavaClass {
|
): FirJavaClass {
|
||||||
val valueParametersForAnnotationConstructor = ValueParametersForAnnotationConstructor()
|
val valueParametersForAnnotationConstructor = ValueParametersForAnnotationConstructor()
|
||||||
val classIsAnnotation = javaClass.classKind == ClassKind.ANNOTATION_CLASS
|
val classIsAnnotation = javaClass.classKind == ClassKind.ANNOTATION_CLASS
|
||||||
|
val moduleData = getModuleDataForClass(javaClass)
|
||||||
return buildJavaClass {
|
return buildJavaClass {
|
||||||
source = (javaClass as? JavaElementImpl<*>)?.psi?.toKtPsiSourceElement()
|
source = (javaClass as? JavaElementImpl<*>)?.psi?.toKtPsiSourceElement()
|
||||||
moduleData = baseModuleData
|
this.moduleData = moduleData
|
||||||
symbol = classSymbol
|
symbol = classSymbol
|
||||||
name = javaClass.name
|
name = javaClass.name
|
||||||
val visibility = javaClass.visibility
|
val visibility = javaClass.visibility
|
||||||
@@ -244,7 +260,7 @@ class FirJavaFacade(
|
|||||||
val effectiveVisibility = parentEffectiveVisibility.lowerBound(selfEffectiveVisibility, session.typeContext)
|
val effectiveVisibility = parentEffectiveVisibility.lowerBound(selfEffectiveVisibility, session.typeContext)
|
||||||
parentClassEffectiveVisibilityCache[classSymbol] = effectiveVisibility
|
parentClassEffectiveVisibilityCache[classSymbol] = effectiveVisibility
|
||||||
|
|
||||||
val classTypeParameters = javaClass.typeParameters.convertTypeParameters(javaTypeParameterStack, classSymbol)
|
val classTypeParameters = javaClass.typeParameters.convertTypeParameters(javaTypeParameterStack, classSymbol, moduleData)
|
||||||
typeParameters += classTypeParameters
|
typeParameters += classTypeParameters
|
||||||
if (!isStatic && parentClassSymbol != null) {
|
if (!isStatic && parentClassSymbol != null) {
|
||||||
typeParameters += parentClassSymbol.fir.typeParameters.map {
|
typeParameters += parentClassSymbol.fir.typeParameters.map {
|
||||||
@@ -276,7 +292,7 @@ class FirJavaFacade(
|
|||||||
// TODO: may be we can process fields & methods later.
|
// TODO: may be we can process fields & methods later.
|
||||||
// However, they should be built up to override resolve stage
|
// However, they should be built up to override resolve stage
|
||||||
for (javaField in javaClass.fields) {
|
for (javaField in javaClass.fields) {
|
||||||
declarations += convertJavaFieldToFir(javaField, classId, javaTypeParameterStack, dispatchReceiver)
|
declarations += convertJavaFieldToFir(javaField, classId, javaTypeParameterStack, dispatchReceiver, moduleData)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (javaMethod in javaClass.methods) {
|
for (javaMethod in javaClass.methods) {
|
||||||
@@ -285,12 +301,14 @@ class FirJavaFacade(
|
|||||||
javaMethod,
|
javaMethod,
|
||||||
classId,
|
classId,
|
||||||
javaTypeParameterStack,
|
javaTypeParameterStack,
|
||||||
dispatchReceiver
|
dispatchReceiver,
|
||||||
|
moduleData,
|
||||||
)
|
)
|
||||||
declarations += firJavaMethod
|
declarations += firJavaMethod
|
||||||
|
|
||||||
if (classIsAnnotation) {
|
if (classIsAnnotation) {
|
||||||
val parameterForAnnotationConstructor = convertJavaAnnotationMethodToValueParameter(javaMethod, firJavaMethod)
|
val parameterForAnnotationConstructor =
|
||||||
|
convertJavaAnnotationMethodToValueParameter(javaMethod, firJavaMethod, moduleData)
|
||||||
if (javaMethod.name == VALUE_METHOD_NAME) {
|
if (javaMethod.name == VALUE_METHOD_NAME) {
|
||||||
valueParametersForAnnotationConstructor.valueParameterForValue = javaMethod to parameterForAnnotationConstructor
|
valueParametersForAnnotationConstructor.valueParameterForValue = javaMethod to parameterForAnnotationConstructor
|
||||||
} else {
|
} else {
|
||||||
@@ -313,6 +331,7 @@ class FirJavaFacade(
|
|||||||
classTypeParameters,
|
classTypeParameters,
|
||||||
javaTypeParameterStack,
|
javaTypeParameterStack,
|
||||||
parentClassSymbol,
|
parentClassSymbol,
|
||||||
|
moduleData,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
for (javaConstructor in javaClassDeclaredConstructors) {
|
for (javaConstructor in javaClassDeclaredConstructors) {
|
||||||
@@ -324,16 +343,17 @@ class FirJavaFacade(
|
|||||||
classTypeParameters,
|
classTypeParameters,
|
||||||
javaTypeParameterStack,
|
javaTypeParameterStack,
|
||||||
parentClassSymbol,
|
parentClassSymbol,
|
||||||
|
moduleData,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (classKind == ClassKind.ENUM_CLASS) {
|
if (classKind == ClassKind.ENUM_CLASS) {
|
||||||
generateValuesFunction(
|
generateValuesFunction(
|
||||||
baseModuleData,
|
moduleData,
|
||||||
classId.packageFqName,
|
classId.packageFqName,
|
||||||
classId.relativeClassName
|
classId.relativeClassName
|
||||||
)
|
)
|
||||||
generateValueOfFunction(baseModuleData, classId.packageFqName, classId.relativeClassName)
|
generateValueOfFunction(moduleData, classId.packageFqName, classId.relativeClassName)
|
||||||
}
|
}
|
||||||
if (classIsAnnotation) {
|
if (classIsAnnotation) {
|
||||||
declarations +=
|
declarations +=
|
||||||
@@ -341,7 +361,8 @@ class FirJavaFacade(
|
|||||||
classSource = (javaClass as? JavaElementImpl<*>)?.psi?.toKtPsiSourceElement(KtFakeSourceElementKind.ImplicitConstructor) as? KtFakeSourceElement,
|
classSource = (javaClass as? JavaElementImpl<*>)?.psi?.toKtPsiSourceElement(KtFakeSourceElementKind.ImplicitConstructor) as? KtFakeSourceElement,
|
||||||
constructorId = constructorId,
|
constructorId = constructorId,
|
||||||
ownerClassBuilder = this,
|
ownerClassBuilder = this,
|
||||||
valueParametersForAnnotationConstructor = valueParametersForAnnotationConstructor
|
valueParametersForAnnotationConstructor = valueParametersForAnnotationConstructor,
|
||||||
|
moduleData = moduleData,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}.apply {
|
}.apply {
|
||||||
@@ -369,7 +390,8 @@ class FirJavaFacade(
|
|||||||
javaField: JavaField,
|
javaField: JavaField,
|
||||||
classId: ClassId,
|
classId: ClassId,
|
||||||
javaTypeParameterStack: JavaTypeParameterStack,
|
javaTypeParameterStack: JavaTypeParameterStack,
|
||||||
dispatchReceiver: ConeClassLikeType
|
dispatchReceiver: ConeClassLikeType,
|
||||||
|
moduleData: FirModuleData,
|
||||||
): FirDeclaration {
|
): FirDeclaration {
|
||||||
val fieldName = javaField.name
|
val fieldName = javaField.name
|
||||||
val fieldId = CallableId(classId.packageFqName, classId.relativeClassName, fieldName)
|
val fieldId = CallableId(classId.packageFqName, classId.relativeClassName, fieldName)
|
||||||
@@ -377,7 +399,7 @@ class FirJavaFacade(
|
|||||||
return when {
|
return when {
|
||||||
javaField.isEnumEntry -> buildEnumEntry {
|
javaField.isEnumEntry -> buildEnumEntry {
|
||||||
source = (javaField as? JavaElementImpl<*>)?.psi?.toKtPsiSourceElement()
|
source = (javaField as? JavaElementImpl<*>)?.psi?.toKtPsiSourceElement()
|
||||||
moduleData = baseModuleData
|
this.moduleData = moduleData
|
||||||
symbol = FirEnumEntrySymbol(fieldId)
|
symbol = FirEnumEntrySymbol(fieldId)
|
||||||
name = fieldName
|
name = fieldName
|
||||||
status = FirResolvedDeclarationStatusImpl(
|
status = FirResolvedDeclarationStatusImpl(
|
||||||
@@ -400,7 +422,7 @@ class FirJavaFacade(
|
|||||||
}
|
}
|
||||||
else -> buildJavaField {
|
else -> buildJavaField {
|
||||||
source = (javaField as? JavaElementImpl<*>)?.psi?.toKtPsiSourceElement()
|
source = (javaField as? JavaElementImpl<*>)?.psi?.toKtPsiSourceElement()
|
||||||
moduleData = baseModuleData
|
this.moduleData = moduleData
|
||||||
symbol = FirFieldSymbol(fieldId)
|
symbol = FirFieldSymbol(fieldId)
|
||||||
name = fieldName
|
name = fieldName
|
||||||
status = FirResolvedDeclarationStatusImpl(
|
status = FirResolvedDeclarationStatusImpl(
|
||||||
@@ -441,20 +463,21 @@ class FirJavaFacade(
|
|||||||
javaMethod: JavaMethod,
|
javaMethod: JavaMethod,
|
||||||
classId: ClassId,
|
classId: ClassId,
|
||||||
javaTypeParameterStack: JavaTypeParameterStack,
|
javaTypeParameterStack: JavaTypeParameterStack,
|
||||||
dispatchReceiver: ConeClassLikeType
|
dispatchReceiver: ConeClassLikeType,
|
||||||
|
moduleData: FirModuleData,
|
||||||
): FirJavaMethod {
|
): FirJavaMethod {
|
||||||
val methodName = javaMethod.name
|
val methodName = javaMethod.name
|
||||||
val methodId = CallableId(classId.packageFqName, classId.relativeClassName, methodName)
|
val methodId = CallableId(classId.packageFqName, classId.relativeClassName, methodName)
|
||||||
val methodSymbol = FirNamedFunctionSymbol(methodId)
|
val methodSymbol = FirNamedFunctionSymbol(methodId)
|
||||||
val returnType = javaMethod.returnType
|
val returnType = javaMethod.returnType
|
||||||
return buildJavaMethod {
|
return buildJavaMethod {
|
||||||
moduleData = baseModuleData
|
this.moduleData = moduleData
|
||||||
source = (javaMethod as? JavaElementImpl<*>)?.psi?.toKtPsiSourceElement()
|
source = (javaMethod as? JavaElementImpl<*>)?.psi?.toKtPsiSourceElement()
|
||||||
symbol = methodSymbol
|
symbol = methodSymbol
|
||||||
name = methodName
|
name = methodName
|
||||||
returnTypeRef = returnType.toFirJavaTypeRef(session, javaTypeParameterStack)
|
returnTypeRef = returnType.toFirJavaTypeRef(session, javaTypeParameterStack)
|
||||||
isStatic = javaMethod.isStatic
|
isStatic = javaMethod.isStatic
|
||||||
typeParameters += javaMethod.typeParameters.convertTypeParameters(javaTypeParameterStack, methodSymbol)
|
typeParameters += javaMethod.typeParameters.convertTypeParameters(javaTypeParameterStack, methodSymbol, moduleData)
|
||||||
for ((index, valueParameter) in javaMethod.valueParameters.withIndex()) {
|
for ((index, valueParameter) in javaMethod.valueParameters.withIndex()) {
|
||||||
valueParameters += valueParameter.toFirValueParameter(session, moduleData, index, javaTypeParameterStack)
|
valueParameters += valueParameter.toFirValueParameter(session, moduleData, index, javaTypeParameterStack)
|
||||||
}
|
}
|
||||||
@@ -488,11 +511,15 @@ class FirJavaFacade(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun convertJavaAnnotationMethodToValueParameter(javaMethod: JavaMethod, firJavaMethod: FirJavaMethod): FirJavaValueParameter =
|
private fun convertJavaAnnotationMethodToValueParameter(
|
||||||
|
javaMethod: JavaMethod,
|
||||||
|
firJavaMethod: FirJavaMethod,
|
||||||
|
moduleData: FirModuleData,
|
||||||
|
): FirJavaValueParameter =
|
||||||
buildJavaValueParameter {
|
buildJavaValueParameter {
|
||||||
source = (javaMethod as? JavaElementImpl<*>)?.psi
|
source = (javaMethod as? JavaElementImpl<*>)?.psi
|
||||||
?.toKtPsiSourceElement(KtFakeSourceElementKind.ImplicitJavaAnnotationConstructor)
|
?.toKtPsiSourceElement(KtFakeSourceElementKind.ImplicitJavaAnnotationConstructor)
|
||||||
moduleData = baseModuleData
|
this.moduleData = moduleData
|
||||||
returnTypeRef = firJavaMethod.returnTypeRef
|
returnTypeRef = firJavaMethod.returnTypeRef
|
||||||
name = javaMethod.name
|
name = javaMethod.name
|
||||||
isVararg = javaMethod.returnType is JavaArrayType && javaMethod.name == VALUE_METHOD_NAME
|
isVararg = javaMethod.returnType is JavaArrayType && javaMethod.name == VALUE_METHOD_NAME
|
||||||
@@ -507,11 +534,12 @@ class FirJavaFacade(
|
|||||||
classTypeParameters: List<FirTypeParameter>,
|
classTypeParameters: List<FirTypeParameter>,
|
||||||
javaTypeParameterStack: JavaTypeParameterStack,
|
javaTypeParameterStack: JavaTypeParameterStack,
|
||||||
outerClassSymbol: FirRegularClassSymbol?,
|
outerClassSymbol: FirRegularClassSymbol?,
|
||||||
|
moduleData: FirModuleData,
|
||||||
): FirJavaConstructor {
|
): FirJavaConstructor {
|
||||||
val constructorSymbol = FirConstructorSymbol(constructorId)
|
val constructorSymbol = FirConstructorSymbol(constructorId)
|
||||||
return buildJavaConstructor {
|
return buildJavaConstructor {
|
||||||
source = (javaConstructor as? JavaElementImpl<*>)?.psi?.toKtPsiSourceElement()
|
source = (javaConstructor as? JavaElementImpl<*>)?.psi?.toKtPsiSourceElement()
|
||||||
moduleData = baseModuleData
|
this.moduleData = moduleData
|
||||||
symbol = constructorSymbol
|
symbol = constructorSymbol
|
||||||
isInner = javaClass.outerClass != null && !javaClass.isStatic
|
isInner = javaClass.outerClass != null && !javaClass.isStatic
|
||||||
val isThisInner = this.isInner
|
val isThisInner = this.isInner
|
||||||
@@ -535,7 +563,7 @@ class FirJavaFacade(
|
|||||||
typeParameters += classTypeParameters.map { buildConstructedClassTypeParameterRef { symbol = it.symbol } }
|
typeParameters += classTypeParameters.map { buildConstructedClassTypeParameterRef { symbol = it.symbol } }
|
||||||
|
|
||||||
if (javaConstructor != null) {
|
if (javaConstructor != null) {
|
||||||
this.typeParameters += javaConstructor.typeParameters.convertTypeParameters(javaTypeParameterStack, constructorSymbol)
|
this.typeParameters += javaConstructor.typeParameters.convertTypeParameters(javaTypeParameterStack, constructorSymbol, moduleData)
|
||||||
annotationBuilder = { javaConstructor.convertAnnotationsToFir(session, javaTypeParameterStack) }
|
annotationBuilder = { javaConstructor.convertAnnotationsToFir(session, javaTypeParameterStack) }
|
||||||
for ((index, valueParameter) in javaConstructor.valueParameters.withIndex()) {
|
for ((index, valueParameter) in javaConstructor.valueParameters.withIndex()) {
|
||||||
valueParameters += valueParameter.toFirValueParameter(session, moduleData, index, javaTypeParameterStack)
|
valueParameters += valueParameter.toFirValueParameter(session, moduleData, index, javaTypeParameterStack)
|
||||||
@@ -552,11 +580,12 @@ class FirJavaFacade(
|
|||||||
classSource: KtFakeSourceElement?,
|
classSource: KtFakeSourceElement?,
|
||||||
constructorId: CallableId,
|
constructorId: CallableId,
|
||||||
ownerClassBuilder: FirJavaClassBuilder,
|
ownerClassBuilder: FirJavaClassBuilder,
|
||||||
valueParametersForAnnotationConstructor: ValueParametersForAnnotationConstructor
|
valueParametersForAnnotationConstructor: ValueParametersForAnnotationConstructor,
|
||||||
|
moduleData: FirModuleData,
|
||||||
): FirJavaConstructor {
|
): FirJavaConstructor {
|
||||||
return buildJavaConstructor {
|
return buildJavaConstructor {
|
||||||
source = classSource
|
source = classSource
|
||||||
moduleData = baseModuleData
|
this.moduleData = moduleData
|
||||||
symbol = FirConstructorSymbol(constructorId)
|
symbol = FirConstructorSymbol(constructorId)
|
||||||
status = FirResolvedDeclarationStatusImpl(Visibilities.Public, Modality.FINAL, EffectiveVisibility.Public)
|
status = FirResolvedDeclarationStatusImpl(Visibilities.Public, Modality.FINAL, EffectiveVisibility.Public)
|
||||||
returnTypeRef = buildResolvedTypeRef {
|
returnTypeRef = buildResolvedTypeRef {
|
||||||
|
|||||||
Reference in New Issue
Block a user