[Pharo-users] AST: Adding RBComment to a node

2020-04-23 Thread Mehrdad Abdi
Hello, 

How can I make a comment on a node dynamically? 

- Here is a code i've tried:

b:= RBParser parseMethod: 'foo self x: 2. x:=0. y:=8.'.
node := b body statements at: 1.
node comments: { RBComment with: 'comment' at: node stop + 1 }.
b formattedCode.

- The result:

foo
self x: 2.. x:=0. y
x := 0.
y := 8

- I expect:

foo
self x: 2."comment"
x := 0.
y := 8




[Pharo-users] Question on MetaLink: access to the calling MessageNode from a MethodNode

2019-12-18 Thread Mehrdad Abdi
Hello

For a specific method, I need to log some information when the method is 
called, like the state of the receiver, values of arguments, where the method 
is called, ... .

Using following MetaLink, I’m able to capture the receiver and arguments and 
context. 

link := MetaLink new
metaObject: self;
selector:

#linkBeforeMethodArguments:receiver:selector:context:;
control: #before;
level: 0;
arguments: #( arguments receiver selector context ). 
aMethod := MyClass methodNamed: #myMethodArg1:arg2.
aMethod ast link: link

For capturing the information related to where this method is called, It's 
possible to extract it from Context, but it’s a dirty way. 
Is there any way to access the MessageNode which called this MethodNode?

Best regards,
Mehrdad