Class GroovyObjectOverrides

java.lang.Object
org.apache.groovy.internal.metaclass.GroovyObjectOverrides

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.

  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    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.
    static boolean
    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.
    static boolean
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • overridesSetProperty

      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. Computed once per class.

      When reflection cannot read the public methods of the class, the answer is true. A caller then invokes GroovyObject.setProperty(String, Object), 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.

      Parameters:
      type - a class that implements GroovyObject
      Returns:
      true if a write should be passed to the object's own setProperty rather than to its metaclass
    • overridesGetProperty

      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. 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).
      Parameters:
      type - a class that implements GroovyObject
      Returns:
      true if a read should be passed to the object's own getProperty rather than to its metaclass
      See Also:
    • hasCustomGetProperty

      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. 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.
      Parameters:
      type - a class that implements GroovyObject
      Returns:
      true if a read should be passed to the object's own getProperty rather than to its metaclass