Programmer Reference : Pragmas : Annotation pragmas : Processing Annotation Pragmas : Performing Operations with Annotation Pragmas
Performing Operations with Annotation Pragmas
There are two ways to use pragma methods. One is to evaluate the Smalltalk code in the method; the other is to evaluate some other expression based on the arguments provided in the annotation pragma. Both of these can be used together.
Unary annotation pragmas have no arguments, so their only use is as a means to locate and evaluate the method they appear in. For example, the doStuff annotation pragma is only useful for sending the message containing it, as in:
(Pragma allNamed: #doStuff in: PragmaExampleClass) do: [ :aPragma |
PragmaExampleClass new perform: aPragma selector ]
Rather than naming the method class explicitly, we can get it from the annotation pragma itself by sending it a methodClass message:
(Pragma allNamed: #doStuff in: PragmaExampleClass) do: [ :aPragma |
aPragma methodClass new perform: aPragma selector ]
Most annotation pragmas are keyword pragmas, and are useful because of the arguments they carry. To use the arguments, send a withArgumentsDo: message to the annotation pragma. The argument is a block with the same number of block arguments as the annotation pragma has keywords. For example:
(Pragma allNamed: #doStuffWith:and: in: PragmaExampleClass) do: [ :aPragma |
aPragma withArgumentsDo: [ :first :second |
Transcript
cr; tab; show: first printString;
cr; tab; show: second printString ] ]
Last modified date: 01/29/2015