Skip to content

Commit

Permalink
Only initialize typeElementVisitors once. (#9316)
Browse files Browse the repository at this point in the history
* Only initialize typeElementVisitors once. Fixes micronaut-projects/micronaut-data#2197
  • Loading branch information
graemerocher authored May 26, 2023
1 parent f21a3cf commit b1ee26c
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ internal open class TypeElementSymbolProcessor(private val environment: SymbolPr
SymbolProcessor {

private lateinit var loadedVisitors: MutableList<LoadedVisitor>
private lateinit var typeElementVisitors: Collection<TypeElementVisitor<*, *>>
private var typeElementVisitors: Collection<TypeElementVisitor<*, *>>? = null
private lateinit var visitorContext: KotlinVisitorContext
private val processed: MutableSet<String> = mutableSetOf()

Expand Down Expand Up @@ -82,11 +82,12 @@ internal open class TypeElementSymbolProcessor(private val environment: SymbolPr
)
}

typeElementVisitors = findTypeElementVisitors()
loadedVisitors = ArrayList(typeElementVisitors.size)
visitorContext = KotlinVisitorContext(environment, resolver)

start()
if (typeElementVisitors == null) {
typeElementVisitors = findTypeElementVisitors()
loadedVisitors = ArrayList(typeElementVisitors!!.size)
visitorContext = KotlinVisitorContext(environment, resolver)
start()
}

if (loadedVisitors.isNotEmpty()) {

Expand Down Expand Up @@ -114,7 +115,7 @@ internal open class TypeElementSymbolProcessor(private val environment: SymbolPr
val className = typeElement.qualifiedName?.asString()
if (className != null && !processed.contains(className)) {
processed.add(className)

for (loadedVisitor in loadedVisitors) {
if (!loadedVisitor.matches(typeElement)) {
continue
Expand Down Expand Up @@ -158,7 +159,7 @@ internal open class TypeElementSymbolProcessor(private val environment: SymbolPr
}

private fun start() {
for (visitor in typeElementVisitors) {
for (visitor in typeElementVisitors!!) {
try {
loadedVisitors.add(
LoadedVisitor(
Expand Down

0 comments on commit b1ee26c

Please sign in to comment.