KT-33889: Do not use private non-API methods from JavacProcessingEnvironment

Avoid using JavacProcessingEnvironment.validImportStringToPattern method
because it has been removed in JDK9. This commit changes how we compute
pattern to match the class names, and it create instances of Pattern
manually by following spec for Processor.getSupportedAnnotationTypes().
Support for module prefix is not added yet.
This commit is contained in:
Ivan Gavrilovic
2019-09-23 16:47:21 +01:00
committed by Yan Zhulanow
parent 594f4a6f56
commit aaa00b0f6f
@@ -5,12 +5,12 @@
package org.jetbrains.kotlin.kapt3.base.incremental package org.jetbrains.kotlin.kapt3.base.incremental
import com.sun.tools.javac.processing.JavacProcessingEnvironment
import java.io.File import java.io.File
import java.io.ObjectInputStream import java.io.ObjectInputStream
import java.io.ObjectOutputStream import java.io.ObjectOutputStream
import java.io.Serializable import java.io.Serializable
import java.net.URI import java.net.URI
import java.util.regex.Pattern
class JavaClassCache() : Serializable { class JavaClassCache() : Serializable {
private var sourceCache = mutableMapOf<URI, SourceFileStructure>() private var sourceCache = mutableMapOf<URI, SourceFileStructure>()
@@ -130,7 +130,18 @@ class JavaClassCache() : Serializable {
* annotation processor. This search is not transitive. * annotation processor. This search is not transitive.
*/ */
fun invalidateEntriesAnnotatedWith(annotations: Set<String>): Set<File> { fun invalidateEntriesAnnotatedWith(annotations: Set<String>): Set<File> {
val patterns = annotations.map { JavacProcessingEnvironment.validImportStringToPattern(it) } val patterns: List<Pattern> = if ("*" in annotations) {
// optimize this case - create only one pattern
listOf(Pattern.compile(".*"))
} else {
annotations.map {
Pattern.compile(
// These are already valid import statements, otherwise run fails when loading the annotation processor.
// Handles structure; TypeName [.*] e.g. org.jetbrains.annotations.NotNull and org.jetbrains.annotations.*
it.replace(".", "\\.").replace("*", ".+")
)
}
}
val matchesAnyPattern = { name: String -> patterns.any { it.matcher(name).matches() } } val matchesAnyPattern = { name: String -> patterns.any { it.matcher(name).matches() } }
val toReprocess = mutableSetOf<URI>() val toReprocess = mutableSetOf<URI>()