[FE] Properly parse java class name from sources if java class has annotations
^KT-56847 Fixed
This commit is contained in:
committed by
Space Team
parent
5455942859
commit
331cc1465a
+6
@@ -1386,6 +1386,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
|||||||
runTest("compiler/testData/diagnostics/tests/annotations/invalidTypesInAnnotationConstructor.kt");
|
runTest("compiler/testData/diagnostics/tests/annotations/invalidTypesInAnnotationConstructor.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("javaAnnotationAndJavaClassWithIt.kt")
|
||||||
|
public void testJavaAnnotationAndJavaClassWithIt() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/annotations/javaAnnotationAndJavaClassWithIt.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("JavaAnnotationConstructors.kt")
|
@TestMetadata("JavaAnnotationConstructors.kt")
|
||||||
public void testJavaAnnotationConstructors() throws Exception {
|
public void testJavaAnnotationConstructors() throws Exception {
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ class SingleJavaFileRootsIndex(private val roots: List<JavaRoot>) {
|
|||||||
start(String(file.contentsToByteArray()))
|
start(String(file.contentsToByteArray()))
|
||||||
}
|
}
|
||||||
private var braceBalance = 0
|
private var braceBalance = 0
|
||||||
|
private var parenthesisBalance = 0
|
||||||
|
|
||||||
private fun at(type: IElementType): Boolean = lexer.tokenType == type
|
private fun at(type: IElementType): Boolean = lexer.tokenType == type
|
||||||
|
|
||||||
@@ -67,6 +68,8 @@ class SingleJavaFileRootsIndex(private val roots: List<JavaRoot>) {
|
|||||||
when {
|
when {
|
||||||
at(ElementType.LBRACE) -> braceBalance++
|
at(ElementType.LBRACE) -> braceBalance++
|
||||||
at(ElementType.RBRACE) -> braceBalance--
|
at(ElementType.RBRACE) -> braceBalance--
|
||||||
|
at(ElementType.LPARENTH) -> parenthesisBalance++
|
||||||
|
at(ElementType.RPARENTH) -> parenthesisBalance--
|
||||||
}
|
}
|
||||||
lexer.advance()
|
lexer.advance()
|
||||||
}
|
}
|
||||||
@@ -74,7 +77,7 @@ class SingleJavaFileRootsIndex(private val roots: List<JavaRoot>) {
|
|||||||
private fun tokenText(): String = lexer.tokenText
|
private fun tokenText(): String = lexer.tokenText
|
||||||
|
|
||||||
private fun atClass(): Boolean =
|
private fun atClass(): Boolean =
|
||||||
braceBalance == 0 && (lexer.tokenType in CLASS_KEYWORDS || atRecord())
|
braceBalance == 0 && parenthesisBalance == 0 && (lexer.tokenType in CLASS_KEYWORDS || atRecord())
|
||||||
|
|
||||||
private fun atRecord(): Boolean {
|
private fun atRecord(): Boolean {
|
||||||
// Note that the soft keyword "record" is lexed as IDENTIFIER instead of RECORD_KEYWORD.
|
// Note that the soft keyword "record" is lexed as IDENTIFIER instead of RECORD_KEYWORD.
|
||||||
@@ -112,7 +115,6 @@ class SingleJavaFileRootsIndex(private val roots: List<JavaRoot>) {
|
|||||||
if (end()) break
|
if (end()) break
|
||||||
result.add(ClassId(packageFqName, Name.identifier(tokenText())))
|
result.add(ClassId(packageFqName, Name.identifier(tokenText())))
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
@@ -1392,6 +1392,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
|||||||
runTest("compiler/testData/diagnostics/tests/annotations/invalidTypesInAnnotationConstructor.kt");
|
runTest("compiler/testData/diagnostics/tests/annotations/invalidTypesInAnnotationConstructor.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("javaAnnotationAndJavaClassWithIt.kt")
|
||||||
|
public void testJavaAnnotationAndJavaClassWithIt() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/annotations/javaAnnotationAndJavaClassWithIt.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("JavaAnnotationConstructors.kt")
|
@TestMetadata("JavaAnnotationConstructors.kt")
|
||||||
public void testJavaAnnotationConstructors() throws Exception {
|
public void testJavaAnnotationConstructors() throws Exception {
|
||||||
|
|||||||
+6
@@ -1386,6 +1386,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
|||||||
runTest("compiler/testData/diagnostics/tests/annotations/invalidTypesInAnnotationConstructor.kt");
|
runTest("compiler/testData/diagnostics/tests/annotations/invalidTypesInAnnotationConstructor.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("javaAnnotationAndJavaClassWithIt.kt")
|
||||||
|
public void testJavaAnnotationAndJavaClassWithIt() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/annotations/javaAnnotationAndJavaClassWithIt.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("JavaAnnotationConstructors.kt")
|
@TestMetadata("JavaAnnotationConstructors.kt")
|
||||||
public void testJavaAnnotationConstructors() throws Exception {
|
public void testJavaAnnotationConstructors() throws Exception {
|
||||||
|
|||||||
+28
@@ -0,0 +1,28 @@
|
|||||||
|
// FIR_IDENTICAL
|
||||||
|
// ISSUE: KT-56847
|
||||||
|
// FILE: foo/TestTarget.java
|
||||||
|
package foo;
|
||||||
|
|
||||||
|
@AnnotationWithArg(String.class)
|
||||||
|
@Ann
|
||||||
|
public final class TestTarget {}
|
||||||
|
|
||||||
|
// FILE: foo/Ann.java
|
||||||
|
package foo;
|
||||||
|
|
||||||
|
public @interface Ann {}
|
||||||
|
|
||||||
|
// FILE: foo/AnnotationWithArg.java
|
||||||
|
package foo;
|
||||||
|
|
||||||
|
public @interface AnnotationWithArg {
|
||||||
|
Class<?> value();
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: foo/AnotherTarget.kt
|
||||||
|
package foo
|
||||||
|
|
||||||
|
@Ann
|
||||||
|
class AnotherTarget {
|
||||||
|
fun hello() {}
|
||||||
|
}
|
||||||
Generated
+6
@@ -1392,6 +1392,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
|||||||
runTest("compiler/testData/diagnostics/tests/annotations/invalidTypesInAnnotationConstructor.kt");
|
runTest("compiler/testData/diagnostics/tests/annotations/invalidTypesInAnnotationConstructor.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("javaAnnotationAndJavaClassWithIt.kt")
|
||||||
|
public void testJavaAnnotationAndJavaClassWithIt() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/annotations/javaAnnotationAndJavaClassWithIt.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("JavaAnnotationConstructors.kt")
|
@TestMetadata("JavaAnnotationConstructors.kt")
|
||||||
public void testJavaAnnotationConstructors() throws Exception {
|
public void testJavaAnnotationConstructors() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user