[SLC] cover case with invalid java identifier as annotation argument
^KT-56868 Fixed ^KT-57328
This commit is contained in:
committed by
Space Team
parent
948c511284
commit
71299f1d13
+13
-6
@@ -188,17 +188,24 @@ internal fun KtAnnotationValue.toAnnotationMemberValue(parent: PsiElement): PsiA
|
||||
}
|
||||
}
|
||||
|
||||
is KtEnumEntryAnnotationValue -> {
|
||||
val fqName = this.callableId?.asSingleFqName()?.asString() ?: return null
|
||||
val psiReference = PsiElementFactory.getInstance(parent.project).createReferenceFromText(fqName, parent)
|
||||
SymbolPsiReference(sourcePsi, parent, psiReference)
|
||||
}
|
||||
|
||||
is KtEnumEntryAnnotationValue -> asPsiReferenceExpression(parent)
|
||||
KtUnsupportedAnnotationValue -> null
|
||||
is KtKClassAnnotationValue -> toAnnotationMemberValue(parent)
|
||||
}
|
||||
}
|
||||
|
||||
private fun KtEnumEntryAnnotationValue.asPsiReferenceExpression(parent: PsiElement): SymbolPsiReference? {
|
||||
val fqName = this.callableId?.asSingleFqName()?.asString() ?: return null
|
||||
val elementFactory = PsiElementFactory.getInstance(parent.project)
|
||||
val psiReference = try {
|
||||
elementFactory.createReferenceFromText(fqName, parent)
|
||||
} catch (_: IncorrectOperationException) {
|
||||
return null
|
||||
}
|
||||
|
||||
return SymbolPsiReference(sourcePsi, parent, psiReference)
|
||||
}
|
||||
|
||||
private fun KtKClassAnnotationValue.toAnnotationMemberValue(parent: PsiElement): PsiExpression? {
|
||||
val typeString = when (this) {
|
||||
is KtKClassAnnotationValue.KtNonLocalKClassAnnotationValue -> classId.asSingleFqName().asString()
|
||||
|
||||
+23
-7
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder
|
||||
import org.jetbrains.kotlin.test.directives.ConfigurationDirectives
|
||||
import org.jetbrains.kotlin.test.directives.ModuleStructureDirectives
|
||||
import org.jetbrains.kotlin.test.directives.model.Directive
|
||||
import org.jetbrains.kotlin.test.directives.model.DirectiveApplicability
|
||||
import org.jetbrains.kotlin.test.directives.model.SimpleDirectivesContainer
|
||||
import org.jetbrains.kotlin.test.model.TestModule
|
||||
@@ -65,7 +66,7 @@ abstract class AbstractSymbolLightClassesTestBase(
|
||||
val ktFile = ktFiles.first()
|
||||
val project = ktFile.project
|
||||
|
||||
ignoreExceptionIfIgnoreFirPresent(module) {
|
||||
ignoreExceptionIfIgnoreDirectivePresent(module) {
|
||||
compareResults(module, testServices) {
|
||||
getRenderResult(ktFile, ktFiles, testDataPath, module, project)
|
||||
}
|
||||
@@ -75,7 +76,7 @@ abstract class AbstractSymbolLightClassesTestBase(
|
||||
protected fun compareResults(module: TestModule, testServices: TestServices, computeActual: () -> String) {
|
||||
val actual = computeActual().cleanup()
|
||||
compareResults(testServices, actual)
|
||||
removeIgnoreFir(module)
|
||||
removeIgnoreDirectives(module)
|
||||
removeDuplicatedFirJava(testServices)
|
||||
}
|
||||
|
||||
@@ -95,13 +96,15 @@ abstract class AbstractSymbolLightClassesTestBase(
|
||||
project: Project
|
||||
): String
|
||||
|
||||
private inline fun ignoreExceptionIfIgnoreFirPresent(module: TestModule, action: () -> Unit) {
|
||||
private inline fun ignoreExceptionIfIgnoreDirectivePresent(module: TestModule, action: () -> Unit) {
|
||||
try {
|
||||
action()
|
||||
} catch (e: Throwable) {
|
||||
if (Directives.IGNORE_FIR in module.directives) {
|
||||
val directives = module.directives
|
||||
if (Directives.IGNORE_FIR in directives || stopIfCompilationErrorDirectivePresent && Directives.IGNORE_LIBRARY_EXCEPTIONS in directives) {
|
||||
return
|
||||
}
|
||||
|
||||
throw e
|
||||
}
|
||||
}
|
||||
@@ -114,10 +117,19 @@ abstract class AbstractSymbolLightClassesTestBase(
|
||||
testServices.assertions.assertEqualsToFile(path, actual)
|
||||
}
|
||||
|
||||
private fun removeIgnoreFir(module: TestModule) {
|
||||
if (Directives.IGNORE_FIR in module.directives) {
|
||||
error("Test is passing. Please, remove `// ${Directives.IGNORE_FIR.name}` directive")
|
||||
private fun removeIgnoreDirectives(module: TestModule) {
|
||||
val directives = module.directives
|
||||
if (Directives.IGNORE_FIR in directives) {
|
||||
throwTestIsPassingException(Directives.IGNORE_FIR)
|
||||
}
|
||||
|
||||
if (stopIfCompilationErrorDirectivePresent && Directives.IGNORE_LIBRARY_EXCEPTIONS in directives) {
|
||||
throwTestIsPassingException(Directives.IGNORE_LIBRARY_EXCEPTIONS)
|
||||
}
|
||||
}
|
||||
|
||||
private fun throwTestIsPassingException(directive: Directive): Nothing {
|
||||
error("Test is passing. Please, remove `// ${directive.name}` directive")
|
||||
}
|
||||
|
||||
protected fun findLightClass(fqname: String, project: Project): PsiClass? {
|
||||
@@ -183,5 +195,9 @@ abstract class AbstractSymbolLightClassesTestBase(
|
||||
description = "Ignore the test for Symbol FIR-based implementation of LC",
|
||||
applicability = DirectiveApplicability.Global
|
||||
)
|
||||
|
||||
val IGNORE_LIBRARY_EXCEPTIONS by stringDirective(
|
||||
description = "Ignore the test for decompiled-based implementation of LC"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+6
@@ -186,6 +186,12 @@ public class SymbolLightClassesByFqNameForLibraryTestGenerated extends AbstractS
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/InlineReified.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("InvalidJavaIdentifierAsAnnotationArgument.kt")
|
||||
public void testInvalidJavaIdentifierAsAnnotationArgument() throws Exception {
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/InvalidJavaIdentifierAsAnnotationArgument.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("JavaBetween.kt")
|
||||
public void testJavaBetween() throws Exception {
|
||||
|
||||
+6
@@ -186,6 +186,12 @@ public class SymbolLightClassesEqualityByFqNameForLibraryTestGenerated extends A
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/InlineReified.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("InvalidJavaIdentifierAsAnnotationArgument.kt")
|
||||
public void testInvalidJavaIdentifierAsAnnotationArgument() throws Exception {
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/InvalidJavaIdentifierAsAnnotationArgument.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("JavaBetween.kt")
|
||||
public void testJavaBetween() throws Exception {
|
||||
|
||||
+6
@@ -186,6 +186,12 @@ public class SymbolLightClassesParentingByFqNameForLibraryTestGenerated extends
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/InlineReified.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("InvalidJavaIdentifierAsAnnotationArgument.kt")
|
||||
public void testInvalidJavaIdentifierAsAnnotationArgument() throws Exception {
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/InvalidJavaIdentifierAsAnnotationArgument.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("JavaBetween.kt")
|
||||
public void testJavaBetween() throws Exception {
|
||||
|
||||
+6
@@ -186,6 +186,12 @@ public class SymbolLightClassesByFqNameForSourceTestGenerated extends AbstractSy
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/InlineReified.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("InvalidJavaIdentifierAsAnnotationArgument.kt")
|
||||
public void testInvalidJavaIdentifierAsAnnotationArgument() throws Exception {
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/InvalidJavaIdentifierAsAnnotationArgument.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("JavaBetween.kt")
|
||||
public void testJavaBetween() throws Exception {
|
||||
|
||||
+6
@@ -186,6 +186,12 @@ public class SymbolLightClassesEqualityByFqNameForSourceTestGenerated extends Ab
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/InlineReified.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("InvalidJavaIdentifierAsAnnotationArgument.kt")
|
||||
public void testInvalidJavaIdentifierAsAnnotationArgument() throws Exception {
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/InvalidJavaIdentifierAsAnnotationArgument.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("JavaBetween.kt")
|
||||
public void testJavaBetween() throws Exception {
|
||||
|
||||
+6
@@ -186,6 +186,12 @@ public class SymbolLightClassesParentingByFqNameForSourceTestGenerated extends A
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/InlineReified.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("InvalidJavaIdentifierAsAnnotationArgument.kt")
|
||||
public void testInvalidJavaIdentifierAsAnnotationArgument() throws Exception {
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/InvalidJavaIdentifierAsAnnotationArgument.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("JavaBetween.kt")
|
||||
public void testJavaBetween() throws Exception {
|
||||
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
@Sized(value = Size.3x3)
|
||||
public final class Big /* Big*/ {
|
||||
public Big();// .ctor()
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
@Sized(value = ?)
|
||||
public final class Big /* Big*/ {
|
||||
public Big();// .ctor()
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// Big
|
||||
enum class Size { `2x2`, `3x3` }
|
||||
annotation class Sized(val value: Size)
|
||||
|
||||
@Sized(Size.`3x3`)
|
||||
class Big
|
||||
|
||||
// IGNORE_LIBRARY_EXCEPTIONS: KT-57328
|
||||
+5
@@ -164,6 +164,11 @@ public class CompilerLightClassTestGenerated extends AbstractCompilerLightClassT
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/InlineReified.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InvalidJavaIdentifierAsAnnotationArgument.kt")
|
||||
public void testInvalidJavaIdentifierAsAnnotationArgument() throws Exception {
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/InvalidJavaIdentifierAsAnnotationArgument.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("JavaBetween.kt")
|
||||
public void testJavaBetween() throws Exception {
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/JavaBetween.kt");
|
||||
|
||||
Reference in New Issue
Block a user