You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@groovy.apache.org by Ralph Johnson <rj...@gmail.com> on 2021/01/21 03:40:38 UTC
getProperty
I'm refactoring a class so that instead of being a subclass of Binding, it
has a variable that is a Binding. There are a lot of different
subclasses of Binding in this system, I'm leaving most of them the same,
but I decided this one was wrong. When used as a binding, it has a
couple of interesting named values, "Types" and "Instances". So, there
are scripts that say "store.Types" and "store.Instances" and I could
rewrite them to be "store.binding.Types" and "store.binding.Instances", but
there are a LOT of these scripts and I am not even sure where they all
are. If the names had been lowercase then I could have defined getTypes
and getInstances, but since they are capitalized, I don't know how to
handle them.
One possibility is to define getProperty to look for the names "Types" and
"Instances". It would look something like this
Object getProperty(String name) {
switch(name) {
case 'Types': return binding['Types']
case 'Instances': return binding['Instances']
default: ????
}
}
What do I put as the default action? The problem is that it will get
called for every property, not only these fake ones. I can't say "return
super.getProperty(name)" because it is defined at the meta-level, not in
the superclass.
Of course, if there is a simpler way to solve the problem, I would love to
hear it.
-Ralph Johnson