Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: added a paragraph about dispatch

...

Number:

GEP-11

Title:

Groovy 3 semantics and new MOP

Version:

1.78.10

Type:

Feature

Target:

3.0

Status:

Draft

Leader:

Jochen "blackdrag" Theodorou

Created:

2012-06-26

Last modification:

2013-1004-0102

Last update by:
Contributors
limit1

...

Because of the concept of context a class does not have one direct meta class that can be generated without its context. The call site defines the place of the context. How the context itself is defined is a TODO. As an implementation strategy it is possible to for example use ClassValue to store a table with the context being a key. The key would probably have to be available as static information, or as easily computable information. Since the resulting meta class could be stored later in the call site object context changes are to be avoided, since it implies the invalidation of the call sites using that context.

General dispatch rule for methods (and properties)

To define the dispatch rules correctly we need to define some terms first:
Static Sender Class (SSC):  This is the static information about the class a call is made from. If there is for example a class A and a class B extends A, and a call in a method in A, then even if your instance is actually a B the SSC will still be A.
Inheritance based Multimethods (short multimethods from now on): Given a class A and a class B extends A, a call made from within A may see a method defined on B as long as the method is visible (not private). Groovy defines a special  exception to this though. If the method call from within A is calling a method of the name m, then a m from B can only be visible if there is no private m defined in A.

Given those two definitions a method call in will select the set of method to decide from based on this:
A call m() with the SSC A and done on an instance of B (extends A) will be using the methods defined in A, if A has a private m, otherwise the call is done using B.

Calls to Super:
A call to super in B extends A will have the SSC B, but for the method selection process the super class of SSC (super(SSC)) will be used. In super calls mutimethods are not visible. Thus we can directly use the meta class super(SSC), but we will dispatch only on the public methods of that meta class.

Property Discovery

Currently MetaClass discovers properties based on the Java Beans conventions. It also allows pseudo properties matching a convention on java.beans.EventSetDescriptor. This allows the following trick in SwingBuilder for example

...