Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. package metaobjectTest
  2.  
  3.  
  4. @doc{*
  5. Annotation 'log', when attached to a prototype P, without paramters,
  6. adds a statement to each method 'm':
  7. "Calling method 'm' of prototype 'P'" println
  8.  
  9. The same result is got by attaching 'log' to method 'm'
  10.  
  11. Annotation may take a single parameter that is either an identifier
  12. or a String. The metaobject creates a hashtable HmetCount of type
  13. HashMap<String, Int>
  14. and inserts it in the global table with the key that is the identifier.
  15. In the hashtable HmetCount, each key is a full method name of the form
  16. packageName.prototypeName::methodName
  17. The value is an Int with the number of times the method was called.
  18. See the example below to discover how to use the tables.
  19. *}
  20. @log(mylog)
  21. object Log
  22.  
  23. func run {
  24.  
  25. zero;
  26. one: 0 two: 1;
  27. self one: 0 two: 1;
  28. self three: "a", "b", "c";
  29. self three: "a", "b", "c";
  30. self three: "a", "b", "c";
  31.  
  32.  
  33. cast mapStrDyn = System globalTable get: "mylog" {
  34. var HashMap<String, Int> logMap = mapStrDyn;
  35. for elem in logMap asArray {
  36. // Tuple<key, K, value, V>
  37. Out println: "Method: " ++ elem key ++
  38. " Count: " ++ elem value;
  39. }
  40. }
  41.  
  42. }
  43.  
  44. func zero {
  45. }
  46. func one: Int n two: Int nn { }
  47. func three: String a, String b, String c {
  48. var s = "after calling 'three'";
  49. assert s size > 10;
  50. }
  51.  
  52. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement