Skip to content

Commit

Permalink
fix(generator-accessor-plugin): ambiguous method call in Groovy
Browse files Browse the repository at this point in the history
  • Loading branch information
zlataovce committed Sep 20, 2023
1 parent 93acc51 commit 2807653
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ import me.kcra.takenaka.core.VersionRangeBuilder
import me.kcra.takenaka.generator.accessor.AccessorConfiguration
import me.kcra.takenaka.generator.accessor.AccessorType
import me.kcra.takenaka.generator.accessor.CodeLanguage
import me.kcra.takenaka.generator.accessor.model.ClassAccessor
import me.kcra.takenaka.generator.accessor.model.ClassAccessorBuilder
import me.kcra.takenaka.generator.accessor.model.FieldChainBuilder
import me.kcra.takenaka.generator.accessor.model.MethodChainBuilder
import me.kcra.takenaka.generator.accessor.model.*
import me.kcra.takenaka.generator.accessor.plugin.tasks.DEFAULT_INDEX_NS
import org.gradle.api.Action
import org.gradle.api.Project
Expand Down Expand Up @@ -326,14 +323,14 @@ enum class PlatformTristate(val wantsClient: Boolean, val wantsServer: Boolean)
* @param name mapped name of the accessed class
* @author Matouš Kučera
*/
class GradleFlavoredClassAccessorBuilder(name: String) : ClassAccessorBuilder(name) {
class GradleFlavoredClassAccessorBuilder(name: String) : AbstractClassAccessorBuilder(name) {
/**
* Adds a new chained field accessor model.
*
* @param block the builder action
*/
fun fieldChain(block: Action<FieldChainBuilder>) {
fieldChain(block::execute)
fieldChain0(block::execute)
}

/**
Expand All @@ -342,6 +339,6 @@ class GradleFlavoredClassAccessorBuilder(name: String) : ClassAccessorBuilder(na
* @param block the builder action
*/
fun methodChain(block: Action<MethodChainBuilder>) {
methodChain(block::execute)
methodChain0(block::execute)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import java.util.*
import kotlin.reflect.KClass

/**
* A builder for [ClassAccessor].
* A base class for a [ClassAccessor] builder.
*
* @property name mapped name of the accessed class
* @author Matouš Kučera
*/
open class ClassAccessorBuilder(val name: String) {
abstract class AbstractClassAccessorBuilder(val name: String) {
/**
* Field accessor models.
*/
Expand Down Expand Up @@ -78,7 +78,7 @@ open class ClassAccessorBuilder(val name: String) {
*
* @param block the builder action
*/
inline fun fieldChain(block: FieldChainBuilder.() -> Unit) {
protected inline fun fieldChain0(block: FieldChainBuilder.() -> Unit) {
fields += buildFieldChain(block)
}

Expand All @@ -105,9 +105,9 @@ open class ClassAccessorBuilder(val name: String) {
* @param names the mapped enum constant names to be chained
*/
fun enumConstantChain(vararg names: String) {
fieldChain {
fieldChain0 {
names.forEach { name ->
item(this@ClassAccessorBuilder.name, name)
item(this@AbstractClassAccessorBuilder.name, name)
}
}
}
Expand Down Expand Up @@ -162,7 +162,7 @@ open class ClassAccessorBuilder(val name: String) {
*
* @param block the builder action
*/
inline fun methodChain(block: MethodChainBuilder.() -> Unit) {
protected inline fun methodChain0(block: MethodChainBuilder.() -> Unit) {
methods += buildMethodChain(block)
}

Expand Down Expand Up @@ -206,7 +206,7 @@ open class ClassAccessorBuilder(val name: String) {
*/
@JvmOverloads
fun getterChainInferred(name: String, version: String? = null) {
methodChain {
methodChain0 {
itemInferred(name, version)
itemInferred("get${name.replaceFirstChar { it.titlecase(Locale.getDefault()) }}", version)
}
Expand All @@ -226,7 +226,7 @@ open class ClassAccessorBuilder(val name: String) {
fun getterChain(type: Any, name: String) {
val prefix = if (type.asDescriptor() == "Z") "is" else "get" // presume boolean getter name to be isSomething instead of getSomething

methodChain {
methodChain0 {
item(type, name)
item(type, "$prefix${name.replaceFirstChar { it.titlecase(Locale.getDefault()) }}")
}
Expand Down Expand Up @@ -255,7 +255,7 @@ open class ClassAccessorBuilder(val name: String) {
* @param name the mapped method name
*/
fun setterChain(type: Any, name: String) {
methodChain {
methodChain0 {
item(Void.TYPE, name, type)
item(Void.TYPE, "set${name.replaceFirstChar { it.titlecase(Locale.getDefault()) }}", type)
}
Expand All @@ -279,6 +279,31 @@ open class ClassAccessorBuilder(val name: String) {
fun toClassAccessor() = ClassAccessor(name, fields, constructors, methods, requiredMemberTypes)
}

/**
* A simple implementation of [AbstractClassAccessorBuilder].
*
* @param name mapped name of the accessed class
*/
class ClassAccessorBuilder(name: String) : AbstractClassAccessorBuilder(name) {
/**
* Adds a new chained field accessor model.
*
* @param block the builder action
*/
fun fieldChain(block: FieldChainBuilder.() -> Unit) {
fieldChain0(block)
}

/**
* Adds a new chained method accessor model.
*
* @param block the builder action
*/
fun methodChain(block: MethodChainBuilder.() -> Unit) {
methodChain0(block)
}
}

/**
* Builds a new [ClassAccessor].
*
Expand Down

0 comments on commit 2807653

Please sign in to comment.