Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
onDeclaration_afsa
package metaobjectTest
@doc{*
Annotations of this metaobject are attached to a declaration. The
Cyan code attached to the annotation is run in phase afsa. To better
understand this, see the documentation for action_afti_dsa.
*}
@onDeclaration_afsa{*
var Boolean found = false;
var Int size = compiler getMethodDecList size;
for i in 0..< size {
var String methodName = ((compiler getMethodDecList) get: i) getName;
if methodName == "run" {
found = true;
break;
}
}
if !found {
metaobject addError: "This prototype should have a 'run' method";
}
*}
object OnDeclaration_afsa
func run {
}
@onDeclaration_afsa{*
var annotation = metaobject getMetaobjectAnnotation;
var String name = annotation getDeclaration getName;
if name != "age" {
metaobject addError: "Field name should be 'age'"
}
*}
var Int age = 0;
@onDeclaration_afsa{*
var Int size = metaobject getAttachedDeclaration
getMethodSignature getParameterList size;
if ( size != 2 ) {
metaobject addError: "This method should have two paramters"
}
*}
func at: Int n put: String s {
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.