Analysis API: Add tests for KtCallResolver.resolveCandidates().
This commit is contained in:
committed by
Ilya Kirillov
parent
f62bdf5826
commit
0ed802bca4
+2
-3
@@ -19,7 +19,6 @@ import org.jetbrains.kotlin.analysis.api.symbols.*
|
||||
import org.jetbrains.kotlin.analysis.api.tokens.ValidityToken
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtSubstitutor
|
||||
import org.jetbrains.kotlin.analysis.api.withValidityAssertion
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.LowLevelFirApiFacadeForResolveOnAir.getTowerContextProvider
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.getOrBuildFir
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.getOrBuildFirFile
|
||||
import org.jetbrains.kotlin.diagnostics.KtDiagnostic
|
||||
@@ -640,7 +639,7 @@ internal class KtFirCallResolver(
|
||||
override fun resolveCandidates(psi: KtElement): List<KtCallInfo> = withValidityAssertion {
|
||||
val firCall = when (val fir = psi.getOrBuildFir(firResolveState)) {
|
||||
is FirFunctionCall -> fir
|
||||
is FirSafeCallExpression -> fir.regularQualifiedAccess.safeAs<FirFunctionCall>()
|
||||
is FirSafeCallExpression -> fir.selector.safeAs<FirFunctionCall>()
|
||||
// TODO: FirDelegatedConstructorColl, FirAnnotationCall, FirArrayOfCall, FirConstructor
|
||||
else -> null
|
||||
} ?: return@withValidityAssertion emptyList()
|
||||
@@ -671,7 +670,7 @@ internal class KtFirCallResolver(
|
||||
|
||||
@OptIn(PrivateForInline::class)
|
||||
fun getAllCandidates(functionCall: FirFunctionCall, element: KtElement): List<KtCallInfo> {
|
||||
val towerContext = firResolveState.getTowerContextProvider().getClosestAvailableParentContext(element)
|
||||
val towerContext = firResolveState.getTowerContextProvider(element.containingKtFile).getClosestAvailableParentContext(element)
|
||||
towerContext?.let { bodyResolveComponents.context.replaceTowerDataContext(it) }
|
||||
// Note: All candidate symbols should have the same name
|
||||
val name =
|
||||
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.fir.components;
|
||||
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.analysis.api.impl.barebone.test.FrontendApiTestConfiguratorService;
|
||||
import org.jetbrains.kotlin.analysis.api.fir.FirFrontendApiTestConfiguratorService;
|
||||
import org.jetbrains.kotlin.analysis.api.impl.base.test.components.AbstractResolveCandidatesTest;
|
||||
import org.jetbrains.kotlin.test.TestMetadata;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/** This class is generated by {@link GenerateNewCompilerTests.kt}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@TestMetadata("analysis/analysis-api/testData/components/callResolver/resolveCandidates")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class FirResolveCandidatesTestGenerated extends AbstractResolveCandidatesTest {
|
||||
@NotNull
|
||||
@Override
|
||||
public FrontendApiTestConfiguratorService getConfigurator() {
|
||||
return FirFrontendApiTestConfiguratorService.INSTANCE;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllFilesPresentInResolveCandidates() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/analysis-api/testData/components/callResolver/resolveCandidates"), Pattern.compile("^(.+)\\.kt$"), null, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("noCandidates.kt")
|
||||
public void testNoCandidates() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/callResolver/resolveCandidates/noCandidates.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("analysis/analysis-api/testData/components/callResolver/resolveCandidates/singleCandidate")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class SingleCandidate {
|
||||
@Test
|
||||
public void testAllFilesPresentInSingleCandidate() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/analysis-api/testData/components/callResolver/resolveCandidates/singleCandidate"), Pattern.compile("^(.+)\\.kt$"), null, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("functionCall.kt")
|
||||
public void testFunctionCall() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/callResolver/resolveCandidates/singleCandidate/functionCall.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("functionCallWithNotEnoughArgs.kt")
|
||||
public void testFunctionCallWithNotEnoughArgs() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/callResolver/resolveCandidates/singleCandidate/functionCallWithNotEnoughArgs.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("indexedGet.kt")
|
||||
public void testIndexedGet() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/callResolver/resolveCandidates/singleCandidate/indexedGet.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("indexedGetWithNotEnoughArgs.kt")
|
||||
public void testIndexedGetWithNotEnoughArgs() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/callResolver/resolveCandidates/singleCandidate/indexedGetWithNotEnoughArgs.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("indexedSet.kt")
|
||||
public void testIndexedSet() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/callResolver/resolveCandidates/singleCandidate/indexedSet.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("indexedSetWithNotEnoughArgs.kt")
|
||||
public void testIndexedSetWithNotEnoughArgs() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/callResolver/resolveCandidates/singleCandidate/indexedSetWithNotEnoughArgs.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("samConstructorCall.kt")
|
||||
public void testSamConstructorCall() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/callResolver/resolveCandidates/singleCandidate/samConstructorCall.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("variableAsFunction.kt")
|
||||
public void testVariableAsFunction() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/callResolver/resolveCandidates/singleCandidate/variableAsFunction.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("variableAsFunctionLikeCall.kt")
|
||||
public void testVariableAsFunctionLikeCall() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/callResolver/resolveCandidates/singleCandidate/variableAsFunctionLikeCall.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user