Last active
August 31, 2022 12:22
-
-
Save joseoliv/4eead47a5fac689bbd8dd8749df3067f to your computer and use it in GitHub Desktop.
onDeclaration_afterSemAn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_checkDeclaration of the class of metaobject onDeclaration_afterSemAn, | |
overridden from ICheckDeclaration_afterSemAn, just interpret the Cyan | |
statements attached to the annotation. | |
Then, in phase afterSemAn of the compilation, the Myan statements below | |
are interpreted. Myan is interpreted Cyan. | |
To better understand this, see the documentation for action_afterResTypes_semAn. | |
*} | |
@onDeclaration_afterSemAn{* | |
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_afterSemAn | |
func run { | |
} | |
@onDeclaration_afterSemAn{* | |
var annotation = metaobject getAnnotation; | |
var String name = annotation getDeclaration getName; | |
if name != "age" { | |
metaobject addError: "Field name should be 'age'" | |
} | |
*} | |
var Int age = 0; | |
@onDeclaration_afterSemAn{* | |
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