Skip to content

Commit d6756de

Browse files
committed
♻️ refactor(reflection): simplify constant argument handling in ReflectionSymbolProcessor
- replace multiple filter and forEach calls with a single for loop and when expression - improve readability and maintainability of constant argument processing logic
1 parent d5c3581 commit d6756de

1 file changed

Lines changed: 13 additions & 15 deletions

File tree

surf-api-gradle-plugin/surf-api-processor/src/main/kotlin/dev/slne/surf/api/processor/reflection/ReflectionSymbolProcessor.kt

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@ import com.palantir.javapoet.TypeName
1313
import com.palantir.javapoet.WildcardTypeName
1414
import dev.slne.surf.api.processor.ClassNames
1515
import dev.slne.surf.api.processor.ShortClassNames
16+
import dev.slne.surf.api.processor.ShortClassNames.CONSTANT_BOOLEAN_ARGUMENT
17+
import dev.slne.surf.api.processor.ShortClassNames.CONSTANT_INT_ARGUMENT
18+
import dev.slne.surf.api.processor.ShortClassNames.CONSTANT_LONG_ARGUMENT
19+
import dev.slne.surf.api.processor.ShortClassNames.CONSTANT_STRING_ARGUMENT
1620
import dev.slne.surf.api.processor.reflection.emitter.ReflectionJavaEmitter
1721
import dev.slne.surf.api.processor.reflection.exception.ReflectionProcessorException
1822
import dev.slne.surf.api.processor.reflection.model.*
23+
import dev.slne.surf.api.processor.reflection.model.ConstantArgument.*
1924
import dev.slne.surf.api.processor.util.*
2025
import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap
2126
import org.jetbrains.kotlin.name.FqNameUnsafe
@@ -342,21 +347,14 @@ class ReflectionSymbolProcessor(environment: SymbolProcessorEnvironment) : Symbo
342347
private fun KSFunctionDeclaration.constantArguments(): List<ConstantArgument> {
343348
val result = mutableListOf<ConstantArgument>()
344349

345-
annotations
346-
.filter { it.shortName.asString() == ShortClassNames.CONSTANT_INT_ARGUMENT }
347-
.forEach { result += ConstantArgument.IntValue(it.intArg("value", 0)) }
348-
349-
annotations
350-
.filter { it.shortName.asString() == ShortClassNames.CONSTANT_LONG_ARGUMENT }
351-
.forEach { result += ConstantArgument.LongValue(it.longArg("value", 0L)) }
352-
353-
annotations
354-
.filter { it.shortName.asString() == ShortClassNames.CONSTANT_BOOLEAN_ARGUMENT }
355-
.forEach { result += ConstantArgument.BooleanValue(it.booleanArg("value", false)) }
356-
357-
annotations
358-
.filter { it.shortName.asString() == ShortClassNames.CONSTANT_STRING_ARGUMENT }
359-
.forEach { result += ConstantArgument.StringValue(it.stringArg("value")) }
350+
for (annotation in annotations) {
351+
when (annotation.shortName.asString()) {
352+
CONSTANT_INT_ARGUMENT -> result += IntValue(annotation.intArg("value", 0))
353+
CONSTANT_LONG_ARGUMENT -> result += LongValue(annotation.longArg("value", 0L))
354+
CONSTANT_BOOLEAN_ARGUMENT -> result += BooleanValue(annotation.booleanArg("value", false))
355+
CONSTANT_STRING_ARGUMENT -> result += StringValue(annotation.stringArg("value"))
356+
}
357+
}
360358

361359
return result
362360
}

0 commit comments

Comments
 (0)