[Analysis API] support creating KtSymbol by K/JS dynamic scope
^KT-61257 fixed
This commit is contained in:
committed by
Space Team
parent
91edbeb747
commit
a90562c0da
+5
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.analysis.api.components.KtSymbolContainingDeclaratio
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.KtFe10AnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.components.base.Fe10KtAnalysisSessionComponent
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.KtFe10DescDefaultBackingFieldSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.KtFe10DynamicFunctionDescValueParameterSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.base.getDescriptor
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.base.toKtSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.getModule
|
||||
@@ -66,6 +67,10 @@ internal class KtFe10SymbolContainingDeclarationProvider(
|
||||
return getContainingModule(symbol.owningProperty)
|
||||
}
|
||||
|
||||
if (symbol is KtFe10DynamicFunctionDescValueParameterSymbol) {
|
||||
return getContainingModule(symbol.owner)
|
||||
}
|
||||
|
||||
TODO(symbol::class.java.name)
|
||||
}
|
||||
|
||||
|
||||
+28
-4
@@ -33,6 +33,7 @@ import org.jetbrains.kotlin.name.CallableId
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.returnTypeOrNothing
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.isDynamic
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isExtension
|
||||
|
||||
internal class KtFe10DescFunctionSymbol private constructor(
|
||||
@@ -49,13 +50,24 @@ internal class KtFe10DescFunctionSymbol private constructor(
|
||||
}
|
||||
|
||||
override val symbolKind: KtSymbolKind
|
||||
get() = withValidityAssertion { descriptor.ktSymbolKind }
|
||||
get() = withValidityAssertion {
|
||||
if (descriptor.isDynamic()) {
|
||||
return@withValidityAssertion KtSymbolKind.CLASS_MEMBER
|
||||
}
|
||||
descriptor.ktSymbolKind
|
||||
}
|
||||
|
||||
override val isSuspend: Boolean
|
||||
get() = withValidityAssertion { descriptor.isSuspend }
|
||||
|
||||
override val isOperator: Boolean
|
||||
get() = withValidityAssertion { descriptor.isOperator }
|
||||
get() = withValidityAssertion {
|
||||
if (descriptor.isDynamic()) {
|
||||
// For consistency with the K2 implementation, see `FirDynamicMembersStorage`
|
||||
return@withValidityAssertion true
|
||||
}
|
||||
descriptor.isOperator
|
||||
}
|
||||
|
||||
override val isExternal: Boolean
|
||||
get() = withValidityAssertion { descriptor.isExternal }
|
||||
@@ -67,7 +79,13 @@ internal class KtFe10DescFunctionSymbol private constructor(
|
||||
get() = withValidityAssertion { descriptor.isExplicitOverride }
|
||||
|
||||
override val isInfix: Boolean
|
||||
get() = withValidityAssertion { descriptor.isInfix }
|
||||
get() = withValidityAssertion {
|
||||
if (descriptor.isDynamic()) {
|
||||
// For consistency with the K2 implementation, see `FirDynamicMembersStorage`
|
||||
return@withValidityAssertion true
|
||||
}
|
||||
descriptor.isInfix
|
||||
}
|
||||
|
||||
override val isStatic: Boolean
|
||||
get() = withValidityAssertion { descriptor is JavaCallableMemberDescriptor && DescriptorUtils.isStaticDeclaration(descriptor) }
|
||||
@@ -82,7 +100,13 @@ internal class KtFe10DescFunctionSymbol private constructor(
|
||||
get() = withValidityAssertion { descriptor.isExpect }
|
||||
|
||||
override val valueParameters: List<KtValueParameterSymbol>
|
||||
get() = withValidityAssertion { descriptor.valueParameters.map { KtFe10DescValueParameterSymbol(it, analysisContext) } }
|
||||
get() = withValidityAssertion {
|
||||
if (descriptor.isDynamic()) {
|
||||
// For consistency with the K2 implementation, see `FirDynamicMembersStorage`
|
||||
return@withValidityAssertion listOf(KtFe10DynamicFunctionDescValueParameterSymbol(this))
|
||||
}
|
||||
descriptor.valueParameters.map { KtFe10DescValueParameterSymbol(it, analysisContext) }
|
||||
}
|
||||
|
||||
override val hasStableParameterNames: Boolean
|
||||
get() = withValidityAssertion { descriptor.ktHasStableParameterNames }
|
||||
|
||||
+12
-4
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.psi.KtParameter
|
||||
import org.jetbrains.kotlin.psi.KtProperty
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.isDynamic
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isExtension
|
||||
|
||||
internal class KtFe10DescKotlinPropertySymbol(
|
||||
@@ -37,7 +38,12 @@ internal class KtFe10DescKotlinPropertySymbol(
|
||||
get() = withValidityAssertion { descriptor.name }
|
||||
|
||||
override val symbolKind: KtSymbolKind
|
||||
get() = withValidityAssertion { descriptor.ktSymbolKind }
|
||||
get() = withValidityAssertion {
|
||||
if (descriptor.isDynamic()) {
|
||||
return@withValidityAssertion KtSymbolKind.CLASS_MEMBER
|
||||
}
|
||||
descriptor.ktSymbolKind
|
||||
}
|
||||
|
||||
override val isLateInit: Boolean
|
||||
get() = withValidityAssertion { descriptor.isLateInit }
|
||||
@@ -67,10 +73,10 @@ internal class KtFe10DescKotlinPropertySymbol(
|
||||
get() = withValidityAssertion { descriptor.isExpect }
|
||||
|
||||
override val hasGetter: Boolean
|
||||
get() = withValidityAssertion { true }
|
||||
get() = withValidityAssertion { !descriptor.isDynamic() }
|
||||
|
||||
override val hasSetter: Boolean
|
||||
get() = withValidityAssertion { descriptor.isVar }
|
||||
get() = withValidityAssertion { !descriptor.isDynamic() && !isVal }
|
||||
|
||||
override val callableIdIfNonLocal: CallableId?
|
||||
get() = withValidityAssertion { descriptor.callableIdIfNotLocal }
|
||||
@@ -86,14 +92,16 @@ internal class KtFe10DescKotlinPropertySymbol(
|
||||
createKtInitializerValue(initializer, descriptor, analysisContext)
|
||||
}
|
||||
|
||||
override val getter: KtPropertyGetterSymbol
|
||||
override val getter: KtPropertyGetterSymbol?
|
||||
get() = withValidityAssertion {
|
||||
if (descriptor.isDynamic()) return null
|
||||
val getter = descriptor.getter ?: return KtFe10DescDefaultPropertyGetterSymbol(descriptor, analysisContext)
|
||||
return KtFe10DescPropertyGetterSymbol(getter, analysisContext)
|
||||
}
|
||||
|
||||
override val setter: KtPropertySetterSymbol?
|
||||
get() = withValidityAssertion {
|
||||
if (descriptor.isDynamic()) return null
|
||||
if (!descriptor.isVar) {
|
||||
return null
|
||||
}
|
||||
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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.api.descriptors.symbols.descriptorBased
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationsList
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.Fe10AnalysisContext
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.base.KtFe10Symbol
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.base.toKtType
|
||||
import org.jetbrains.kotlin.analysis.api.impl.base.annotations.KtEmptyAnnotationsList
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeToken
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtFunctionSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbolOrigin
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtValueParameterSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.types.createDynamicType
|
||||
|
||||
internal class KtFe10DynamicFunctionDescValueParameterSymbol(
|
||||
val owner: KtFe10DescFunctionSymbol,
|
||||
) : KtValueParameterSymbol(), KtFe10Symbol {
|
||||
override val analysisContext: Fe10AnalysisContext
|
||||
get() = owner.analysisContext
|
||||
|
||||
override val token: KtLifetimeToken
|
||||
get() = owner.token
|
||||
|
||||
override val origin: KtSymbolOrigin
|
||||
get() = withValidityAssertion { KtSymbolOrigin.JS_DYNAMIC }
|
||||
|
||||
override val psi: PsiElement?
|
||||
get() = withValidityAssertion { null }
|
||||
|
||||
override val annotationsList: KtAnnotationsList
|
||||
get() = withValidityAssertion { KtEmptyAnnotationsList(token) }
|
||||
|
||||
override val name: Name
|
||||
get() = withValidityAssertion { Name.identifier("args") }
|
||||
|
||||
override val hasDefaultValue: Boolean
|
||||
get() = withValidityAssertion { false }
|
||||
|
||||
override val isVararg: Boolean
|
||||
get() = withValidityAssertion { true }
|
||||
|
||||
override val isCrossinline: Boolean
|
||||
get() = withValidityAssertion { false }
|
||||
|
||||
override val isNoinline: Boolean
|
||||
get() = withValidityAssertion { false }
|
||||
|
||||
override val isImplicitLambdaParameter: Boolean
|
||||
get() = withValidityAssertion { false }
|
||||
|
||||
override val returnType: KtType
|
||||
get() = withValidityAssertion { createDynamicType(analysisContext.builtIns).toKtType(analysisContext) }
|
||||
|
||||
context(KtAnalysisSession)
|
||||
override fun createPointer(): KtSymbolPointer<KtValueParameterSymbol> = withValidityAssertion {
|
||||
Pointer(owner.createPointer())
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean = other is KtFe10DynamicFunctionDescValueParameterSymbol && other.owner == this.owner
|
||||
override fun hashCode(): Int = owner.hashCode()
|
||||
|
||||
|
||||
private class Pointer(val ownerPointer: KtSymbolPointer<KtFunctionSymbol>) : KtSymbolPointer<KtValueParameterSymbol>() {
|
||||
@Deprecated("Consider using org.jetbrains.kotlin.analysis.api.KtAnalysisSession.restoreSymbol")
|
||||
override fun restoreSymbol(analysisSession: KtAnalysisSession): KtValueParameterSymbol? {
|
||||
@Suppress("DEPRECATION")
|
||||
val owner = ownerPointer.restoreSymbol(analysisSession) as? KtFe10DescFunctionSymbol ?: return null
|
||||
return KtFe10DynamicFunctionDescValueParameterSymbol(owner)
|
||||
}
|
||||
}
|
||||
}
|
||||
+7
-1
@@ -50,6 +50,7 @@ import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.CapturedType
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.isDynamic
|
||||
import org.jetbrains.kotlin.resolve.constants.*
|
||||
import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.annotationClass
|
||||
@@ -141,6 +142,7 @@ internal fun KtSymbol.getDescriptor(): DeclarationDescriptor? {
|
||||
is KtFe10PsiDefaultSetterParameterSymbol -> descriptor
|
||||
is KtFe10PsiDefaultPropertySetterSymbol -> null
|
||||
is KtFe10DescDefaultPropertySetterSymbol -> null
|
||||
is KtFe10DynamicFunctionDescValueParameterSymbol -> null
|
||||
is KtFe10FileSymbol -> null
|
||||
is KtFe10DescDefaultPropertySetterSymbol.DefaultKtValueParameterSymbol -> descriptor
|
||||
is KtFe10PsiDefaultPropertySetterSymbol.DefaultKtValueParameterSymbol -> descriptor
|
||||
@@ -331,7 +333,11 @@ internal fun DeclarationDescriptor.getSymbolOrigin(analysisContext: Fe10Analysis
|
||||
is CallableMemberDescriptor -> when (kind) {
|
||||
CallableMemberDescriptor.Kind.DELEGATION -> return KtSymbolOrigin.DELEGATED
|
||||
CallableMemberDescriptor.Kind.SYNTHESIZED -> return KtSymbolOrigin.SOURCE_MEMBER_GENERATED
|
||||
else -> {}
|
||||
else -> {
|
||||
if (isDynamic()) {
|
||||
return KtSymbolOrigin.JS_DYNAMIC
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+28
@@ -220,6 +220,34 @@ public class Fe10IdeNormalAnalysisSourceModuleSymbolByReferenceTestGenerated ext
|
||||
runTest("analysis/analysis-api/testData/symbols/symbolByReference/valueParameter.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("analysis/analysis-api/testData/symbols/symbolByReference/js")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class Js {
|
||||
@Test
|
||||
public void testAllFilesPresentInJs() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/analysis-api/testData/symbols/symbolByReference/js"), Pattern.compile("^(.+)\\.kt$"), null, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("functionFromJsDynamicScopeNoArguments.kt")
|
||||
public void testFunctionFromJsDynamicScopeNoArguments() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/symbols/symbolByReference/js/functionFromJsDynamicScopeNoArguments.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("functionFromJsDynamicScopeWithArguments.kt")
|
||||
public void testFunctionFromJsDynamicScopeWithArguments() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/symbols/symbolByReference/js/functionFromJsDynamicScopeWithArguments.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("propertyFromJsDynamicScope.kt")
|
||||
public void testPropertyFromJsDynamicScope() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/symbols/symbolByReference/js/propertyFromJsDynamicScope.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("analysis/analysis-api/testData/symbols/symbolByReference/withTestCompilerPluginEnabled")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
+10
-1
@@ -76,7 +76,16 @@ internal class KtFirSymbolContainingDeclarationProvider(
|
||||
|
||||
is KtCallableSymbol -> {
|
||||
val outerFirClassifier = symbol.firSymbol.getContainingClassSymbol(symbol.firSymbol.llFirSession)
|
||||
?: return getParentSymbolByPsi()
|
||||
if (outerFirClassifier == null) {
|
||||
return when (firSymbol.origin) {
|
||||
FirDeclarationOrigin.DynamicScope -> {
|
||||
// A callable declaration from dynamic scope has no containing declaration as it comes from a dynamic type
|
||||
// which is not based on a specific classifier
|
||||
null
|
||||
}
|
||||
else -> getParentSymbolByPsi()
|
||||
}
|
||||
}
|
||||
firSymbolBuilder.buildSymbol(outerFirClassifier) as? KtDeclarationSymbol
|
||||
}
|
||||
|
||||
|
||||
+2
@@ -33,6 +33,7 @@ import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.Visibility
|
||||
import org.jetbrains.kotlin.fir.containingClassLookupTag
|
||||
import org.jetbrains.kotlin.fir.contracts.FirEffectDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.*
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.isExtension
|
||||
@@ -92,6 +93,7 @@ internal class KtFirFunctionSymbol(
|
||||
override val symbolKind: KtSymbolKind
|
||||
get() = withValidityAssertion {
|
||||
when {
|
||||
firSymbol.origin == FirDeclarationOrigin.DynamicScope -> KtSymbolKind.CLASS_MEMBER
|
||||
firSymbol.isLocal -> KtSymbolKind.LOCAL
|
||||
firSymbol.containingClassLookupTag()?.classId == null -> KtSymbolKind.TOP_LEVEL
|
||||
else -> KtSymbolKind.CLASS_MEMBER
|
||||
|
||||
+3
@@ -68,6 +68,9 @@ internal class KtFirKotlinPropertySymbol(
|
||||
|
||||
override val symbolKind: KtSymbolKind
|
||||
get() = withValidityAssertion {
|
||||
if (firSymbol.origin == FirDeclarationOrigin.DynamicScope) {
|
||||
return@withValidityAssertion KtSymbolKind.CLASS_MEMBER
|
||||
}
|
||||
when (firSymbol.containingClassLookupTag()?.classId) {
|
||||
null -> KtSymbolKind.TOP_LEVEL
|
||||
else -> KtSymbolKind.CLASS_MEMBER
|
||||
|
||||
+1
-5
@@ -19,7 +19,6 @@ import org.jetbrains.kotlin.analysis.api.symbols.markers.KtSymbolKind
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.util.errorWithFirSpecificEntries
|
||||
import org.jetbrains.kotlin.fir.utils.exceptions.withFirEntry
|
||||
import org.jetbrains.kotlin.utils.exceptions.errorWithAttachment
|
||||
import org.jetbrains.kotlin.fir.containingClassForLocalAttr
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.synthetic.FirSyntheticProperty
|
||||
import org.jetbrains.kotlin.fir.declarations.synthetic.FirSyntheticPropertyAccessor
|
||||
@@ -27,7 +26,6 @@ import org.jetbrains.kotlin.fir.declarations.utils.isLocal
|
||||
import org.jetbrains.kotlin.fir.scopes.impl.importedFromObjectOrStaticData
|
||||
import org.jetbrains.kotlin.fir.scopes.impl.originalForWrappedIntegerOperator
|
||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
|
||||
|
||||
internal interface KtFirSymbol<out S : FirBasedSymbol<*>> : KtSymbol, KtLifetimeOwner {
|
||||
val firSymbol: S
|
||||
@@ -98,9 +96,7 @@ internal tailrec fun FirDeclaration.ktSymbolOrigin(): KtSymbolOrigin = when (ori
|
||||
is FirDeclarationOrigin.Plugin -> KtSymbolOrigin.PLUGIN
|
||||
FirDeclarationOrigin.RenamedForOverride -> KtSymbolOrigin.JAVA
|
||||
is FirDeclarationOrigin.SubstitutionOverride -> KtSymbolOrigin.SUBSTITUTION_OVERRIDE
|
||||
FirDeclarationOrigin.DynamicScope -> errorWithAttachment("Invalid FirDeclarationOrigin ${origin::class.simpleName}") {
|
||||
withFirEntry("firToGetOrigin", this@ktSymbolOrigin)
|
||||
}
|
||||
FirDeclarationOrigin.DynamicScope -> KtSymbolOrigin.JS_DYNAMIC
|
||||
is FirDeclarationOrigin.ScriptCustomization -> KtSymbolOrigin.PLUGIN
|
||||
}
|
||||
|
||||
|
||||
+18
-3
@@ -23,6 +23,8 @@ import org.jetbrains.kotlin.fir.references.impl.FirPropertyFromParameterResolved
|
||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.lazyResolveToPhase
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||
import org.jetbrains.kotlin.fir.types.ConeDynamicType
|
||||
import org.jetbrains.kotlin.fir.types.create
|
||||
import org.jetbrains.kotlin.fir.types.toRegularClassSymbol
|
||||
import org.jetbrains.kotlin.fir.utils.exceptions.withFirEntry
|
||||
import org.jetbrains.kotlin.name.CallableId
|
||||
@@ -79,8 +81,13 @@ private fun createContextReceiver(
|
||||
builder.token
|
||||
)
|
||||
|
||||
internal fun FirCallableSymbol<*>.getCallableIdIfNonLocal(): CallableId? =
|
||||
callableId.takeUnless { it.isLocal }
|
||||
internal fun FirCallableSymbol<*>.getCallableIdIfNonLocal(): CallableId? {
|
||||
return when {
|
||||
origin == FirDeclarationOrigin.DynamicScope -> null
|
||||
callableId.isLocal -> null
|
||||
else -> callableId
|
||||
}
|
||||
}
|
||||
|
||||
internal fun FirClassLikeSymbol<*>.getClassIdIfNonLocal(): ClassId? =
|
||||
classId.takeUnless { it.isLocal }
|
||||
@@ -88,7 +95,15 @@ internal fun FirClassLikeSymbol<*>.getClassIdIfNonLocal(): ClassId? =
|
||||
internal fun FirCallableSymbol<*>.dispatchReceiverType(
|
||||
builder: KtSymbolByFirBuilder,
|
||||
): KtType? {
|
||||
return dispatchReceiverType?.let { builder.typeBuilder.buildKtType(it) }
|
||||
val type = if (
|
||||
origin == FirDeclarationOrigin.DynamicScope
|
||||
&& (this is FirPropertySymbol || this is FirFunctionSymbol)
|
||||
) {
|
||||
ConeDynamicType.create(builder.rootSession)
|
||||
} else {
|
||||
dispatchReceiverType
|
||||
}
|
||||
return type?.let { builder.typeBuilder.buildKtType(it) }
|
||||
}
|
||||
|
||||
internal fun FirVariableSymbol<*>.getKtConstantInitializer(resolveSession: LLFirResolveSession): KtInitializerValue? {
|
||||
|
||||
+10
@@ -58,6 +58,16 @@ public class FirIdeNormalAnalysisScriptSourceModuleSymbolByReferenceTestGenerate
|
||||
runTest("analysis/analysis-api/testData/symbols/symbolByReference/scriptResult.kts");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("analysis/analysis-api/testData/symbols/symbolByReference/js")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class Js {
|
||||
@Test
|
||||
public void testAllFilesPresentInJs() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/analysis-api/testData/symbols/symbolByReference/js"), Pattern.compile("^(.+)\\.kts$"), null, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("analysis/analysis-api/testData/symbols/symbolByReference/withTestCompilerPluginEnabled")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
+28
@@ -220,6 +220,34 @@ public class FirIdeNormalAnalysisSourceModuleSymbolByReferenceTestGenerated exte
|
||||
runTest("analysis/analysis-api/testData/symbols/symbolByReference/valueParameter.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("analysis/analysis-api/testData/symbols/symbolByReference/js")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class Js {
|
||||
@Test
|
||||
public void testAllFilesPresentInJs() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/analysis-api/testData/symbols/symbolByReference/js"), Pattern.compile("^(.+)\\.kt$"), null, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("functionFromJsDynamicScopeNoArguments.kt")
|
||||
public void testFunctionFromJsDynamicScopeNoArguments() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/symbols/symbolByReference/js/functionFromJsDynamicScopeNoArguments.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("functionFromJsDynamicScopeWithArguments.kt")
|
||||
public void testFunctionFromJsDynamicScopeWithArguments() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/symbols/symbolByReference/js/functionFromJsDynamicScopeWithArguments.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("propertyFromJsDynamicScope.kt")
|
||||
public void testPropertyFromJsDynamicScope() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/symbols/symbolByReference/js/propertyFromJsDynamicScope.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("analysis/analysis-api/testData/symbols/symbolByReference/withTestCompilerPluginEnabled")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
+28
@@ -219,4 +219,32 @@ public class FirStandaloneNormalAnalysisSourceModuleSymbolByReferenceTestGenerat
|
||||
public void testValueParameter() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/symbols/symbolByReference/valueParameter.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("analysis/analysis-api/testData/symbols/symbolByReference/js")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class Js {
|
||||
@Test
|
||||
public void testAllFilesPresentInJs() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/analysis-api/testData/symbols/symbolByReference/js"), Pattern.compile("^(.+)\\.kt$"), null, true, "withTestCompilerPluginEnabled");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("functionFromJsDynamicScopeNoArguments.kt")
|
||||
public void testFunctionFromJsDynamicScopeNoArguments() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/symbols/symbolByReference/js/functionFromJsDynamicScopeNoArguments.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("functionFromJsDynamicScopeWithArguments.kt")
|
||||
public void testFunctionFromJsDynamicScopeWithArguments() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/symbols/symbolByReference/js/functionFromJsDynamicScopeWithArguments.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("propertyFromJsDynamicScope.kt")
|
||||
public void testPropertyFromJsDynamicScope() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/symbols/symbolByReference/js/propertyFromJsDynamicScope.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,4 +154,12 @@ public enum class KtSymbolOrigin {
|
||||
* @see org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin.Plugin
|
||||
*/
|
||||
PLUGIN,
|
||||
|
||||
|
||||
/**
|
||||
* Declaration from dynamic Kotlin/JS scope.
|
||||
*
|
||||
* See: [Dynamic type Kotlin documentation](https://kotlinlang.org/docs/dynamic-type.html)
|
||||
*/
|
||||
JS_DYNAMIC,
|
||||
}
|
||||
|
||||
analysis/analysis-api/testData/symbols/symbolByReference/js/functionFromJsDynamicScopeNoArguments.kt
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
// TARGET_PLATFORM: JS
|
||||
// DO_NOT_CHECK_SYMBOL_RESTORE
|
||||
|
||||
fun foo(jsObject: dynamic) {
|
||||
jsObject.dynamic<caret>FunctionCall()
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
infix operator fun dynamicFunctionCall(vararg args: dynamic): dynamic
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
KtFunctionSymbol:
|
||||
annotationsList: []
|
||||
callableIdIfNonLocal: null
|
||||
contextReceivers: []
|
||||
contractEffects: []
|
||||
hasStableParameterNames: true
|
||||
isActual: false
|
||||
isBuiltinFunctionInvoke: false
|
||||
isExpect: false
|
||||
isExtension: false
|
||||
isExternal: false
|
||||
isInfix: true
|
||||
isInline: false
|
||||
isOperator: true
|
||||
isOverride: false
|
||||
isStatic: false
|
||||
isSuspend: false
|
||||
modality: FINAL
|
||||
name: dynamicFunctionCall
|
||||
origin: JS_DYNAMIC
|
||||
receiverParameter: null
|
||||
returnType: KtDynamicType:
|
||||
annotationsList: []
|
||||
type: dynamic
|
||||
symbolKind: CLASS_MEMBER
|
||||
typeParameters: []
|
||||
valueParameters: [
|
||||
KtValueParameterSymbol:
|
||||
annotationsList: []
|
||||
callableIdIfNonLocal: null
|
||||
contextReceivers: []
|
||||
generatedPrimaryConstructorProperty: null
|
||||
hasDefaultValue: false
|
||||
isCrossinline: false
|
||||
isExtension: false
|
||||
isImplicitLambdaParameter: false
|
||||
isNoinline: false
|
||||
isVararg: true
|
||||
name: args
|
||||
origin: JS_DYNAMIC
|
||||
receiverParameter: null
|
||||
returnType: KtDynamicType:
|
||||
annotationsList: []
|
||||
type: dynamic
|
||||
symbolKind: LOCAL
|
||||
typeParameters: []
|
||||
getContainingModule: KtSourceModule "Sources of main"
|
||||
deprecationStatus: null
|
||||
]
|
||||
visibility: Public
|
||||
getDispatchReceiver(): KtDynamicType:
|
||||
annotationsList: []
|
||||
type: dynamic
|
||||
getContainingModule: KtSourceModule "Sources of main"
|
||||
deprecationStatus: null
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// TARGET_PLATFORM: JS
|
||||
// DO_NOT_CHECK_SYMBOL_RESTORE
|
||||
|
||||
fun foo(jsObject: dynamic) {
|
||||
jsObject.dynamic<caret>FunctionCall(1, "str")
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
infix operator fun dynamicFunctionCall(vararg args: dynamic): dynamic
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
KtFunctionSymbol:
|
||||
annotationsList: []
|
||||
callableIdIfNonLocal: null
|
||||
contextReceivers: []
|
||||
contractEffects: []
|
||||
hasStableParameterNames: true
|
||||
isActual: false
|
||||
isBuiltinFunctionInvoke: false
|
||||
isExpect: false
|
||||
isExtension: false
|
||||
isExternal: false
|
||||
isInfix: true
|
||||
isInline: false
|
||||
isOperator: true
|
||||
isOverride: false
|
||||
isStatic: false
|
||||
isSuspend: false
|
||||
modality: FINAL
|
||||
name: dynamicFunctionCall
|
||||
origin: JS_DYNAMIC
|
||||
receiverParameter: null
|
||||
returnType: KtDynamicType:
|
||||
annotationsList: []
|
||||
type: dynamic
|
||||
symbolKind: CLASS_MEMBER
|
||||
typeParameters: []
|
||||
valueParameters: [
|
||||
KtValueParameterSymbol:
|
||||
annotationsList: []
|
||||
callableIdIfNonLocal: null
|
||||
contextReceivers: []
|
||||
generatedPrimaryConstructorProperty: null
|
||||
hasDefaultValue: false
|
||||
isCrossinline: false
|
||||
isExtension: false
|
||||
isImplicitLambdaParameter: false
|
||||
isNoinline: false
|
||||
isVararg: true
|
||||
name: args
|
||||
origin: JS_DYNAMIC
|
||||
receiverParameter: null
|
||||
returnType: KtDynamicType:
|
||||
annotationsList: []
|
||||
type: dynamic
|
||||
symbolKind: LOCAL
|
||||
typeParameters: []
|
||||
getContainingModule: KtSourceModule "Sources of main"
|
||||
deprecationStatus: null
|
||||
]
|
||||
visibility: Public
|
||||
getDispatchReceiver(): KtDynamicType:
|
||||
annotationsList: []
|
||||
type: dynamic
|
||||
getContainingModule: KtSourceModule "Sources of main"
|
||||
deprecationStatus: null
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// TARGET_PLATFORM: JS
|
||||
// DO_NOT_CHECK_SYMBOL_RESTORE
|
||||
|
||||
fun foo(jsObject: dynamic) {
|
||||
jsObject.dynamic<caret>PropertyAcess
|
||||
}
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
var dynamicPropertyAcess: dynamic
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
KtKotlinPropertySymbol:
|
||||
annotationsList: []
|
||||
backingFieldSymbol: null
|
||||
callableIdIfNonLocal: null
|
||||
contextReceivers: []
|
||||
getter: null
|
||||
hasBackingField: true
|
||||
hasGetter: false
|
||||
hasSetter: false
|
||||
initializer: null
|
||||
isActual: false
|
||||
isConst: false
|
||||
isDelegatedProperty: false
|
||||
isExpect: false
|
||||
isExtension: false
|
||||
isFromPrimaryConstructor: false
|
||||
isLateInit: false
|
||||
isOverride: false
|
||||
isStatic: false
|
||||
isVal: false
|
||||
modality: FINAL
|
||||
name: dynamicPropertyAcess
|
||||
origin: JS_DYNAMIC
|
||||
receiverParameter: null
|
||||
returnType: KtDynamicType:
|
||||
annotationsList: []
|
||||
type: dynamic
|
||||
setter: null
|
||||
symbolKind: CLASS_MEMBER
|
||||
typeParameters: []
|
||||
visibility: Public
|
||||
getDispatchReceiver(): KtDynamicType:
|
||||
annotationsList: []
|
||||
type: dynamic
|
||||
getContainingModule: KtSourceModule "Sources of main"
|
||||
deprecationStatus: null
|
||||
getterDeprecationStatus: null
|
||||
javaGetterName: getDynamicPropertyAcess
|
||||
javaSetterName: setDynamicPropertyAcess
|
||||
setterDeprecationStatus: null
|
||||
@@ -165,6 +165,7 @@ class FirDynamicMembersStorage(val session: FirSession) : FirSessionComponent {
|
||||
moduleData = session.moduleData
|
||||
containingFunctionSymbol = this@buildSimpleFunction.symbol
|
||||
origin = FirDeclarationOrigin.DynamicScope
|
||||
resolvePhase = FirResolvePhase.BODY_RESOLVE
|
||||
returnTypeRef = anyArrayTypeRef
|
||||
this.name = Name.identifier("args")
|
||||
this.symbol = FirValueParameterSymbol(this.name)
|
||||
|
||||
Reference in New Issue
Block a user