Skip to content

Commit

Permalink
Remove deprecated APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
ting-yuan committed May 26, 2021
1 parent a9e8151 commit d89c149
Show file tree
Hide file tree
Showing 23 changed files with 69 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,6 @@ import com.google.devtools.ksp.symbol.KSAnnotated
* their own error handling.
*/
interface SymbolProcessor {
/**
* Called by Kotlin Symbol Processing to initialize the processor.
*
* @param options passed from command line, Gradle, etc.
* @param kotlinVersion language version of compilation environment.
* @param codeGenerator creates managed files.
*/
@Deprecated("Implement the SymbolProcessorProvider interface instead. This warning will become an error in beta.")
fun init(options: Map<String, String>, kotlinVersion: KotlinVersion, codeGenerator: CodeGenerator, logger: KSPLogger) {}

/**
* Called by Kotlin Symbol Processing to run the processing task.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,10 @@ class KotlinSymbolProcessingExtension(
val classLoader = URLClassLoader(processingClasspath.map { it.toURI().toURL() }.toTypedArray(), javaClass.classLoader)

ServiceLoaderLite.loadImplementations(SymbolProcessorProvider::class.java, classLoader)
.plus(loadProvidersForLegacySymbolProcessors(classLoader))
}
}
return providers
}

private fun loadProvidersForLegacySymbolProcessors(classLoader: URLClassLoader): List<SymbolProcessorProvider> {
return ServiceLoaderLite
.loadImplementations(SymbolProcessor::class.java, classLoader)
.map(::LegacySymbolProcessorAdapter)
}
}

abstract class AbstractKotlinSymbolProcessingExtension(val options: KspOptions, val logger: KSPLogger, val testMode: Boolean) :
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ class InitPlusProviderIT {

JarFile(artifact).use { jarFile ->
Assert.assertTrue(jarFile.getEntry("TestProcessor.log").size > 0)
Assert.assertTrue(jarFile.getEntry("TestProcessorInit.log").size > 0)
Assert.assertTrue(jarFile.getEntry("HelloFromInit.class").size > 0)
Assert.assertTrue(jarFile.getEntry("HelloFromProvider.class").size > 0)
Assert.assertTrue(jarFile.getEntry("GeneratedFromInit.class").size > 0)
Assert.assertTrue(jarFile.getEntry("GeneratedFromProvider.class").size > 0)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import com.google.devtools.ksp.processing.CodeGenerator
import com.google.devtools.ksp.processing.Dependencies
import com.google.devtools.ksp.processing.KSPLogger
import com.google.devtools.ksp.processing.Resolver
import com.google.devtools.ksp.processing.SymbolProcessor
import com.google.devtools.ksp.processing.*
import com.google.devtools.ksp.symbol.*
import com.google.devtools.ksp.validate
import com.google.devtools.ksp.visitor.KSDefaultVisitor
Expand All @@ -16,7 +12,7 @@ class Validator : SymbolProcessor {
lateinit var logger: KSPLogger
var processed = false

override fun init(options: Map<String, String>, kotlinVersion: KotlinVersion, codeGenerator: CodeGenerator, logger: KSPLogger) {
fun init(options: Map<String, String>, kotlinVersion: KotlinVersion, codeGenerator: CodeGenerator, logger: KSPLogger) {
this.codeGenerator = codeGenerator
this.logger = logger
}
Expand Down Expand Up @@ -48,4 +44,12 @@ class Validator : SymbolProcessor {
}
}


class TestProcessorProvider : SymbolProcessorProvider {
override fun create(
env: SymbolProcessorEnvironment
): SymbolProcessor {
return Validator().apply {
init(env.options, env.kotlinVersion, env.codeGenerator, env.logger)
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TestProcessorProvider

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ repositories {

dependencies {
implementation(kotlin("stdlib"))
ksp(project(":init-processor"))
ksp(project(":provider-processor"))
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.example

import HelloFromInit
import HelloFromProvider

fun main() {
HelloFromInit().foo()
HelloFromProvider().foo()
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ErrorProcessor : SymbolProcessor {
var rounds = 0
lateinit var exception: String

override fun init(options: Map<String, String>, kotlinVersion: KotlinVersion, codeGenerator: CodeGenerator, logger: KSPLogger) {
fun init(options: Map<String, String>, kotlinVersion: KotlinVersion, codeGenerator: CodeGenerator, logger: KSPLogger) {
exception = if (options.containsKey("exception")) {
options["exception"]!!
} else {
Expand Down Expand Up @@ -54,4 +54,12 @@ class ErrorProcessor : SymbolProcessor {
}
}


class TestProcessorProvider : SymbolProcessorProvider {
override fun create(
env: SymbolProcessorEnvironment
): SymbolProcessor {
return ErrorProcessor().apply {
init(env.options, env.kotlinVersion, env.codeGenerator, env.logger)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class NormalProcessor : SymbolProcessor {
logger.error("NormalProcessor called error on $rounds")
}

override fun init(options: Map<String, String>, kotlinVersion: KotlinVersion, codeGenerator: CodeGenerator, logger: KSPLogger) {
fun init(options: Map<String, String>, kotlinVersion: KotlinVersion, codeGenerator: CodeGenerator, logger: KSPLogger) {
this.logger = logger
this.codeGenerator = codeGenerator
}
Expand All @@ -27,3 +27,12 @@ class NormalProcessor : SymbolProcessor {
}


class TestProcessorProvider2 : SymbolProcessorProvider {
override fun create(
env: SymbolProcessorEnvironment
): SymbolProcessor {
return NormalProcessor().apply {
init(env.options, env.kotlinVersion, env.codeGenerator, env.logger)
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
TestProcessorProvider
TestProcessorProvider2
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class TestProcessor : SymbolProcessor {
lateinit var logger: KSPLogger
var processed = false

override fun init(options: Map<String, String>, kotlinVersion: KotlinVersion, codeGenerator: CodeGenerator, logger: KSPLogger) {
fun init(options: Map<String, String>, kotlinVersion: KotlinVersion, codeGenerator: CodeGenerator, logger: KSPLogger) {
this.codeGenerator = codeGenerator
this.logger = logger
}
Expand Down Expand Up @@ -45,3 +45,13 @@ class TestProcessor : SymbolProcessor {
return emptyList()
}
}

class TestProcessorProvider : SymbolProcessorProvider {
override fun create(
env: SymbolProcessorEnvironment
): SymbolProcessor {
return TestProcessor().apply {
init(env.options, env.kotlinVersion, env.codeGenerator, env.logger)
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TestProcessorProvider
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class BuilderProcessor : SymbolProcessor {
lateinit var codeGenerator: CodeGenerator
lateinit var logger: KSPLogger

override fun init(options: Map<String, String>, kotlinVersion: KotlinVersion, codeGenerator: CodeGenerator, logger: KSPLogger) {
fun init(options: Map<String, String>, kotlinVersion: KotlinVersion, codeGenerator: CodeGenerator, logger: KSPLogger) {
this.codeGenerator = codeGenerator
this.logger = logger
}
Expand Down Expand Up @@ -74,3 +74,13 @@ class BuilderProcessor : SymbolProcessor {
}

}

class TestProcessorProvider : SymbolProcessorProvider {
override fun create(
env: SymbolProcessorEnvironment
): SymbolProcessor {
return BuilderProcessor().apply {
init(env.options, env.kotlinVersion, env.codeGenerator, env.logger)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class TestProcessor : SymbolProcessor {
file.appendText("$indent$s\n")
}

override fun init(options: Map<String, String>, kotlinVersion: KotlinVersion, codeGenerator: CodeGenerator, logger: KSPLogger) {
fun init(options: Map<String, String>, kotlinVersion: KotlinVersion, codeGenerator: CodeGenerator, logger: KSPLogger) {
this.codeGenerator = codeGenerator
file = codeGenerator.createNewFile(Dependencies(false), "", "TestProcessor", "log")
emit("TestProcessor: init($options)", "")
Expand Down Expand Up @@ -258,4 +258,12 @@ class TestProcessor : SymbolProcessor {

}


class TestProcessorProvider2 : SymbolProcessorProvider {
override fun create(
env: SymbolProcessorEnvironment
): SymbolProcessor {
return TestProcessor().apply {
init(env.options, env.kotlinVersion, env.codeGenerator, env.logger)
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
TestProcessorProvider
TestProcessorProvider2

0 comments on commit d89c149

Please sign in to comment.