Skip to content

Instantly share code, notes, and snippets.

@joseoliv
Last active August 31, 2022 12:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joseoliv/acc8437a209ecf2a35cf81a84db75475 to your computer and use it in GitHub Desktop.
Save joseoliv/acc8437a209ecf2a35cf81a84db75475 to your computer and use it in GitHub Desktop.
onOverride
package metaobjectTest
@doc{*
Annotations of this metaobject are attached to a declaration. The
Cyan code attached to the annotation is run in phase afterSemAn. Method
afterSemAn_checkOverride of the class of metaobject onOverride,
overridden from ICheckOverride_afterSemAn, just interpret the Cyan
statements attached to the annotation.
Then, in phase afterSemAn of the compilation, the Myan statements
attached to the annotation onOverride below are interpreted.
Myan is interpreted Cyan.
To better understand this, see the documentation for action_afterResTypes_semAn.
*}
open
object OnOverride
func run {
}
@onOverride{*
// the overridden method should call
// this method in its first statement
// shouldCallSuperMethod is an action function
// of package cyan.lang
call: #shouldCallSuperMethod;
*}
/* print a warning message if method 'draw' is overridden in
a subprototype that does not declares a 'subMethod' method.
*/
@onOverride{*
var Boolean found = false;
var methodList =
method getDeclaringObject getMethodDecList: (compiler getEnv);
for i in 0..< methodList size {
var String methodName = (methodList get: i) getName;
if methodName == "subMethod" {
found = true;
break;
}
}
if !found {
var String protoName = method getDeclaringObject getName;
Out println: "Prototype " ++ method getDeclaringObject getName ++
" should have a 'subMethod' method";
}
*}
func draw {
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment