public final class GroovyObjectOverrides
extends Object
Whether a class overrides the setProperty or getProperty that
GroovyObject provides, which decides how the runtime dispatches a dynamic
property write or read to its instances.
An override receives every access. The GroovyObject defaults only hand the access
to the metaclass, so the runtime calls the metaclass itself instead and tells it which
class is making the access; that is what lets, say, a superclass reach its own private
field on an instance of a subclass.
For overridesSetProperty(Class) and overridesGetProperty(Class), an
override is any implementation other than the GroovyObject default itself,
whether the class declares it, inherits it from a superclass, or takes it from a default
method of another interface, such as one extending GroovyObject.
hasCustomGetProperty(Class) also sets aside implementations that are synthetic
or marked Internal.
Reads have two criteria, which differ on purpose. ScriptBytecodeAdapter.getProperty
uses overridesGetProperty(Class); the property-read call sites, invokedynamic and
classic, use hasCustomGetProperty(Class). They disagree in one case: a
getProperty other than the GroovyObject default that is synthetic or
marked @Internal, which the adapter passes the read to and the call sites go
around to the metaclass. That split is older than this class, and giving one path the
other's criterion would change which implementation answers such a read.
Writes have one criterion, overridesSetProperty(Class), which
ScriptBytecodeAdapter.setProperty and setGroovyObjectProperty and the
invokedynamic property-write sites share. No write path sets aside a synthetic or
@Internal setProperty, and classic compilation has no property-write call
sites: its writes go through ScriptBytecodeAdapter.
Not user API.
| Type Params | Return Type | Name and description |
|---|---|---|
|
public static boolean |
hasCustomGetProperty(Class<?> type)Tells whether instances of the given class take getProperty(String) from an
implementation that is neither synthetic nor marked Internal: the criterion
of the property-read call sites, invokedynamic and classic. |
|
public static boolean |
overridesGetProperty(Class<?> type)Tells whether instances of the given class take getProperty(String) from an
implementation other than the GroovyObject default, including a default method
of another interface. |
|
public static boolean |
overridesSetProperty(Class<?> type)Tells whether instances of the given class take setProperty(String, Object)
from an implementation other than the GroovyObject default, including a
default method of another interface. |
Tells whether instances of the given class take getProperty(String) from an
implementation that is neither synthetic nor marked Internal: the criterion
of the property-read call sites, invokedynamic and classic. Unlike
overridesGetProperty(Class), it treats an implementation that is synthetic or
marked @Internal as generated, like the GroovyObject default, which
carries @Internal for this reason.
Computed once per class, and true when reflection cannot read the public
methods of the class, for the reasons given for overridesSetProperty(Class):
the invokedynamic and classic call sites alike then pass the read to the object's own
getProperty rather than to a metaclass path that would skip a real override.
type - a class that implements GroovyObjecttrue if a read should be passed to the object's own
getProperty rather than to its metaclass Tells whether instances of the given class take getProperty(String) from an
implementation other than the GroovyObject default, including a default method
of another interface. This is the criterion of ScriptBytecodeAdapter.getProperty. Computed once per class, and true
when reflection cannot read the public methods of the class, for the reasons given
for overridesSetProperty(Class).
type - a class that implements GroovyObjecttrue if a read should be passed to the object's own
getProperty rather than to its metaclass Tells whether instances of the given class take setProperty(String, Object)
from an implementation other than the GroovyObject default, including a
default method of another interface. Computed once per class.
When reflection cannot read the public methods of the class, the answer is
true. A caller then invokes GroovyObject.setProperty,
which reaches whichever implementation the object really has; if that is the
GroovyObject default, the write still reaches the metaclass, but without the sender, so it is
resolved as if the object's own class were making it. Answering false would
instead hand the write straight to the metaclass, bypassing any override.
type - a class that implements GroovyObjecttrue if a write should be passed to the object's own
setProperty rather than to its metaclass