[LL FIR] AbstractDependentCopyTest: supports custom text in copy
This provides an ability to test more real-world cases. E.g., we can emulate completion behavior ^KT-60987
This commit is contained in:
committed by
Space Team
parent
52f0f75175
commit
201100db60
+3
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.analysis.low.level.api.fir.util.codeFragment
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.util.errorWithFirSpecificEntries
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.util.isScriptStatement
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.util.originalDeclaration
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.util.originalKtFile
|
||||
import org.jetbrains.kotlin.utils.exceptions.errorWithAttachment
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.parentOfType
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.parentsOfType
|
||||
@@ -190,6 +191,8 @@ object LowLevelFirApiFacadeForResolveOnAir {
|
||||
require(originalFirResolveSession is LLFirResolvableResolveSession)
|
||||
require(elementToAnalyze !is KtFile) { "KtFile for dependency element not supported" }
|
||||
|
||||
elementToAnalyze.containingKtFile.originalKtFile = originalKtFile
|
||||
|
||||
val minimalCopiedDeclaration = elementToAnalyze.getNonLocalContainingOrThisDeclarationCodeFragmentAware {
|
||||
it.isApplicableForOnAirResolve()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
Tower Data Context:
|
||||
Element 0
|
||||
Scope: FirDefaultStarImportingScope
|
||||
Element 1
|
||||
Scope: FirDefaultSimpleImportingScope
|
||||
Element 2
|
||||
Scope: FirExplicitStarImportingScope
|
||||
Element 3
|
||||
Scope: FirDefaultSimpleImportingScope
|
||||
Element 4
|
||||
Scope: FirDefaultSimpleImportingScope
|
||||
Element 5
|
||||
Scope: FirPackageMemberScope
|
||||
Element 6
|
||||
Scope: FirExplicitSimpleImportingScope
|
||||
Element 7
|
||||
Scope: FirLocalScope
|
||||
@@ -0,0 +1,5 @@
|
||||
fun foo() {
|
||||
val i = unusedInOriginal()
|
||||
}
|
||||
|
||||
fun unusedInOriginal() = 42
|
||||
@@ -0,0 +1,8 @@
|
||||
KT element: KtNamedFunction
|
||||
FIR element: FirSimpleFunctionImpl
|
||||
FIR source kind: KtRealSourceElementKind
|
||||
|
||||
FIR element rendered:
|
||||
public final [ResolvedTo(BODY_RESOLVE)] fun foo(): R|kotlin/Unit| {
|
||||
[ResolvedTo(BODY_RESOLVE)] lval i: R|kotlin/Int| = R|/unusedInOriginal|()
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
fun<caret> foo() {
|
||||
"original text"
|
||||
}
|
||||
|
||||
fun unusedInOriginal() = 42
|
||||
+15
-1
@@ -11,8 +11,11 @@ import org.jetbrains.kotlin.analysis.low.level.api.fir.test.base.AbstractLowLeve
|
||||
import org.jetbrains.kotlin.analysis.test.framework.services.expressionMarkerProvider
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||
import org.jetbrains.kotlin.test.services.TestModuleStructure
|
||||
import org.jetbrains.kotlin.test.services.TestServices
|
||||
import kotlin.io.path.exists
|
||||
import kotlin.io.path.readText
|
||||
|
||||
/**
|
||||
* This test class is supposed to specify the behavior of [getFirResolveSessionForDependentCopy].
|
||||
@@ -28,7 +31,18 @@ abstract class AbstractDependentCopyTest : AbstractLowLevelApiSingleFileTest() {
|
||||
registeredDirectives = moduleStructure.allDirectives,
|
||||
)
|
||||
|
||||
val fileCopy = ktFile.copy() as KtFile
|
||||
val specialContentForCopiedFile = getTestDataFileSiblingPath(
|
||||
extension = "copy.txt",
|
||||
testPrefix = null,
|
||||
).takeIf { it.exists() }?.readText()
|
||||
|
||||
val fileCopy = KtPsiFactory(ktFile.project).createFile(
|
||||
ktFile.name,
|
||||
specialContentForCopiedFile ?: ktFile.text,
|
||||
)
|
||||
|
||||
fileCopy.originalFile = ktFile
|
||||
|
||||
val sameElementInCopy = PsiTreeUtil.findSameElementInCopy(element, fileCopy)
|
||||
resolveWithClearCaches(ktFile) { originalSession ->
|
||||
val dependentSession = getFirResolveSessionForDependentCopy(
|
||||
|
||||
+6
@@ -35,4 +35,10 @@ public class SourceDependentCopyContextTestGenerated extends AbstractSourceDepen
|
||||
public void testClassBody() throws Exception {
|
||||
runTest("analysis/low-level-api-fir/testdata/dependentCopy/classBody.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("function.kt")
|
||||
public void testFunction() throws Exception {
|
||||
runTest("analysis/low-level-api-fir/testdata/dependentCopy/function.kt");
|
||||
}
|
||||
}
|
||||
|
||||
+6
@@ -35,4 +35,10 @@ public class SourceDependentCopyFirTestGenerated extends AbstractSourceDependent
|
||||
public void testClassBody() throws Exception {
|
||||
runTest("analysis/low-level-api-fir/testdata/dependentCopy/classBody.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("function.kt")
|
||||
public void testFunction() throws Exception {
|
||||
runTest("analysis/low-level-api-fir/testdata/dependentCopy/function.kt");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user