diff --git a/compiler/fir/cones/src/org/jetbrains/kotlin/fir/symbols/Callables.kt b/compiler/fir/cones/src/org/jetbrains/kotlin/fir/symbols/Callables.kt new file mode 100644 index 00000000000..b0a21a87256 --- /dev/null +++ b/compiler/fir/cones/src/org/jetbrains/kotlin/fir/symbols/Callables.kt @@ -0,0 +1,37 @@ +/* + * Copyright 2010-2019 JetBrains s.r.o. 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.fir.symbols + +import org.jetbrains.kotlin.fir.types.ConeKotlinType +import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.name.Name + +// NB: with className == null we are at top level +data class CallableId(val packageName: FqName, val className: FqName?, val callableName: Name) { + constructor(packageName: FqName, callableName: Name): this(packageName, null, callableName) + + override fun toString(): String { + return buildString { + append(packageName.asString().replace('.', '/')) + append("/") + if (className != null) { + append(className) + append(".") + } + append(callableName) + } + } +} + +interface ConeCallableSymbol : ConeSymbol { + val callableId: CallableId +} + +interface ConePropertySymbol : ConeCallableSymbol + +interface ConeFunctionSymbol : ConeCallableSymbol { + val parameters: List +} \ No newline at end of file diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/JavaSymbolProvider.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/JavaSymbolProvider.kt index 2bff2916893..f21cb7157ac 100644 --- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/JavaSymbolProvider.kt +++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/JavaSymbolProvider.kt @@ -9,6 +9,7 @@ import com.intellij.openapi.project.Project import com.intellij.psi.search.GlobalSearchScope import org.jetbrains.kotlin.fir.java.symbols.JavaClassSymbol import org.jetbrains.kotlin.fir.resolve.AbstractFirSymbolProvider +import org.jetbrains.kotlin.fir.symbols.CallableId import org.jetbrains.kotlin.fir.symbols.ConeSymbol import org.jetbrains.kotlin.load.java.JavaClassFinder import org.jetbrains.kotlin.name.ClassId @@ -19,6 +20,10 @@ class JavaSymbolProvider( val project: Project, private val searchScope: GlobalSearchScope ) : AbstractFirSymbolProvider() { + override fun getCallableSymbols(callableId: CallableId): List { + // TODO + return emptyList() + } override fun getSymbolByFqName(classId: ClassId): ConeSymbol? { return classCache.lookupCacheOrCalculate(classId) { diff --git a/compiler/fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt b/compiler/fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt index fd145080f27..2d30cdad8dd 100644 --- a/compiler/fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt +++ b/compiler/fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt @@ -20,9 +20,8 @@ import org.jetbrains.kotlin.fir.references.FirErrorNamedReference import org.jetbrains.kotlin.fir.references.FirExplicitSuperReference import org.jetbrains.kotlin.fir.references.FirSimpleNamedReference import org.jetbrains.kotlin.fir.references.FirExplicitThisReference -import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol -import org.jetbrains.kotlin.fir.symbols.impl.FirTypeAliasSymbol -import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol +import org.jetbrains.kotlin.fir.symbols.CallableId +import org.jetbrains.kotlin.fir.symbols.impl.* import org.jetbrains.kotlin.fir.types.FirType import org.jetbrains.kotlin.fir.types.FirTypeProjection import org.jetbrains.kotlin.fir.types.impl.* @@ -250,6 +249,7 @@ class RawFirBuilder(val session: FirSession, val stubMode: Boolean) { val firProperty = FirMemberPropertyImpl( session, this, + FirPropertySymbol(callableIdForName(nameAsSafeName)), nameAsSafeName, visibility, modality, @@ -359,6 +359,7 @@ class RawFirBuilder(val session: FirSession, val stubMode: Boolean) { val firConstructor = FirPrimaryConstructorImpl( session, this ?: owner, + FirFunctionSymbol(callableIdForClassConstructor()), this?.visibility ?: Visibilities.UNKNOWN, this?.hasExpectModifier() ?: false, this?.hasActualModifier() ?: false, @@ -432,6 +433,14 @@ class RawFirBuilder(val session: FirSession, val stubMode: Boolean) { val currentClassId get() = ClassId(packageFqName, className, false) + fun callableIdForName(name: Name) = + if (className == FqName.ROOT) CallableId(packageFqName, name) + else CallableId(packageFqName, className, name) + + fun callableIdForClassConstructor() = + if (className == FqName.ROOT) CallableId(packageFqName, Name.special("")) + else CallableId(packageFqName, className, className.shortName()) + var className: FqName = FqName.ROOT override fun visitClassOrObject(classOrObject: KtClassOrObject, data: Unit): FirElement { @@ -546,6 +555,7 @@ class RawFirBuilder(val session: FirSession, val stubMode: Boolean) { FirMemberFunctionImpl( session, function, + FirFunctionSymbol(callableIdForName(function.nameAsSafeName)), function.nameAsSafeName, function.visibility, function.modality, @@ -621,6 +631,7 @@ class RawFirBuilder(val session: FirSession, val stubMode: Boolean) { val firConstructor = FirConstructorImpl( session, this, + FirFunctionSymbol(callableIdForClassConstructor()), visibility, hasExpectModifier(), hasActualModifier(), @@ -686,6 +697,7 @@ class RawFirBuilder(val session: FirSession, val stubMode: Boolean) { FirMemberPropertyImpl( session, property, + FirPropertySymbol(callableIdForName(name)), name, property.visibility, property.modality, diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/FirSymbolProvider.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/FirSymbolProvider.kt index 7c3984d06f4..d583c913ee6 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/FirSymbolProvider.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/FirSymbolProvider.kt @@ -7,6 +7,7 @@ package org.jetbrains.kotlin.fir.resolve import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.service +import org.jetbrains.kotlin.fir.symbols.CallableId import org.jetbrains.kotlin.fir.symbols.ConeSymbol import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.FqName @@ -15,6 +16,8 @@ interface FirSymbolProvider { fun getSymbolByFqName(classId: ClassId): ConeSymbol? + fun getCallableSymbols(callableId: CallableId): List + fun getPackage(fqName: FqName): FqName? // TODO: Replace to symbol sometime companion object { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/impl/FirCompositeSymbolProvider.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/impl/FirCompositeSymbolProvider.kt index c1e12fe95fc..a5144f1bf03 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/impl/FirCompositeSymbolProvider.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/impl/FirCompositeSymbolProvider.kt @@ -6,12 +6,20 @@ package org.jetbrains.kotlin.fir.resolve.impl import org.jetbrains.kotlin.fir.resolve.FirSymbolProvider +import org.jetbrains.kotlin.fir.symbols.CallableId import org.jetbrains.kotlin.fir.symbols.ConeSymbol import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult class FirCompositeSymbolProvider(val providers: List) : FirSymbolProvider { + override fun getCallableSymbols(callableId: CallableId): List { + for (provider in providers) { + val symbols = provider.getCallableSymbols(callableId) + if (symbols.isNotEmpty()) return symbols + } + return emptyList() + } override fun getPackage(fqName: FqName): FqName? { return providers.firstNotNullResult { it.getPackage(fqName) } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/impl/FirDependenciesSymbolProviderImpl.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/impl/FirDependenciesSymbolProviderImpl.kt index 15520d236dd..ca484fabf9e 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/impl/FirDependenciesSymbolProviderImpl.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/impl/FirDependenciesSymbolProviderImpl.kt @@ -10,11 +10,16 @@ import org.jetbrains.kotlin.fir.dependenciesWithoutSelf import org.jetbrains.kotlin.fir.resolve.AbstractFirSymbolProvider import org.jetbrains.kotlin.fir.resolve.FirSymbolProvider import org.jetbrains.kotlin.fir.service +import org.jetbrains.kotlin.fir.symbols.CallableId import org.jetbrains.kotlin.fir.symbols.ConeSymbol import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.FqName class FirDependenciesSymbolProviderImpl(val session: FirSession) : AbstractFirSymbolProvider() { + override fun getCallableSymbols(callableId: CallableId): List { + // TODO + return emptyList() + } private val dependencyProviders by lazy { val moduleInfo = session.moduleInfo ?: return@lazy emptyList() diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/impl/FirLibrarySymbolProviderImpl.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/impl/FirLibrarySymbolProviderImpl.kt index 26255a2be23..9a4efdb2821 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/impl/FirLibrarySymbolProviderImpl.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/impl/FirLibrarySymbolProviderImpl.kt @@ -11,10 +11,10 @@ import org.jetbrains.kotlin.descriptors.SourceElement import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.deserialization.FirTypeDeserializer import org.jetbrains.kotlin.fir.resolve.FirSymbolProvider +import org.jetbrains.kotlin.fir.symbols.CallableId import org.jetbrains.kotlin.fir.symbols.ConeSymbol import org.jetbrains.kotlin.fir.symbols.LibraryClassSymbol import org.jetbrains.kotlin.fir.symbols.impl.FictitiousFunctionSymbol -import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol import org.jetbrains.kotlin.metadata.ProtoBuf import org.jetbrains.kotlin.metadata.builtins.BuiltInsBinaryVersion import org.jetbrains.kotlin.metadata.deserialization.NameResolverImpl @@ -27,6 +27,10 @@ import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult import java.io.InputStream class FirLibrarySymbolProviderImpl(val session: FirSession) : FirSymbolProvider { + override fun getCallableSymbols(callableId: CallableId): List { + // TODO + return emptyList() + } private class BuiltInsPackageFragment(stream: InputStream, val fqName: FqName) { lateinit var version: BuiltInsBinaryVersion diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/impl/FirProviderImpl.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/impl/FirProviderImpl.kt index b2d643b4249..874d4dbb1ce 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/impl/FirProviderImpl.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/impl/FirProviderImpl.kt @@ -9,10 +9,7 @@ import org.jetbrains.kotlin.fir.FirElement import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.resolve.FirProvider -import org.jetbrains.kotlin.fir.symbols.ConeClassLikeSymbol -import org.jetbrains.kotlin.fir.symbols.ConeSymbol -import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol -import org.jetbrains.kotlin.fir.symbols.FirSymbolOwner +import org.jetbrains.kotlin.fir.symbols.* import org.jetbrains.kotlin.fir.visitors.FirVisitorVoid import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.FqName @@ -31,6 +28,10 @@ class FirProviderImpl(val session: FirSession) : FirProvider { return (getFirClassifierByFqName(classId) as? FirSymbolOwner<*>)?.symbol } + override fun getCallableSymbols(callableId: CallableId): List { + return (callableMap[callableId] ?: emptyList()).filterIsInstance>().map { it.symbol } + } + override fun getFirClassifierContainerFile(fqName: ClassId): FirFile { return classifierContainerFileMap[fqName] ?: error("Couldn't find container for $fqName") } @@ -61,12 +62,29 @@ class FirProviderImpl(val session: FirSession) : FirProvider { classifierMap[classId] = typeAlias classifierContainerFileMap[classId] = file } + + override fun visitCallableMember(callableMember: FirCallableMember) { + val callableId = when (containerFqName) { + FqName.ROOT -> CallableId(packageName, callableMember.name) + else -> CallableId(packageName, containerFqName, callableMember.name) + } + callableMap.merge(callableId, listOf(callableMember)) { a, b -> a + b } + } + + override fun visitNamedFunction(namedFunction: FirNamedFunction) { + visitCallableMember(namedFunction) + } + + override fun visitProperty(property: FirProperty) { + visitCallableMember(property) + } }) } private val fileMap = mutableMapOf>() private val classifierMap = mutableMapOf() private val classifierContainerFileMap = mutableMapOf() + private val callableMap = mutableMapOf>() override fun getFirFilesByPackage(fqName: FqName): List { return fileMap[fqName].orEmpty() diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirAbstractTreeTransformerWithSuperTypes.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirAbstractTreeTransformerWithSuperTypes.kt index 184f74443c5..55502099de7 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirAbstractTreeTransformerWithSuperTypes.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirAbstractTreeTransformerWithSuperTypes.kt @@ -16,16 +16,16 @@ import org.jetbrains.kotlin.fir.types.ConeClassErrorType import org.jetbrains.kotlin.fir.types.ConeClassLikeType abstract class FirAbstractTreeTransformerWithSuperTypes(reversedScopePriority: Boolean) : FirAbstractTreeTransformer() { - protected var towerScope = FirCompositeScope(mutableListOf(), reversedPriority = reversedScopePriority) + protected val towerScope = FirCompositeScope(mutableListOf(), reversedPriority = reversedScopePriority) protected inline fun withScopeCleanup(crossinline l: () -> T): T { - val scopeBefore = towerScope - val scopes = towerScope.scopes - val sizeBefore = scopes.size + val sizeBefore = towerScope.scopes.size val result = l() - towerScope = scopeBefore - assert(scopes.size >= sizeBefore) - scopes.subList(sizeBefore + 1, scopes.size).clear() + val size = towerScope.scopes.size + assert(size >= sizeBefore) + repeat(size - sizeBefore) { + towerScope.scopes.let { it.removeAt(it.size - 1) } + } return result } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirAccessResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirAccessResolveTransformer.kt new file mode 100644 index 00000000000..67c3fc60610 --- /dev/null +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirAccessResolveTransformer.kt @@ -0,0 +1,64 @@ +/* + * Copyright 2010-2019 JetBrains s.r.o. 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.fir.resolve.transformers + +import org.jetbrains.kotlin.fir.FirNamedReference +import org.jetbrains.kotlin.fir.FirResolvedCallableReference +import org.jetbrains.kotlin.fir.declarations.FirDeclaration +import org.jetbrains.kotlin.fir.declarations.FirFile +import org.jetbrains.kotlin.fir.declarations.FirRegularClass +import org.jetbrains.kotlin.fir.references.FirErrorNamedReference +import org.jetbrains.kotlin.fir.references.FirResolvedCallableReferenceImpl +import org.jetbrains.kotlin.fir.scopes.FirPosition +import org.jetbrains.kotlin.fir.scopes.impl.FirClassDeclaredMemberScope +import org.jetbrains.kotlin.fir.scopes.impl.FirTopLevelDeclaredMemberScope +import org.jetbrains.kotlin.fir.symbols.ConeCallableSymbol +import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol +import org.jetbrains.kotlin.fir.visitors.CompositeTransformResult +import org.jetbrains.kotlin.fir.visitors.compose + +class FirAccessResolveTransformer : FirAbstractTreeTransformerWithSuperTypes(reversedScopePriority = true) { + + override fun transformFile(file: FirFile, data: Nothing?): CompositeTransformResult { + return withScopeCleanup { + towerScope.scopes += FirTopLevelDeclaredMemberScope(file, file.session) + super.transformFile(file, data) + } + } + + override fun transformRegularClass(regularClass: FirRegularClass, data: Nothing?): CompositeTransformResult { + return withScopeCleanup { + lookupSuperTypes(regularClass).asReversed().mapNotNullTo(towerScope.scopes) { + val symbol = it.symbol + if (symbol is FirClassSymbol) { + FirClassDeclaredMemberScope(symbol.fir, symbol.fir.session) + } else { + null + } + } + towerScope.scopes += FirClassDeclaredMemberScope(regularClass, regularClass.session) + super.transformRegularClass(regularClass, data) + } + } + + override fun transformNamedReference(namedReference: FirNamedReference, data: Nothing?): CompositeTransformResult { + if (namedReference is FirResolvedCallableReference) return namedReference.compose() + val name = namedReference.name + var symbol: ConeCallableSymbol? = null + towerScope.processClassifiersByName(name, FirPosition.OTHER) { + symbol = it as? ConeCallableSymbol + // I'm lucky today!!! (the first symbol we have found is the one we need) + it is ConeCallableSymbol + } + val callableSymbol = symbol ?: return FirErrorNamedReference( + namedReference.session, namedReference.psi, "Unresolved name: $name" + ).compose() + return FirResolvedCallableReferenceImpl( + namedReference.session, namedReference.psi, + name, callableSymbol + ).compose() + } +} \ No newline at end of file diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirTotalResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirTotalResolveTransformer.kt index 619a9c2c05b..134335b5b4f 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirTotalResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirTotalResolveTransformer.kt @@ -13,7 +13,8 @@ class FirTotalResolveTransformer { val transformers: List> = listOf( FirImportResolveTransformer(), FirTypeResolveTransformer(), - FirStatusResolveTransformer() + FirStatusResolveTransformer(), + FirAccessResolveTransformer() ) fun processFile(firFile: FirFile) { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassDeclaredMemberScope.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassDeclaredMemberScope.kt new file mode 100644 index 00000000000..081dbbf6713 --- /dev/null +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassDeclaredMemberScope.kt @@ -0,0 +1,35 @@ +/* + * Copyright 2010-2019 JetBrains s.r.o. 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.fir.scopes.impl + +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.declarations.FirRegularClass +import org.jetbrains.kotlin.fir.scopes.FirPosition +import org.jetbrains.kotlin.fir.symbols.CallableId +import org.jetbrains.kotlin.fir.symbols.ConeSymbol +import org.jetbrains.kotlin.name.Name + +class FirClassDeclaredMemberScope( + klass: FirRegularClass, + session: FirSession, + lookupInFir: Boolean = true +) : FirAbstractProviderBasedScope(session, lookupInFir) { + private val classId = klass.symbol.classId + + override fun processClassifiersByName( + name: Name, + position: FirPosition, + processor: (ConeSymbol) -> Boolean + ): Boolean { + val symbols = provider.getCallableSymbols(CallableId(classId.packageFqName, classId.relativeClassName, name)) + for (symbol in symbols) { + if (!processor(symbol)) { + return false + } + } + return true + } +} \ No newline at end of file diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirTopLevelDeclaredMemberScope.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirTopLevelDeclaredMemberScope.kt new file mode 100644 index 00000000000..e959bedc47d --- /dev/null +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirTopLevelDeclaredMemberScope.kt @@ -0,0 +1,35 @@ +/* + * Copyright 2010-2019 JetBrains s.r.o. 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.fir.scopes.impl + +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.declarations.FirFile +import org.jetbrains.kotlin.fir.scopes.FirPosition +import org.jetbrains.kotlin.fir.symbols.CallableId +import org.jetbrains.kotlin.fir.symbols.ConeSymbol +import org.jetbrains.kotlin.name.Name + +class FirTopLevelDeclaredMemberScope( + file: FirFile, + session: FirSession, + lookupInFir: Boolean = true +) : FirAbstractProviderBasedScope(session, lookupInFir) { + private val packageFqName = file.packageFqName + + override fun processClassifiersByName( + name: Name, + position: FirPosition, + processor: (ConeSymbol) -> Boolean + ): Boolean { + val symbols = provider.getCallableSymbols(CallableId(packageFqName, name)) + for (symbol in symbols) { + if (!processor(symbol)) { + return false + } + } + return true + } +} \ No newline at end of file diff --git a/compiler/fir/resolve/testData/resolve/builtins/lists.txt b/compiler/fir/resolve/testData/resolve/builtins/lists.txt index e55468d26ab..18a4ad595d2 100644 --- a/compiler/fir/resolve/testData/resolve/builtins/lists.txt +++ b/compiler/fir/resolve/testData/resolve/builtins/lists.txt @@ -8,8 +8,8 @@ FILE: lists.kt } public final function convert R|kotlin/collections/List|.(): R|MyStringList| { - return@@@convert STUB + return@@@convert as/R|MyStringList|(this#) } public final function ret(l: R|kotlin/collections/MutableList|): R|MyMutableStringList| { - return@@@ret STUB + return@@@ret as/R|MyMutableStringList|(this#) } diff --git a/compiler/fir/resolve/testData/resolve/derivedClass.txt b/compiler/fir/resolve/testData/resolve/derivedClass.txt index 2a55b76ffaf..76e3fb7d65b 100644 --- a/compiler/fir/resolve/testData/resolve/derivedClass.txt +++ b/compiler/fir/resolve/testData/resolve/derivedClass.txt @@ -7,9 +7,9 @@ FILE: derivedClass.kt } public final class Derived : R|Base| { - public constructor(x: R|T|): super|>() + public constructor(x: R|T|): super|>(R|/Base.x|) } public final function create(x: R|T|): R|Derived| { - return@@@create STUB + return@@@create #(#) } diff --git a/compiler/fir/resolve/testData/resolve/enum.txt b/compiler/fir/resolve/testData/resolve/enum.txt index 093f91e2a82..0e150188b50 100644 --- a/compiler/fir/resolve/testData/resolve/enum.txt +++ b/compiler/fir/resolve/testData/resolve/enum.txt @@ -16,19 +16,19 @@ FILE: enum.kt public get(): R|Some| public final enum entry FIRST : R|SomeEnum| { - public constructor(): super() + public constructor(): super(#) public final override function check(y: R|Some|): R|kotlin/Boolean| { - return@@@check STUB + return@@@check Boolean(true) } } public final enum entry SECOND : R|SomeEnum| { - public constructor(): super() + public constructor(): super(#) public final override function check(y: R|Some|): R|kotlin/Boolean| { - return@@@check STUB + return@@@check ==(#, #) } } diff --git a/compiler/fir/resolve/testData/resolve/fromBuilder/enums.txt b/compiler/fir/resolve/testData/resolve/fromBuilder/enums.txt index cf47b36e80c..94c2000a002 100644 --- a/compiler/fir/resolve/testData/resolve/fromBuilder/enums.txt +++ b/compiler/fir/resolve/testData/resolve/fromBuilder/enums.txt @@ -28,33 +28,33 @@ FILE: enums.kt internal get(): R|kotlin/Double| public final enum entry MERCURY : R|Planet| { - public constructor(): super() + public constructor(): super(Double(1.0), Double(2.0)) public final override function sayHello(): R|kotlin/Unit| { - return@@@sayHello STUB + #(String(Hello!!!)) } } public final enum entry VENERA : R|Planet| { - public constructor(): super() + public constructor(): super(Double(3.0), Double(4.0)) public final override function sayHello(): R|kotlin/Unit| { - return@@@sayHello STUB + #(String(Ola!!!)) } } public final enum entry EARTH : R|Planet| { - public constructor(): super() + public constructor(): super(Double(5.0), Double(6.0)) public final override function sayHello(): R|kotlin/Unit| { - return@@@sayHello STUB + #(String(Privet!!!)) } } - public final property g(val): R|kotlin/Double| = STUB + public final property g(val): R|kotlin/Double| = #(#(#, R|/Planet.m|), #(R|/Planet.r|, R|/Planet.r|)) public get(): R|kotlin/Double| public abstract function sayHello(): R|kotlin/Unit| @@ -62,7 +62,7 @@ FILE: enums.kt public final companion object Companion { public constructor(): super() - public final const property G(val): R|error: Not supported: FirImplicitTypeImpl| = STUB + public final const property G(val): R|error: Not supported: FirImplicitTypeImpl| = Double(6.67E-11) public get(): R|error: Not supported: FirImplicitTypeImpl| } diff --git a/compiler/fir/resolve/testData/resolve/fromBuilder/noPrimaryConstructor.txt b/compiler/fir/resolve/testData/resolve/fromBuilder/noPrimaryConstructor.txt index 566222a51c2..16983f05075 100644 --- a/compiler/fir/resolve/testData/resolve/fromBuilder/noPrimaryConstructor.txt +++ b/compiler/fir/resolve/testData/resolve/fromBuilder/noPrimaryConstructor.txt @@ -4,9 +4,9 @@ FILE: noPrimaryConstructor.kt public get(): R|kotlin/String| public constructor(x: R|kotlin/String|): super() { - return STUB + this#.R|/NoPrimary.x| = R|/NoPrimary.x| } - public constructor(): this() + public constructor(): this(String()) } diff --git a/compiler/fir/resolve/testData/resolve/fromBuilder/simpleClass.txt b/compiler/fir/resolve/testData/resolve/fromBuilder/simpleClass.txt index fc6be87ea0b..e4794b5a6ef 100644 --- a/compiler/fir/resolve/testData/resolve/fromBuilder/simpleClass.txt +++ b/compiler/fir/resolve/testData/resolve/fromBuilder/simpleClass.txt @@ -9,19 +9,18 @@ FILE: simpleClass.kt public final class SomeClass : R|SomeInterface| { public constructor(): super() - private final property baz(val): R|error: Not supported: FirImplicitTypeImpl| = STUB + private final property baz(val): R|error: Not supported: FirImplicitTypeImpl| = Int(42) private get(): R|error: Not supported: FirImplicitTypeImpl| public final override function foo(x: R|kotlin/Int|, y: R|kotlin/String|): R|kotlin/String| { - return@@@foo STUB + return@@@foo #(#(#, #), R|/SomeClass.baz|) } public final override property bar(var): R|kotlin/Boolean| public get(): R|kotlin/Boolean| { - return STUB + return Boolean(true) } public set(value: R|kotlin/Boolean|): R|kotlin/Unit| { - return STUB } public final lateinit property fau(var): R|kotlin/Double| diff --git a/compiler/fir/resolve/testData/resolve/fromBuilder/typeParameters.txt b/compiler/fir/resolve/testData/resolve/fromBuilder/typeParameters.txt index 0ddf2b1259d..02e32ec85a1 100644 --- a/compiler/fir/resolve/testData/resolve/fromBuilder/typeParameters.txt +++ b/compiler/fir/resolve/testData/resolve/fromBuilder/typeParameters.txt @@ -15,11 +15,11 @@ FILE: typeParameters.kt public constructor(): super|>() public final override function get(index: R|kotlin/Int|): R|kotlin/Int| { - return@@@get STUB + return@@@get Int(42) } public final override function concat(other: R|List|): R|List| { - return@@@concat STUB + return@@@concat this# } } diff --git a/compiler/fir/resolve/testData/resolve/functionTypes.txt b/compiler/fir/resolve/testData/resolve/functionTypes.txt index 5603052cfac..c8c343f5f68 100644 --- a/compiler/fir/resolve/testData/resolve/functionTypes.txt +++ b/compiler/fir/resolve/testData/resolve/functionTypes.txt @@ -1,12 +1,11 @@ FILE: functionTypes.kt public final function simpleRun(f: R|(T) -> kotlin/Unit|): R|kotlin/Unit| { - return@@@simpleRun STUB + return@@@simpleRun #() } public final function simpleMap R|kotlin/collections/List|.(f: R|(T) -> R|): R|R| { - return@@@simpleMap STUB } public final function simpleWith(t: R|T|, f: R|T.() -> kotlin/Unit|): R|kotlin/Unit| { - return@@@simpleWith STUB + return@@@simpleWith #.#() } public abstract interface KMutableProperty1 : R|KProperty1|, R|KMutableProperty| { } diff --git a/compiler/fir/resolve/testData/resolve/genericFunctions.txt b/compiler/fir/resolve/testData/resolve/genericFunctions.txt index 9e25f2c20b0..c368ac9197a 100644 --- a/compiler/fir/resolve/testData/resolve/genericFunctions.txt +++ b/compiler/fir/resolve/testData/resolve/genericFunctions.txt @@ -2,7 +2,7 @@ FILE: genericFunctions.kt public abstract interface Any { } public final inline function safeAs R|Any|.(): R|T| { - return@@@safeAs STUB + return@@@safeAs as?/R|T|(this#) } public abstract class Summator { public constructor(): super() diff --git a/compiler/fir/resolve/testData/resolve/multifile/Annotations.txt b/compiler/fir/resolve/testData/resolve/multifile/Annotations.txt index 540cca203bf..5bc4b29f4a4 100644 --- a/compiler/fir/resolve/testData/resolve/multifile/Annotations.txt +++ b/compiler/fir/resolve/testData/resolve/multifile/Annotations.txt @@ -5,7 +5,7 @@ FILE: Annotations.kt @R|annotations/Simple|() public abstract function foo(@R|annotations/WithString|(String(abc)) arg: @R|annotations/Simple|() R|kotlin/Double|): R|kotlin/Unit| - @R|annotations/Complex|(STUB, STUB) public abstract property v(val): R|kotlin/String| + @R|annotations/Complex|(#(Int(7)), #(String())) public abstract property v(val): R|kotlin/String| public get(): R|kotlin/String| } @@ -16,15 +16,15 @@ FILE: Annotations.kt public get(): R|kotlin/Char| public final override function foo(arg: R|kotlin/Double|): R|kotlin/Unit| { - return@@@foo STUB } public final override property v(val): R|kotlin/String| @R|annotations/Simple|() public get(): R|kotlin/String| { - return STUB + return String() } - @R|annotations/WithString|(String(constructor)) public constructor(): this() + @R|annotations/WithString|(String(constructor)) public constructor(): this(Char( +)) } @R|annotations/WithInt|(Int(24)) @R|annotations/VeryComplex|(Float(3.14), Double(6.67E-11), Boolean(false), Long(123456789012345), Null(null)) @R|annotations/WithInt|(Int(24)) @R|annotations/VeryComplex|(Float(3.14), Double(6.67E-11), Boolean(false), Long(123456789012345), Null(null)) public final typealias Third = @R|annotations/Simple|() R|test/Second| diff --git a/compiler/fir/resolve/testData/resolve/nestedClass.txt b/compiler/fir/resolve/testData/resolve/nestedClass.txt index e20c9e39631..ee67b413957 100644 --- a/compiler/fir/resolve/testData/resolve/nestedClass.txt +++ b/compiler/fir/resolve/testData/resolve/nestedClass.txt @@ -10,12 +10,12 @@ FILE: nestedClass.kt public constructor(): super() public final class Derived : R|Base| { - public constructor(s: R|kotlin/String|): super() + public constructor(s: R|kotlin/String|): super(R|/Base.s|) } public final object Obj : R|Base| { - public constructor(): super() + public constructor(): super(String()) } diff --git a/compiler/fir/resolve/testData/resolve/references/simple.kt b/compiler/fir/resolve/testData/resolve/references/simple.kt new file mode 100644 index 00000000000..01c56edc69c --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/references/simple.kt @@ -0,0 +1,3 @@ +fun foo() = 1 + +fun bar() = foo() \ No newline at end of file diff --git a/compiler/fir/resolve/testData/resolve/references/simple.txt b/compiler/fir/resolve/testData/resolve/references/simple.txt new file mode 100644 index 00000000000..37a32bc1631 --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/references/simple.txt @@ -0,0 +1,7 @@ +FILE: simple.kt + public final function foo(): R|error: Not supported: FirImplicitTypeImpl| { + return@@@foo Int(1) + } + public final function bar(): R|error: Not supported: FirImplicitTypeImpl| { + return@@@bar R|/foo|() + } diff --git a/compiler/fir/resolve/testData/resolve/references/superMember.kt b/compiler/fir/resolve/testData/resolve/references/superMember.kt new file mode 100644 index 00000000000..1dfabd7727c --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/references/superMember.kt @@ -0,0 +1,9 @@ +open class A { + open fun foo() {} +} + +class B : A() { + fun bar() { + foo() + } +} \ No newline at end of file diff --git a/compiler/fir/resolve/testData/resolve/references/superMember.txt b/compiler/fir/resolve/testData/resolve/references/superMember.txt new file mode 100644 index 00000000000..adc8ff99fba --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/references/superMember.txt @@ -0,0 +1,16 @@ +FILE: superMember.kt + public open class A { + public constructor(): super() + + public open function foo(): R|kotlin/Unit| { + } + + } + public final class B : R|A| { + public constructor(): super() + + public final function bar(): R|kotlin/Unit| { + R|/A.foo|() + } + + } diff --git a/compiler/fir/resolve/testData/resolve/simpleClass.txt b/compiler/fir/resolve/testData/resolve/simpleClass.txt index 84a13e7e64d..7a526e6c949 100644 --- a/compiler/fir/resolve/testData/resolve/simpleClass.txt +++ b/compiler/fir/resolve/testData/resolve/simpleClass.txt @@ -9,19 +9,18 @@ FILE: simpleClass.kt public final class SomeClass : R|SomeInterface| { public constructor(): super() - private final property baz(val): R|error: Not supported: FirImplicitTypeImpl| = STUB + private final property baz(val): R|error: Not supported: FirImplicitTypeImpl| = Int(42) private get(): R|error: Not supported: FirImplicitTypeImpl| public final override function foo(x: R|kotlin/Int|, y: R|kotlin/String|): R|kotlin/String| { - return@@@foo STUB + return@@@foo #(#(#, #), R|/SomeClass.baz|) } public final override property bar(var): R|kotlin/Boolean| public get(): R|kotlin/Boolean| { - return STUB + return Boolean(true) } public set(value: R|kotlin/Boolean|): R|kotlin/Unit| { - return STUB } public final property fau(var): R|kotlin/Double| diff --git a/compiler/fir/resolve/testData/resolve/stdlib/concurrent.txt b/compiler/fir/resolve/testData/resolve/stdlib/concurrent.txt index 5f121b779a2..b4060c0773c 100644 --- a/compiler/fir/resolve/testData/resolve/stdlib/concurrent.txt +++ b/compiler/fir/resolve/testData/resolve/stdlib/concurrent.txt @@ -1,7 +1,6 @@ FILE: concurrent.kt - @R|kotlin/jvm/Volatile|() public final property xx(var): R|kotlin/Int| = STUB + @R|kotlin/jvm/Volatile|() public final property xx(var): R|kotlin/Int| = Int(2) public get(): R|kotlin/Int| public set(value: R|kotlin/Int|): R|kotlin/Unit| @R|kotlin/jvm/Synchronized|() public final function foo(): R|kotlin/Unit| { - return@@@foo STUB } diff --git a/compiler/fir/resolve/testData/resolve/stdlib/functionX.txt b/compiler/fir/resolve/testData/resolve/stdlib/functionX.txt index baea075697b..03c64d7249a 100644 --- a/compiler/fir/resolve/testData/resolve/stdlib/functionX.txt +++ b/compiler/fir/resolve/testData/resolve/stdlib/functionX.txt @@ -1,13 +1,24 @@ FILE: functionX.kt - public final property x(val): R|kotlin/jvm/functions/Function0| = STUB + public final property x(val): R|kotlin/jvm/functions/Function0| = function R|error: Not supported: FirImplicitTypeImpl|.(): R|error: Not supported: FirImplicitTypeImpl| { + return { + Int(42) + } + + } + public get(): R|kotlin/jvm/functions/Function0| - public final property y(val): R|kotlin/Function1| = STUB + public final property y(val): R|kotlin/Function1| = function R|error: Not supported: FirImplicitTypeImpl|.(): R|error: Not supported: FirImplicitTypeImpl| { + return { + # + } + + } + public get(): R|kotlin/Function1| public final class MyFunction : R|kotlin/Function2| { public constructor(): super() public final override function invoke(p1: R|kotlin/Int|, p2: R|kotlin/String|): R|kotlin/Unit| { - return@@@invoke STUB } } diff --git a/compiler/fir/resolve/testData/resolve/stdlib/reflectionClass.txt b/compiler/fir/resolve/testData/resolve/stdlib/reflectionClass.txt index 52ad077ab80..2fe60cc7758 100644 --- a/compiler/fir/resolve/testData/resolve/stdlib/reflectionClass.txt +++ b/compiler/fir/resolve/testData/resolve/stdlib/reflectionClass.txt @@ -1,5 +1,5 @@ FILE: reflectionClass.kt - public final property javaClass(val): R|java/lang/Class| = STUB + public final property javaClass(val): R|java/lang/Class| = (#).# public get(): R|java/lang/Class| - public final property kotlinClass(val): R|kotlin/reflect/KClass| = STUB + public final property kotlinClass(val): R|kotlin/reflect/KClass| = (#) public get(): R|kotlin/reflect/KClass| diff --git a/compiler/fir/resolve/testData/resolve/treeSet.txt b/compiler/fir/resolve/testData/resolve/treeSet.txt index b65d64c07ed..eaf495832a7 100644 --- a/compiler/fir/resolve/testData/resolve/treeSet.txt +++ b/compiler/fir/resolve/testData/resolve/treeSet.txt @@ -1,3 +1,3 @@ FILE: treeSet.kt - public final property x(val): R|java/util/SortedSet| = STUB + public final property x(val): R|java/util/SortedSet| = #() public get(): R|java/util/SortedSet| diff --git a/compiler/fir/resolve/testData/resolve/typeParameterInPropertyReceiver.txt b/compiler/fir/resolve/testData/resolve/typeParameterInPropertyReceiver.txt index 520fefa426d..894f1b524a4 100644 --- a/compiler/fir/resolve/testData/resolve/typeParameterInPropertyReceiver.txt +++ b/compiler/fir/resolve/testData/resolve/typeParameterInPropertyReceiver.txt @@ -1,5 +1,5 @@ FILE: typeParameterInPropertyReceiver.kt public final property self R|T|.(val): R|T| public get(): R|T| { - return STUB + return this# } diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/AbstractFirResolveTestCase.kt b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/AbstractFirResolveTestCase.kt index 47b1d26e188..7cc528b9a9b 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/AbstractFirResolveTestCase.kt +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/AbstractFirResolveTestCase.kt @@ -29,7 +29,7 @@ abstract class AbstractFirResolveTestCase : AbstractFirResolveWithSessionTestCas .uniteWith(TopDownAnalyzerFacadeForJVM.AllJavaSourcesInProjectScope(project)) val session = createSession(scope) - val builder = RawFirBuilder(session, stubMode = true) + val builder = RawFirBuilder(session, stubMode = false) val transformer = FirTotalResolveTransformer() return ktFiles.map { diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirResolveTestCaseGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirResolveTestCaseGenerated.java index 5570a3be3df..c6ffd8aa4fa 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirResolveTestCaseGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirResolveTestCaseGenerated.java @@ -242,4 +242,27 @@ public class FirResolveTestCaseGenerated extends AbstractFirResolveTestCase { runTest("compiler/fir/resolve/testData/resolve/multifile/TypeAliasExpansion.kt"); } } + + @TestMetadata("compiler/fir/resolve/testData/resolve/references") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class References extends AbstractFirResolveTestCase { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInReferences() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/fir/resolve/testData/resolve/references"), Pattern.compile("^([^.]+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + runTest("compiler/fir/resolve/testData/resolve/references/simple.kt"); + } + + @TestMetadata("superMember.kt") + public void testSuperMember() throws Exception { + runTest("compiler/fir/resolve/testData/resolve/references/superMember.kt"); + } + } } diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirNamedReference.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirNamedReference.kt index 1a29ef7e308..7e18b202328 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirNamedReference.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirNamedReference.kt @@ -8,6 +8,7 @@ package org.jetbrains.kotlin.fir import org.jetbrains.kotlin.fir.visitors.FirVisitor import org.jetbrains.kotlin.name.Name +@BaseTransformedType interface FirNamedReference : FirReference { val name: Name diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirRenderer.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirRenderer.kt index 30eeb1487e9..768c6f34aab 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirRenderer.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirRenderer.kt @@ -695,6 +695,12 @@ class FirRenderer(builder: StringBuilder) : FirVisitorVoid() { print("${namedReference.name}#") } + override fun visitResolvedCallableReference(resolvedCallableReference: FirResolvedCallableReference) { + print("R|") + print(resolvedCallableReference.callableSymbol.callableId) + print("|") + } + override fun visitThisReference(thisReference: FirThisReference) { print("this") val labelName = thisReference.labelName diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirResolvedCallableReference.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirResolvedCallableReference.kt new file mode 100644 index 00000000000..784f1227200 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirResolvedCallableReference.kt @@ -0,0 +1,16 @@ +/* + * Copyright 2010-2019 JetBrains s.r.o. 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.fir + +import org.jetbrains.kotlin.fir.symbols.ConeCallableSymbol +import org.jetbrains.kotlin.fir.visitors.FirVisitor + +interface FirResolvedCallableReference : FirNamedReference { + val callableSymbol: ConeCallableSymbol + + override fun accept(visitor: FirVisitor, data: D): R = + visitor.visitResolvedCallableReference(this, data) +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/FirCallableMember.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/FirCallableMember.kt index 5d7da496eeb..82fa0e29a1b 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/FirCallableMember.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/FirCallableMember.kt @@ -6,11 +6,14 @@ package org.jetbrains.kotlin.fir.declarations import org.jetbrains.kotlin.fir.VisitedSupertype +import org.jetbrains.kotlin.fir.symbols.FirSymbolOwner import org.jetbrains.kotlin.fir.types.FirType import org.jetbrains.kotlin.fir.visitors.FirVisitor // Good name needed (something with receiver, type parameters, return type, and name) -interface FirCallableMember : @VisitedSupertype FirDeclaration, FirMemberDeclaration, FirTypedDeclaration { +interface FirCallableMember : + @VisitedSupertype FirDeclaration, FirMemberDeclaration, + FirTypedDeclaration, FirSymbolOwner { val isOverride: Boolean get() = status.isOverride val receiverType: FirType? diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirAbstractCallableMember.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirAbstractCallableMember.kt index 6025bd03ea0..6b246643f07 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirAbstractCallableMember.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirAbstractCallableMember.kt @@ -11,6 +11,7 @@ import org.jetbrains.kotlin.descriptors.Visibility import org.jetbrains.kotlin.fir.FirElement import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.declarations.FirCallableMember +import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol import org.jetbrains.kotlin.fir.transformSingle import org.jetbrains.kotlin.fir.types.FirType import org.jetbrains.kotlin.fir.visitors.FirTransformer @@ -19,6 +20,7 @@ import org.jetbrains.kotlin.name.Name abstract class FirAbstractCallableMember( session: FirSession, psi: PsiElement?, + final override val symbol: FirBasedSymbol, name: Name, visibility: Visibility, modality: Modality?, @@ -30,6 +32,7 @@ abstract class FirAbstractCallableMember( ) : FirAbstractMemberDeclaration(session, psi, name, visibility, modality, isExpect, isActual), FirCallableMember { init { + symbol.bind(this) status.isOverride = isOverride } diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirConstructorImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirConstructorImpl.kt index 77a390b717a..d1cb807762f 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirConstructorImpl.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirConstructorImpl.kt @@ -14,6 +14,7 @@ import org.jetbrains.kotlin.fir.declarations.FirConstructor import org.jetbrains.kotlin.fir.declarations.FirValueParameter import org.jetbrains.kotlin.fir.expressions.FirBlock import org.jetbrains.kotlin.fir.expressions.FirDelegatedConstructorCall +import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol import org.jetbrains.kotlin.fir.transformInplace import org.jetbrains.kotlin.fir.transformSingle import org.jetbrains.kotlin.fir.types.FirType @@ -23,13 +24,14 @@ import org.jetbrains.kotlin.name.Name open class FirConstructorImpl( session: FirSession, psi: PsiElement?, + symbol: FirFunctionSymbol, visibility: Visibility, isExpect: Boolean, isActual: Boolean, delegatedSelfType: FirType, final override var delegatedConstructor: FirDelegatedConstructorCall? ) : FirAbstractCallableMember( - session, psi, NAME, visibility, Modality.FINAL, + session, psi, symbol, NAME, visibility, Modality.FINAL, isExpect, isActual, isOverride = false, receiverType = null, returnType = delegatedSelfType ), FirConstructor { override val valueParameters = mutableListOf() diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirMemberFunctionImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirMemberFunctionImpl.kt index 7364178e680..912123e83fd 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirMemberFunctionImpl.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirMemberFunctionImpl.kt @@ -13,6 +13,7 @@ import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.declarations.FirNamedFunction import org.jetbrains.kotlin.fir.declarations.FirValueParameter import org.jetbrains.kotlin.fir.expressions.FirBlock +import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol import org.jetbrains.kotlin.fir.transformInplace import org.jetbrains.kotlin.fir.transformSingle import org.jetbrains.kotlin.fir.types.FirType @@ -22,6 +23,7 @@ import org.jetbrains.kotlin.name.Name class FirMemberFunctionImpl( session: FirSession, psi: PsiElement?, + symbol: FirFunctionSymbol, name: Name, visibility: Visibility, modality: Modality?, @@ -37,7 +39,7 @@ class FirMemberFunctionImpl( receiverType: FirType?, returnType: FirType ) : FirAbstractCallableMember( - session, psi, name, visibility, modality, + session, psi, symbol, name, visibility, modality, isExpect, isActual, isOverride, receiverType, returnType ), FirNamedFunction, FirModifiableFunction { init { diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirMemberPropertyImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirMemberPropertyImpl.kt index 8c66709fdb2..1e47e87acac 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirMemberPropertyImpl.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirMemberPropertyImpl.kt @@ -13,6 +13,7 @@ import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.declarations.FirProperty import org.jetbrains.kotlin.fir.declarations.FirPropertyAccessor import org.jetbrains.kotlin.fir.expressions.FirExpression +import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol import org.jetbrains.kotlin.fir.transformSingle import org.jetbrains.kotlin.fir.types.FirType import org.jetbrains.kotlin.fir.visitors.FirTransformer @@ -21,6 +22,7 @@ import org.jetbrains.kotlin.name.Name class FirMemberPropertyImpl( session: FirSession, psi: PsiElement?, + symbol: FirPropertySymbol, name: Name, visibility: Visibility, modality: Modality?, @@ -37,7 +39,7 @@ class FirMemberPropertyImpl( override var setter: FirPropertyAccessor, override var delegate: FirExpression? ) : FirAbstractCallableMember( - session, psi, name, visibility, modality, isExpect, isActual, isOverride, receiverType, returnType + session, psi, symbol, name, visibility, modality, isExpect, isActual, isOverride, receiverType, returnType ), FirProperty { init { status.isConst = isConst diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirPrimaryConstructorImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirPrimaryConstructorImpl.kt index 892d95c4909..1da290364b8 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirPrimaryConstructorImpl.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirPrimaryConstructorImpl.kt @@ -9,14 +9,16 @@ import com.intellij.psi.PsiElement import org.jetbrains.kotlin.descriptors.Visibility import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.expressions.FirDelegatedConstructorCall +import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol import org.jetbrains.kotlin.fir.types.FirType class FirPrimaryConstructorImpl( session: FirSession, psi: PsiElement?, + symbol: FirFunctionSymbol, visibility: Visibility, isExpect: Boolean, isActual: Boolean, delegatedSelfType: FirType, delegatedConstructor: FirDelegatedConstructorCall? -) : FirConstructorImpl(session, psi, visibility, isExpect, isActual, delegatedSelfType, delegatedConstructor) \ No newline at end of file +) : FirConstructorImpl(session, psi, symbol, visibility, isExpect, isActual, delegatedSelfType, delegatedConstructor) \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/references/FirResolvedCallableReferenceImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/references/FirResolvedCallableReferenceImpl.kt new file mode 100644 index 00000000000..54962b5f027 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/references/FirResolvedCallableReferenceImpl.kt @@ -0,0 +1,20 @@ +/* + * Copyright 2010-2019 JetBrains s.r.o. 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.fir.references + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.fir.FirAbstractElement +import org.jetbrains.kotlin.fir.FirResolvedCallableReference +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.symbols.ConeCallableSymbol +import org.jetbrains.kotlin.name.Name + +class FirResolvedCallableReferenceImpl( + session: FirSession, + psi: PsiElement?, + override val name: Name, + override val callableSymbol: ConeCallableSymbol +) : FirAbstractElement(session, psi), FirResolvedCallableReference \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirFunctionSymbol.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirFunctionSymbol.kt new file mode 100644 index 00000000000..abc65997b6a --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirFunctionSymbol.kt @@ -0,0 +1,17 @@ +/* + * Copyright 2010-2019 JetBrains s.r.o. 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.fir.symbols.impl + +import org.jetbrains.kotlin.fir.declarations.FirCallableMember +import org.jetbrains.kotlin.fir.symbols.AbstractFirBasedSymbol +import org.jetbrains.kotlin.fir.symbols.CallableId +import org.jetbrains.kotlin.fir.symbols.ConeFunctionSymbol +import org.jetbrains.kotlin.fir.types.ConeKotlinType + +class FirFunctionSymbol(override val callableId: CallableId) : ConeFunctionSymbol, AbstractFirBasedSymbol() { + override val parameters: List + get() = emptyList() +} \ No newline at end of file diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirPropertySymbol.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirPropertySymbol.kt new file mode 100644 index 00000000000..419caf9fbbf --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirPropertySymbol.kt @@ -0,0 +1,13 @@ +/* + * Copyright 2010-2019 JetBrains s.r.o. 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.fir.symbols.impl + +import org.jetbrains.kotlin.fir.declarations.FirCallableMember +import org.jetbrains.kotlin.fir.symbols.AbstractFirBasedSymbol +import org.jetbrains.kotlin.fir.symbols.CallableId +import org.jetbrains.kotlin.fir.symbols.ConePropertySymbol + +class FirPropertySymbol(override val callableId: CallableId) : ConePropertySymbol, AbstractFirBasedSymbol() \ No newline at end of file diff --git a/compiler/fir/tree/visitors/org/jetbrains/kotlin/fir/visitors/FirTransformerGenerated.kt b/compiler/fir/tree/visitors/org/jetbrains/kotlin/fir/visitors/FirTransformerGenerated.kt index 04c33404035..2cf382f6f3e 100644 --- a/compiler/fir/tree/visitors/org/jetbrains/kotlin/fir/visitors/FirTransformerGenerated.kt +++ b/compiler/fir/tree/visitors/org/jetbrains/kotlin/fir/visitors/FirTransformerGenerated.kt @@ -136,10 +136,14 @@ abstract class FirTransformer : FirVisitor transformNamedReference(namedReference: E, data: D): CompositeTransformResult { + open fun transformNamedReference(namedReference: FirNamedReference, data: D): CompositeTransformResult { return transformReference(namedReference, data) } + open fun transformResolvedCallableReference(resolvedCallableReference: FirResolvedCallableReference, data: D): CompositeTransformResult { + return transformNamedReference(resolvedCallableReference, data) + } + open fun transformSuperReference(superReference: E, data: D): CompositeTransformResult { return transformReference(superReference, data) } @@ -580,6 +584,10 @@ abstract class FirTransformer : FirVisitor { + return transformResolvedCallableReference(resolvedCallableReference, data) + } + final override fun visitResolvedDeclarationStatus(resolvedDeclarationStatus: FirResolvedDeclarationStatus, data: D): CompositeTransformResult { return transformResolvedDeclarationStatus(resolvedDeclarationStatus, data) } diff --git a/compiler/fir/tree/visitors/org/jetbrains/kotlin/fir/visitors/FirVisitorGenerated.kt b/compiler/fir/tree/visitors/org/jetbrains/kotlin/fir/visitors/FirVisitorGenerated.kt index bc07ef5a9d8..03ec60809bb 100644 --- a/compiler/fir/tree/visitors/org/jetbrains/kotlin/fir/visitors/FirVisitorGenerated.kt +++ b/compiler/fir/tree/visitors/org/jetbrains/kotlin/fir/visitors/FirVisitorGenerated.kt @@ -140,6 +140,10 @@ abstract class FirVisitor { return visitReference(namedReference, data) } + open fun visitResolvedCallableReference(resolvedCallableReference: FirResolvedCallableReference, data: D): R { + return visitNamedReference(resolvedCallableReference, data) + } + open fun visitSuperReference(superReference: FirSuperReference, data: D): R { return visitReference(superReference, data) } diff --git a/compiler/fir/tree/visitors/org/jetbrains/kotlin/fir/visitors/FirVisitorVoidGenerated.kt b/compiler/fir/tree/visitors/org/jetbrains/kotlin/fir/visitors/FirVisitorVoidGenerated.kt index 69be742b090..77d9b9828e9 100644 --- a/compiler/fir/tree/visitors/org/jetbrains/kotlin/fir/visitors/FirVisitorVoidGenerated.kt +++ b/compiler/fir/tree/visitors/org/jetbrains/kotlin/fir/visitors/FirVisitorVoidGenerated.kt @@ -140,6 +140,10 @@ abstract class FirVisitorVoid : FirVisitor() { visitReference(namedReference, null) } + open fun visitResolvedCallableReference(resolvedCallableReference: FirResolvedCallableReference) { + visitNamedReference(resolvedCallableReference, null) + } + open fun visitSuperReference(superReference: FirSuperReference) { visitReference(superReference, null) } @@ -580,6 +584,10 @@ abstract class FirVisitorVoid : FirVisitor() { visitRegularClass(regularClass) } + final override fun visitResolvedCallableReference(resolvedCallableReference: FirResolvedCallableReference, data: Nothing?) { + visitResolvedCallableReference(resolvedCallableReference) + } + final override fun visitResolvedDeclarationStatus(resolvedDeclarationStatus: FirResolvedDeclarationStatus, data: Nothing?) { visitResolvedDeclarationStatus(resolvedDeclarationStatus) } diff --git a/idea/testData/fir/multiModule/basic/m2_java_dep(m1-java)/user.txt b/idea/testData/fir/multiModule/basic/m2_java_dep(m1-java)/user.txt index 154b1b952b1..b82ccd6ee7a 100644 --- a/idea/testData/fir/multiModule/basic/m2_java_dep(m1-java)/user.txt +++ b/idea/testData/fir/multiModule/basic/m2_java_dep(m1-java)/user.txt @@ -1,4 +1,4 @@ FILE: user.kt public final function foo(hello: R|hello/Hello|): R|kotlin/String| { - return@@@foo STUB + return@@@foo #.# } diff --git a/idea/testData/fir/multiModule/mppMembers/common/common.kt b/idea/testData/fir/multiModule/mppMembers/common/common.kt new file mode 100644 index 00000000000..8d04bbe4141 --- /dev/null +++ b/idea/testData/fir/multiModule/mppMembers/common/common.kt @@ -0,0 +1,5 @@ +expect open class A() { + fun foo() +} + +open class B : A() \ No newline at end of file diff --git a/idea/testData/fir/multiModule/mppMembers/common/common.txt b/idea/testData/fir/multiModule/mppMembers/common/common.txt new file mode 100644 index 00000000000..5012d250b47 --- /dev/null +++ b/idea/testData/fir/multiModule/mppMembers/common/common.txt @@ -0,0 +1,11 @@ +FILE: common.kt + public open expect class A { + public constructor(): super() + + public final function foo(): R|kotlin/Unit| + + } + public open class B : R|A| { + public constructor(): super() + + } diff --git a/idea/testData/fir/multiModule/mppMembers/jvm/jvm.kt b/idea/testData/fir/multiModule/mppMembers/jvm/jvm.kt new file mode 100644 index 00000000000..488c9f817e9 --- /dev/null +++ b/idea/testData/fir/multiModule/mppMembers/jvm/jvm.kt @@ -0,0 +1,19 @@ +actual open class A { + actual fun foo() {} + + fun bar() {} +} + +class C : B() { + fun test() { + foo() + bar() + } +} + +class D : A() { + fun test() { + foo() + bar() + } +} \ No newline at end of file diff --git a/idea/testData/fir/multiModule/mppMembers/jvm/jvm.txt b/idea/testData/fir/multiModule/mppMembers/jvm/jvm.txt new file mode 100644 index 00000000000..3d3abd155be --- /dev/null +++ b/idea/testData/fir/multiModule/mppMembers/jvm/jvm.txt @@ -0,0 +1,29 @@ +FILE: jvm.kt + public open actual class A { + public constructor(): super() + + public final actual function foo(): R|kotlin/Unit| { + } + + public final function bar(): R|kotlin/Unit| { + } + + } + public final class C : R|B| { + public constructor(): super() + + public final function test(): R|kotlin/Unit| { + R|/A.foo|() + #() + } + + } + public final class D : R|A| { + public constructor(): super() + + public final function test(): R|kotlin/Unit| { + R|/A.foo|() + #() + } + + } diff --git a/idea/tests/org/jetbrains/kotlin/idea/fir/AbstractFirMultiModuleResolveTest.kt b/idea/tests/org/jetbrains/kotlin/idea/fir/AbstractFirMultiModuleResolveTest.kt index b7f922f4a20..e5f819f695b 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/fir/AbstractFirMultiModuleResolveTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/fir/AbstractFirMultiModuleResolveTest.kt @@ -68,7 +68,7 @@ abstract class AbstractFirMultiModuleResolveTest : AbstractMultiModuleTest() { for (module in project.allModules().drop(1)) { val session = createSession(module, provider) - val builder = RawFirBuilder(session, stubMode = true) + val builder = RawFirBuilder(session, stubMode = false) val psiManager = PsiManager.getInstance(project) val ideaModuleInfo = session.moduleInfo.cast() diff --git a/idea/tests/org/jetbrains/kotlin/idea/fir/FirMultiModuleResolveTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/fir/FirMultiModuleResolveTestGenerated.java index 8a77615500a..a2c4267168e 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/fir/FirMultiModuleResolveTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/fir/FirMultiModuleResolveTestGenerated.java @@ -33,4 +33,9 @@ public class FirMultiModuleResolveTestGenerated extends AbstractFirMultiModuleRe public void testBasic() throws Exception { runTest("idea/testData/fir/multiModule/basic/"); } + + @TestMetadata("mppMembers") + public void testMppMembers() throws Exception { + runTest("idea/testData/fir/multiModule/mppMembers/"); + } }