LL API: fix kt -> fir mapping for KtValueArgument

This commit is contained in:
Ilya Kirillov
2021-07-09 18:22:33 +02:00
committed by teamcityserver
parent 6139d97b2a
commit f6a97cdec6
11 changed files with 81 additions and 3 deletions
@@ -42,7 +42,7 @@ internal class FirModuleResolveStateDepended(
originalState.getSessionFor(moduleInfo)
override fun getOrBuildFirFor(element: KtElement): FirElement? {
val psi = originalState.elementBuilder.getPsiAsFirElementSource(element)
val psi = originalState.elementBuilder.getPsiAsFirElementSource(element) ?: return null
ktToFirMapping?.getFirOfClosestParent(psi, this)?.let { return it }
@@ -32,7 +32,7 @@ import org.jetbrains.kotlin.psi2ir.deparenthesize
*/
@ThreadSafe
internal class FirElementBuilder {
fun getPsiAsFirElementSource(element: KtElement): KtElement {
fun getPsiAsFirElementSource(element: KtElement): KtElement? {
val deparenthesized = if (element is KtPropertyDelegate) element.deparenthesize() else element
return when {
deparenthesized is KtParenthesizedExpression -> deparenthesized.deparenthesize()
@@ -44,6 +44,10 @@ internal class FirElementBuilder {
*/
deparenthesized.selectorExpression ?: error("Incomplete code:\n${element.getElementTextInContext()}")
}
deparenthesized is KtValueArgument -> {
// null will be return in case of invalid KtValueArgument
deparenthesized.getArgumentExpression()
}
else -> deparenthesized
}
}
@@ -88,7 +92,7 @@ internal class FirElementBuilder {
val fileStructure = fileStructureCache.getFileStructure(firFile, moduleFileCache)
val mappings = fileStructure.getStructureElementFor(element).mappings
val psi = getPsiAsFirElementSource(element)
val psi = getPsiAsFirElementSource(element) ?: return null
return mappings.getFirOfClosestParent(psi, state)
?: state.getOrBuildFirFile(firFile)
}
@@ -0,0 +1,6 @@
public annotation class Annotation(val name: String)
@Annotation(<expr>"y"</expr>)
fun x() {
}
@@ -0,0 +1,5 @@
KT element: KtValueArgument
FIR element: FirConstExpressionImpl
FIR element rendered:
String(y)
@@ -0,0 +1,5 @@
// LOOK_UP_FOR_ELEMENT_OF_TYPE: org.jetbrains.kotlin.psi.KtConstructorCalleeExpression
@<expr>Suppress</expr>("")
fun x() {
}
@@ -0,0 +1,5 @@
KT element: KtConstructorCalleeExpression
FIR element: FirAnnotationCallImpl
FIR element rendered:
@R|kotlin/Suppress|(vararg(String()))
@@ -0,0 +1,4 @@
@Suppress("1", <expr>"2"</expr>)
fun x() {
}
@@ -0,0 +1,5 @@
KT element: KtValueArgument
FIR element: FirConstExpressionImpl
FIR element rendered:
String(2)
@@ -0,0 +1,5 @@
// LOOK_UP_FOR_ELEMENT_OF_TYPE: org.jetbrains.kotlin.psi.KtAnnotationEntry
<expr>@Suppress("")</expr>
fun x() {
}
@@ -0,0 +1,5 @@
KT element: KtAnnotationEntry
FIR element: FirAnnotationCallImpl
FIR element rendered:
@R|kotlin/Suppress|(vararg(String()))
@@ -24,6 +24,40 @@ public class GetOrBuildFirTestGenerated extends AbstractGetOrBuildFirTest {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/getOrBuildFir"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@Nested
@TestMetadata("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/getOrBuildFir/annotations")
@TestDataPath("$PROJECT_ROOT")
public class Annotations {
@Test
public void testAllFilesPresentInAnnotations() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/getOrBuildFir/annotations"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@Test
@TestMetadata("annotationApplicationArgument.kt")
public void testAnnotationApplicationArgument() throws Exception {
runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/getOrBuildFir/annotations/annotationApplicationArgument.kt");
}
@Test
@TestMetadata("annotationApplicationCallExpression.kt")
public void testAnnotationApplicationCallExpression() throws Exception {
runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/getOrBuildFir/annotations/annotationApplicationCallExpression.kt");
}
@Test
@TestMetadata("annotationApplicationVarargArgument.kt")
public void testAnnotationApplicationVarargArgument() throws Exception {
runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/getOrBuildFir/annotations/annotationApplicationVarargArgument.kt");
}
@Test
@TestMetadata("annotationApplicationWithArguments.kt")
public void testAnnotationApplicationWithArguments() throws Exception {
runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/getOrBuildFir/annotations/annotationApplicationWithArguments.kt");
}
}
@Nested
@TestMetadata("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/getOrBuildFir/inImport")
@TestDataPath("$PROJECT_ROOT")