Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report INNER modifier for class descriptors #232

Merged
merged 1 commit into from
Jan 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@ class JavaModifierProcessor : AbstractTestProcessor() {
}

override fun process(resolver: Resolver) {
val symbol = resolver.getSymbolsWithAnnotation("Test").single() as KSClassDeclaration
symbol.superTypes.single().resolve()!!.declaration.accept(ModifierVisitor(), Unit)
resolver.getSymbolsWithAnnotation("Test")
.map {
it as KSClassDeclaration
}
.forEach {
it.superTypes.single().resolve().declaration.accept(ModifierVisitor(), Unit)
}
}

inner class ModifierVisitor : KSTopDownVisitor<Unit, Unit>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ class KSClassDeclarationDescriptorImpl private constructor(val descriptor: Class
if (descriptor.kind == KtClassKind.ANNOTATION_CLASS) {
modifiers.add(Modifier.ANNOTATION)
}
if (descriptor.isInner) {
modifiers.add(Modifier.INNER)
}
modifiers
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,12 @@ abstract class AbstractKotlinKSPTest : KotlinBaseTest<AbstractKotlinKSPTest.KspT
dependencies: List<File>,
testProcessor: AbstractTestProcessor?) {
val moduleRoot = module.rootDir
module.writeJavaFiles(testFiles)
val hasJavaSources = testFiles.any {
it.isJavaFile()
}
if (hasJavaSources) {
module.writeJavaFiles(testFiles)
}
val configuration = createConfiguration(
ConfigurationKind.NO_KOTLIN_REFLECT,
TestJdkKind.FULL_JDK_9,
Expand Down Expand Up @@ -140,6 +145,23 @@ abstract class AbstractKotlinKSPTest : KotlinBaseTest<AbstractKotlinKSPTest.KspT
GenerationUtils.compileFiles(moduleFiles.psiFiles, environment, ClassBuilderFactories.TEST)
} else {
GenerationUtils.compileFilesTo(moduleFiles.psiFiles, environment, outDir)
if (hasJavaSources) {
// need to compile java sources as well
val javaOutDir = module.rootDir.resolve("javaOut")
val classpath = (dependencies + KotlinTestUtils.getAnnotationsJar() + module.outDir)
.joinToString(":") { it.absolutePath }
val options = listOf(
"-classpath", classpath,
"-d", javaOutDir.absolutePath
)
val javaFiles = module.javaSrcDir.listFilesRecursively()
KotlinTestUtils.compileJavaFiles(
javaFiles,
options
)
// merge java outputs into module's out dir
javaOutDir.copyRecursively(target = module.outDir, overwrite = false)
}
}
}

Expand Down Expand Up @@ -187,6 +209,14 @@ abstract class AbstractKotlinKSPTest : KotlinBaseTest<AbstractKotlinKSPTest.KspT
private val TestModule.outDir:File
get() = File(rootDir, "out")

private fun KspTestFile.isJavaFile() = name.endsWith(".java")

private fun File.listFilesRecursively(): List<File> = if (!this.exists()) {
emptyList()
} else {
this.walkTopDown().filter { it.isFile }.toList()
}

/**
* TestFile class for KSP where we can also keep a reference to the [TestModule]
*/
Expand Down
57 changes: 57 additions & 0 deletions compiler-plugin/testData/api/javaModifiers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,35 @@
// staticStr: PRIVATE
// s1: FINAL JAVA_TRANSIENT
// i1: PROTECTED JAVA_STATIC JAVA_VOLATILE
// NestedC: PUBLIC JAVA_STATIC
// InnerC: PUBLIC
// intFun: JAVA_SYNCHRONIZED JAVA_DEFAULT
// foo: ABSTRACT JAVA_STRICT
// OuterJavaClass: PUBLIC
// InnerJavaClass: PUBLIC
// NestedJavaClass: PUBLIC JAVA_STATIC
// OuterKotlinClass: OPEN
// InnerKotlinClass: INNER
// NestedKotlinClass: OPEN
// DependencyOuterJavaClass: OPEN PUBLIC
// DependencyNestedJavaClass: OPEN PUBLIC
// DependencyInnerJavaClass: OPEN PUBLIC INNER
// DependencyOuterKotlinClass: OPEN PUBLIC
// DependencyInnerKotlinClass: FINAL PUBLIC INNER
// DependencyNestedKotlinClass: OPEN PUBLIC
// END
// MODULE: module1
// FILE: DependencyOuterJavaClass.java
public class DependencyOuterJavaClass {
public class DependencyInnerJavaClass {}
public static class DependencyNestedJavaClass {}
}
// FILE: DependencyOuterKotlinClass.kt
open class DependencyOuterKotlinClass {
inner class DependencyInnerKotlinClass
open class DependencyNestedKotlinClass
}
// MODULE: main(module1)
// FILE: a.kt
annotation class Test

Expand All @@ -32,6 +58,18 @@ class Foo : C() {

}

@Test
class Bar : OuterJavaClass()

@Test
class Baz : OuterKotlinClass()

@Test
class JavaDependency : DependencyOuterJavaClass()

@Test
class KotlinDependency : DependencyOuterKotlinClass()

// FILE: C.java

public abstract class C {
Expand All @@ -47,4 +85,23 @@ public abstract class C {
}

abstract strictfp void foo() {}

public static class NestedC {

}

public class InnerC {

}
}

// FILE: OuterJavaClass.java
public class OuterJavaClass {
public class InnerJavaClass {}
public static class NestedJavaClass {}
}
// FILE: OuterKotlinClass.kt
open class OuterKotlinClass {
inner class InnerKotlinClass
open class NestedKotlinClass
}