Skip to content

Instantly share code, notes, and snippets.

@joseoliv
Last active June 13, 2019 22:36
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/41c3923528bd4ade70a7ac389d45ef7d to your computer and use it in GitHub Desktop.
Save joseoliv/41c3923528bd4ade70a7ac389d45ef7d to your computer and use it in GitHub Desktop.
feature
package metaobjectTest
@doc{*
Annotation 'feature' associates a value to an identifier.
It can be attached to fields, methods, method signatures, packages, and
programs. Other metaobjects, the compiler, and Cyan code (at runtime) can
search the list of features. At compilation time, use method getFeatureList
of any declaration (inside a metaobject code). At runtime, use method
'featureList' (for the current prototype) or 'featureList: String'
(for methods and fields) declared in prototype Any.
*}
@feature(proto, "Feature")
object Feature
@feature(aMethod, "run of Feature")
func run {
var Array<Tuple<key, String, value, Any>> list = self featureList;
assert "\"abc\"" removeQuotes == "abc";
type list[0] value
case String value {
assert list[0] key removeQuotes == "proto" &&
value removeQuotes == "Feature";
}
list = self featureList: "run";
type list[0] value
case String value {
assert list[0] key removeQuotes == "aMethod" &&
value removeQuotes == "run of Feature";
}
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment