From d30dbf25b5f7d31169c916b1fe09e45ba5c57840 Mon Sep 17 00:00:00 2001 From: Yan Zhulanow Date: Fri, 17 Feb 2017 19:15:21 +0300 Subject: [PATCH] Kapt1: Allow to use spaces in the collected identifiers (KT-12769) --- .../annotation/AnnotationCollectorExtension.kt | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/plugins/annotation-collector/src/org/jetbrains/kotlin/annotation/AnnotationCollectorExtension.kt b/plugins/annotation-collector/src/org/jetbrains/kotlin/annotation/AnnotationCollectorExtension.kt index c35d6bda52b..69787e648af 100644 --- a/plugins/annotation-collector/src/org/jetbrains/kotlin/annotation/AnnotationCollectorExtension.kt +++ b/plugins/annotation-collector/src/org/jetbrains/kotlin/annotation/AnnotationCollectorExtension.kt @@ -170,6 +170,8 @@ abstract class AnnotationCollectorExtensionBase(val supportInheritedAnnotations: } private fun recordClass(packageName: String, className: String) { + if (!isValidName(packageName) || !isValidName(className)) return + val packageNameId = if (!packageName.isEmpty()) shortenedPackageNameCache.save(packageName, writer) else null @@ -180,17 +182,23 @@ abstract class AnnotationCollectorExtensionBase(val supportInheritedAnnotations: private fun recordAnnotation(name: String?, type: String, annotationDesc: String) { val annotationFqName = Type.getType(annotationDesc).className - if (!isAnnotationHandled(annotationFqName)) return + if (!isAnnotationHandled(annotationFqName) || !isValidName(annotationFqName)) return + + if (name != null && !isValidName(name)) return try { - val annotationId = shortenedAnnotationCache.save(annotationFqName, writer) val packageName = this.currentPackageName + if (!isValidName(packageName)) return + + val className = this.currentClassSimpleName + if (!isValidName(className)) return + + val annotationId = shortenedAnnotationCache.save(annotationFqName, writer) val packageNameId = if (!packageName.isEmpty()) shortenedPackageNameCache.save(packageName, writer) else null - val className = this.currentClassSimpleName val outputClassName = getOutputClassName(packageNameId, className) val elementName = if (name != null) " $name" else "" @@ -201,6 +209,10 @@ abstract class AnnotationCollectorExtensionBase(val supportInheritedAnnotations: } } + private fun isValidName(name: String): Boolean { + return ' ' !in name + } + private fun getOutputClassName(packageNameId: String?, className: String): String { return if (packageNameId == null) className else "$packageNameId/$className" }