From 3340731c7167e73f5414ff2c38806df1ce30985b Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov Date: Fri, 15 Apr 2016 01:48:37 +0300 Subject: [PATCH] Read annotations during construction of KotlinAnnotationsProvider The rationale is to access kotlinClassesInternal and annotatedKotlinElementsInternal in any order --- .../annotation/KotlinAnnotationProvider.kt | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/libraries/tools/kotlin-annotation-processing/src/main/kotlin/org/jetbrains/kotlin/annotation/KotlinAnnotationProvider.kt b/libraries/tools/kotlin-annotation-processing/src/main/kotlin/org/jetbrains/kotlin/annotation/KotlinAnnotationProvider.kt index 6fc48cfea18..51e374e5487 100644 --- a/libraries/tools/kotlin-annotation-processing/src/main/kotlin/org/jetbrains/kotlin/annotation/KotlinAnnotationProvider.kt +++ b/libraries/tools/kotlin-annotation-processing/src/main/kotlin/org/jetbrains/kotlin/annotation/KotlinAnnotationProvider.kt @@ -36,19 +36,23 @@ class KotlinAnnotationProvider(private val annotationsReader: Reader) { constructor(annotationsFile: File) : this(annotationsFile.reader().buffered()) constructor() : this(StringReader("")) - public val annotatedKotlinElements: Map> by lazy { + private val kotlinClassesInternal = hashSetOf() + private val annotatedKotlinElementsInternal = hashMapOf>() + + init { readAnnotations() } - private val kotlinClassesInternal = hashSetOf() + val annotatedKotlinElements: Map> + get() = annotatedKotlinElementsInternal - public val kotlinClasses: Set + val kotlinClasses: Set get() = kotlinClassesInternal - public val supportInheritedAnnotations: Boolean + val supportInheritedAnnotations: Boolean get() = kotlinClassesInternal.isNotEmpty() - private fun readAnnotations(): MutableMap> { + private fun readAnnotations() { val shortenedAnnotationCache = hashMapOf() val shortenedPackageNameCache = hashMapOf() @@ -63,8 +67,6 @@ class KotlinAnnotationProvider(private val annotationsReader: Reader) { return shortenedValue + '.' + s.substring(id.length + 1) } - val annotatedKotlinElements: MutableMap> = hashMapOf() - annotationsReader.useLines { lines -> for (line in lines) { if (line.isEmpty()) continue @@ -84,7 +86,7 @@ class KotlinAnnotationProvider(private val annotationsReader: Reader) { val classFqName = expandClassName(lineParts[2]).replace('$', '.') val elementName = if (lineParts.size == 4) lineParts[3] else null - val set = annotatedKotlinElements.getOrPut(annotationName) { hashSetOf() } + val set = annotatedKotlinElementsInternal.getOrPut(annotationName) { hashSetOf() } set.add(when (type) { ANNOTATED_CLASS -> AnnotatedClassDescriptor(classFqName) ANNOTATED_FIELD -> { @@ -107,8 +109,6 @@ class KotlinAnnotationProvider(private val annotationsReader: Reader) { } } } - - return annotatedKotlinElements } private fun handleShortenedName(cache: MutableMap, lineParts: List) {