forked from google/ksp
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Force resolve outermost class for Java nested classes.
This is a temporary workaround for google#1034
- Loading branch information
Showing
10 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
integration-tests/src/test/kotlin/com/google/devtools/ksp/test/JavaNestedClassIT.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.google.devtools.ksp.test | ||
|
||
import org.gradle.testkit.runner.GradleRunner | ||
import org.gradle.testkit.runner.TaskOutcome | ||
import org.junit.Assert | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class JavaNestedClassIT { | ||
@Rule | ||
@JvmField | ||
val project: TemporaryTestProject = TemporaryTestProject("javaNestedClass") | ||
|
||
@Test | ||
fun testJavaNestedClass() { | ||
|
||
val gradleRunner = GradleRunner.create().withProjectDir(project.root) | ||
|
||
val resultCleanBuild = gradleRunner.withArguments("clean", "build").build() | ||
Assert.assertEquals(TaskOutcome.SUCCESS, resultCleanBuild.task(":workload:build")?.outcome) | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
integration-tests/src/test/resources/javaNestedClass/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
plugins { | ||
kotlin("jvm") | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap/") | ||
} |
19 changes: 19 additions & 0 deletions
19
integration-tests/src/test/resources/javaNestedClass/settings.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
pluginManagement { | ||
val kotlinVersion: String by settings | ||
val kspVersion: String by settings | ||
val testRepo: String by settings | ||
plugins { | ||
id("com.google.devtools.ksp") version kspVersion | ||
kotlin("jvm") version kotlinVersion | ||
} | ||
repositories { | ||
maven(testRepo) | ||
gradlePluginPortal() | ||
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap/") | ||
} | ||
} | ||
|
||
rootProject.name = "javaNestedClass" | ||
|
||
include(":workload") | ||
include(":test-processor") |
25 changes: 25 additions & 0 deletions
25
integration-tests/src/test/resources/javaNestedClass/test-processor/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
val kspVersion: String by project | ||
val testRepo: String by project | ||
|
||
plugins { | ||
kotlin("jvm") | ||
} | ||
|
||
group = "com.example" | ||
version = "1.0-SNAPSHOT" | ||
|
||
repositories { | ||
maven(testRepo) | ||
mavenCentral() | ||
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap/") | ||
} | ||
|
||
dependencies { | ||
implementation(kotlin("stdlib")) | ||
implementation("com.squareup:javapoet:1.12.1") | ||
implementation("com.google.devtools.ksp:symbol-processing-api:$kspVersion") | ||
} | ||
|
||
sourceSets.main { | ||
java.srcDirs("src/main/kotlin") | ||
} |
24 changes: 24 additions & 0 deletions
24
...ts/src/test/resources/javaNestedClass/test-processor/src/main/kotlin/ValidateProcessor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import com.google.devtools.ksp.getClassDeclarationByName | ||
import com.google.devtools.ksp.processing.* | ||
import com.google.devtools.ksp.symbol.* | ||
import com.google.devtools.ksp.validate | ||
|
||
class ValidateProcessor(env: SymbolProcessorEnvironment) : SymbolProcessor { | ||
var logger: KSPLogger = env.logger | ||
|
||
override fun process(resolver: Resolver): List<KSAnnotated> { | ||
val javaClass = resolver.getClassDeclarationByName("com.example.JavaClass")!! | ||
if (!javaClass.validate()) { | ||
logger.error("Failed to validate $javaClass") | ||
} | ||
return emptyList() | ||
} | ||
} | ||
|
||
class ValidateProcessorProvider : SymbolProcessorProvider { | ||
override fun create( | ||
env: SymbolProcessorEnvironment | ||
): SymbolProcessor { | ||
return ValidateProcessor(env) | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...in/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ValidateProcessorProvider |
20 changes: 20 additions & 0 deletions
20
integration-tests/src/test/resources/javaNestedClass/workload/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
val testRepo: String by project | ||
|
||
plugins { | ||
id("com.google.devtools.ksp") | ||
kotlin("jvm") | ||
} | ||
|
||
version = "1.0-SNAPSHOT" | ||
|
||
repositories { | ||
maven(testRepo) | ||
mavenCentral() | ||
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap/") | ||
} | ||
|
||
dependencies { | ||
implementation(kotlin("stdlib")) | ||
implementation(project(":test-processor")) | ||
ksp(project(":test-processor")) | ||
} |
4 changes: 4 additions & 0 deletions
4
integration-tests/src/test/resources/javaNestedClass/workload/src/main/java/com/example/A.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.example | ||
|
||
fun main() { | ||
} |
12 changes: 12 additions & 0 deletions
12
...ests/src/test/resources/javaNestedClass/workload/src/main/java/com/example/JavaClass.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.example; | ||
|
||
public class JavaClass { | ||
|
||
public int b2; | ||
|
||
public ENUM e; | ||
|
||
public enum ENUM { | ||
R,G,B | ||
} | ||
} |