Kapt: Don't create KDocCommentKeeper when not needed
Previously, even if `keepKdocComments=false`, we would still create the
KDocCommentKeeper object unnecessarily.
This commit makes sure we create the object only if
`keepKdocComments=true`.
Bug: Clean-up after commit e252171 for KT-43593
Test: Existing tests
This commit is contained in:
committed by
nataliya.valtman
parent
0a72e16451
commit
592c285198
@@ -150,7 +150,9 @@ open class KaptContext(val options: KaptOptions, val withJdk: Boolean, val logge
|
|||||||
}
|
}
|
||||||
|
|
||||||
compiler = JavaCompiler.instance(context) as KaptJavaCompiler
|
compiler = JavaCompiler.instance(context) as KaptJavaCompiler
|
||||||
compiler.keepComments = true
|
if (options.flags[KaptFlag.KEEP_KDOC_COMMENTS_IN_STUBS]) {
|
||||||
|
compiler.keepComments = true
|
||||||
|
}
|
||||||
|
|
||||||
ClassReader.instance(context).saveParameterNames = true
|
ClassReader.instance(context).saveParameterNames = true
|
||||||
|
|
||||||
|
|||||||
+9
-19
@@ -130,7 +130,7 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati
|
|||||||
|
|
||||||
private val signatureParser = SignatureParser(treeMaker)
|
private val signatureParser = SignatureParser(treeMaker)
|
||||||
|
|
||||||
private val kdocCommentKeeper = KDocCommentKeeper(kaptContext)
|
private val kdocCommentKeeper = if (keepKdocComments) KDocCommentKeeper(kaptContext) else null
|
||||||
|
|
||||||
private val importsFromRoot by lazy(::collectImportsFromRootPackage)
|
private val importsFromRoot by lazy(::collectImportsFromRootPackage)
|
||||||
|
|
||||||
@@ -209,7 +209,9 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati
|
|||||||
val classes = JavacList.of<JCTree>(classDeclaration)
|
val classes = JavacList.of<JCTree>(classDeclaration)
|
||||||
|
|
||||||
val topLevel = treeMaker.TopLevelJava9Aware(packageClause, nonEmptyImports + classes)
|
val topLevel = treeMaker.TopLevelJava9Aware(packageClause, nonEmptyImports + classes)
|
||||||
topLevel.docComments = kdocCommentKeeper.getDocTable(topLevel)
|
if (kdocCommentKeeper != null) {
|
||||||
|
topLevel.docComments = kdocCommentKeeper.getDocTable(topLevel)
|
||||||
|
}
|
||||||
|
|
||||||
KaptJavaFileObject(topLevel, classDeclaration).apply {
|
KaptJavaFileObject(topLevel, classDeclaration).apply {
|
||||||
topLevel.sourcefile = this
|
topLevel.sourcefile = this
|
||||||
@@ -440,11 +442,7 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati
|
|||||||
superTypes.superClass,
|
superTypes.superClass,
|
||||||
superTypes.interfaces,
|
superTypes.interfaces,
|
||||||
enumValues + sortedFields + sortedMethods + nestedClasses
|
enumValues + sortedFields + sortedMethods + nestedClasses
|
||||||
).also {
|
).keepKdocCommentsIfNecessary(clazz)
|
||||||
if (keepKdocComments) {
|
|
||||||
it.keepKdocComments(clazz)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class MemberData(val name: String, val descriptor: String, val position: KotlinPosition?)
|
private class MemberData(val name: String, val descriptor: String, val position: KotlinPosition?)
|
||||||
@@ -734,11 +732,7 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati
|
|||||||
lineMappings.registerField(containingClass, field)
|
lineMappings.registerField(containingClass, field)
|
||||||
|
|
||||||
val initializer = explicitInitializer ?: convertPropertyInitializer(containingClass, field)
|
val initializer = explicitInitializer ?: convertPropertyInitializer(containingClass, field)
|
||||||
return treeMaker.VarDef(modifiers, treeMaker.name(name), typeExpression, initializer).also {
|
return treeMaker.VarDef(modifiers, treeMaker.name(name), typeExpression, initializer).keepKdocCommentsIfNecessary(field)
|
||||||
if (keepKdocComments) {
|
|
||||||
it.keepKdocComments(field)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun convertPropertyInitializer(containingClass: ClassNode, field: FieldNode): JCExpression? {
|
private fun convertPropertyInitializer(containingClass: ClassNode, field: FieldNode): JCExpression? {
|
||||||
@@ -986,11 +980,7 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati
|
|||||||
modifiers, treeMaker.name(name), returnType, genericSignature.typeParameters,
|
modifiers, treeMaker.name(name), returnType, genericSignature.typeParameters,
|
||||||
genericSignature.parameterTypes, genericSignature.exceptionTypes,
|
genericSignature.parameterTypes, genericSignature.exceptionTypes,
|
||||||
body, defaultValue
|
body, defaultValue
|
||||||
).keepSignature(lineMappings, method).also {
|
).keepSignature(lineMappings, method).keepKdocCommentsIfNecessary(method)
|
||||||
if (keepKdocComments) {
|
|
||||||
it.keepKdocComments(method)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isIgnored(annotations: List<AnnotationNode>?): Boolean {
|
private fun isIgnored(annotations: List<AnnotationNode>?): Boolean {
|
||||||
@@ -1455,8 +1445,8 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati
|
|||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun <T : JCTree> T.keepKdocComments(node: Any): T {
|
private fun <T : JCTree> T.keepKdocCommentsIfNecessary(node: Any): T {
|
||||||
kdocCommentKeeper.saveKDocComment(this, node)
|
kdocCommentKeeper?.saveKDocComment(this, node)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user