Pass reader in constructor to KotlinAnnotationProvider
This commit is contained in:
+2
-2
@@ -97,10 +97,10 @@ public abstract class AnnotationProcessorWrapper(
|
|||||||
val annotationsFilePath = processingEnv.options[KAPT_ANNOTATION_OPTION]
|
val annotationsFilePath = processingEnv.options[KAPT_ANNOTATION_OPTION]
|
||||||
val annotationsFile = if (annotationsFilePath != null) File(annotationsFilePath) else null
|
val annotationsFile = if (annotationsFilePath != null) File(annotationsFilePath) else null
|
||||||
kotlinAnnotationsProvider = if (annotationsFile != null && annotationsFile.exists()) {
|
kotlinAnnotationsProvider = if (annotationsFile != null && annotationsFile.exists()) {
|
||||||
FileKotlinAnnotationProvider(annotationsFile)
|
KotlinAnnotationProvider(annotationsFile)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
EmptyKotlinAnnotationsProvider()
|
KotlinAnnotationProvider()
|
||||||
}
|
}
|
||||||
|
|
||||||
processor.init(processingEnv)
|
processor.init(processingEnv)
|
||||||
|
|||||||
+5
-15
@@ -19,9 +19,8 @@ package org.jetbrains.kotlin.annotation
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.Reader
|
import java.io.Reader
|
||||||
import java.io.StringReader
|
import java.io.StringReader
|
||||||
import javax.tools.FileObject
|
|
||||||
|
|
||||||
public abstract class KotlinAnnotationProvider {
|
class KotlinAnnotationProvider(private val annotationsReader: Reader) {
|
||||||
|
|
||||||
private companion object {
|
private companion object {
|
||||||
val ANNOTATED_CLASS = "c"
|
val ANNOTATED_CLASS = "c"
|
||||||
@@ -34,6 +33,9 @@ public abstract class KotlinAnnotationProvider {
|
|||||||
val CLASS_DECLARATION = "d"
|
val CLASS_DECLARATION = "d"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constructor(annotationsFile: File) : this(annotationsFile.reader().buffered())
|
||||||
|
constructor() : this(StringReader(""))
|
||||||
|
|
||||||
public val annotatedKotlinElements: Map<String, Set<AnnotatedElementDescriptor>> by lazy {
|
public val annotatedKotlinElements: Map<String, Set<AnnotatedElementDescriptor>> by lazy {
|
||||||
readAnnotations()
|
readAnnotations()
|
||||||
}
|
}
|
||||||
@@ -46,8 +48,6 @@ public abstract class KotlinAnnotationProvider {
|
|||||||
public val supportInheritedAnnotations: Boolean
|
public val supportInheritedAnnotations: Boolean
|
||||||
get() = kotlinClassesInternal.isNotEmpty()
|
get() = kotlinClassesInternal.isNotEmpty()
|
||||||
|
|
||||||
protected abstract val serializedAnnotations: Reader
|
|
||||||
|
|
||||||
private fun readAnnotations(): MutableMap<String, MutableSet<AnnotatedElementDescriptor>> {
|
private fun readAnnotations(): MutableMap<String, MutableSet<AnnotatedElementDescriptor>> {
|
||||||
val shortenedAnnotationCache = hashMapOf<String, String>()
|
val shortenedAnnotationCache = hashMapOf<String, String>()
|
||||||
val shortenedPackageNameCache = hashMapOf<String, String>()
|
val shortenedPackageNameCache = hashMapOf<String, String>()
|
||||||
@@ -65,7 +65,7 @@ public abstract class KotlinAnnotationProvider {
|
|||||||
|
|
||||||
val annotatedKotlinElements: MutableMap<String, MutableSet<AnnotatedElementDescriptor>> = hashMapOf()
|
val annotatedKotlinElements: MutableMap<String, MutableSet<AnnotatedElementDescriptor>> = hashMapOf()
|
||||||
|
|
||||||
serializedAnnotations.useLines { lines ->
|
annotationsReader.useLines { lines ->
|
||||||
for (line in lines) {
|
for (line in lines) {
|
||||||
if (line.isEmpty()) continue
|
if (line.isEmpty()) continue
|
||||||
val lineParts = line.split(' ')
|
val lineParts = line.split(' ')
|
||||||
@@ -116,14 +116,4 @@ public abstract class KotlinAnnotationProvider {
|
|||||||
val id = lineParts[2]
|
val id = lineParts[2]
|
||||||
cache.put(id, name)
|
cache.put(id, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public class FileKotlinAnnotationProvider(val annotationsFile: File): KotlinAnnotationProvider() {
|
|
||||||
override val serializedAnnotations: Reader
|
|
||||||
get() = annotationsFile.reader().buffered()
|
|
||||||
}
|
|
||||||
|
|
||||||
public class EmptyKotlinAnnotationsProvider : KotlinAnnotationProvider() {
|
|
||||||
override val serializedAnnotations = StringReader("")
|
|
||||||
}
|
}
|
||||||
+1
-1
@@ -53,7 +53,7 @@ public class AnnotationListParseTest {
|
|||||||
|
|
||||||
assertTrue(annotationsFile.absolutePath + " does not exist.", annotationsFile.exists())
|
assertTrue(annotationsFile.absolutePath + " does not exist.", annotationsFile.exists())
|
||||||
|
|
||||||
val annotationProvider = FileKotlinAnnotationProvider(annotationsFile)
|
val annotationProvider = KotlinAnnotationProvider(annotationsFile)
|
||||||
val parsedAnnotations = annotationProvider.annotatedKotlinElements
|
val parsedAnnotations = annotationProvider.annotatedKotlinElements
|
||||||
|
|
||||||
val actualAnnotations = StringBuilder()
|
val actualAnnotations = StringBuilder()
|
||||||
|
|||||||
Reference in New Issue
Block a user