com.powsybl.afs.scripting.BuilderSpec.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of powsybl-afs-scripting Show documentation
Show all versions of powsybl-afs-scripting Show documentation
Extensions to use AFS in scripts
package com.powsybl.afs.scripting
import com.powsybl.afs.AfsException
/**
* @author Geoffroy Jamgotchian
*/
class BuilderSpec {
private final def builder
BuilderSpec(Object builder) {
assert builder
this.builder = builder
}
private def testSetters(String name, args) {
boolean found = false
for (String prefix : ["with", "set"]) {
def setterName = prefix + name.capitalize();
def setter = builder.metaClass.getMetaMethod(setterName, args)
if (setter) {
setter.invoke(builder, args)
found = true
break
}
}
return found
}
def methodMissing(String name, args) {
boolean found = testSetters(name, args)
if (!found && name.startsWith("_")) { // keyword collision strategy
found = testSetters(name.substring(1), args)
}
if (!found) {
throw new AfsException("Setter (method=" + name + ", args=" + args + ") not found")
}
}
}