<p class="MsoNormal">Hi, David!<br>
<span style=""> </span>I need investigate method's content and
find service name. Service name every time will be in one of place and find it
not difficult:<br>
<span style="color: rgb(51, 102, 255);">this.service =
ServiceLocator.getInstance().getService("<b><u>CallMeService</u></b>");</span><br>
I did next:<br>
1) I add:<br>
- uk.co.badgersinfoil.metaas.dom.ASMethod<br>
<b>public ASTStatementList getStmt();</b><br>
- uk.co.badgersinfoil.metaas.impl.ASTASMethod (Implementation);<br>
<b>public ASTStatementList getStmt()<br>
{<br>
return this.stmtList;<br>
}</b><br>
And implement in my code information reader from <b>ASTStatementList</b>.<br>
2) In my business method invoke new one:<br>
<i><span style="color: rgb(51, 102, 255);">// Find Service name<br>
</span></i> <i><span style="color: rgb(51, 102, 255);">// TODO: Use
Implement read method statement from MetAS in Future<br>
</span></i> <i><span style="color: rgb(51, 102, 255);">ASTStatementList
stmts = method.getStmt(); // My hack method for take method content<br>
</span></i> <i><span style="color: rgb(51, 102, 255);">serviceName = <b><u>findServiceName</u></b>(stmts);</span><span style="color: rgb(102, 51, 255);"><br>
</span></i><br>
3) This is information reader method:<br>
<span style="color: rgb(51, 102, 255);">private String
findServiceName(ASTStatementList stmts)<br>
{<br>
String result = null;<br>
LinkedListTree linkedListTree =
stmts.getAST();<br>
LinkedListToken currentListToken =
linkedListTree.getStartToken();<br>
LinkedListToken stopListToken =
linkedListTree.getStopToken();<br>
List lines = new ArrayList();<br>
StringBuffer sb = new StringBuffer();<br>
String tonk = currentListToken.getText();<br>
while ( (currentListToken =
currentListToken.getNext()) != null)<br>
{<br>
if
(currentListToken.equals(stopListToken))<br>
{<br>
if
( (sb.toString().length() > 0) &&
(!sb.toString().equals(";")) )<br>
lines.add(sb.toString());<br>
break;<br>
}<br>
System.out.print(tonk);<br>
sb.append(tonk);<br>
tonk =
currentListToken.getText();<br>
if
(tonk.equals(";"))<br>
{<br>
lines.add(sb.toString());<br>
sb
= new StringBuffer();<br>
}<br>
};<br>
System.out.println();<br>
for (int j = 0; j < lines.size(); j++)<br>
{<br>
String str =
lines.get(j).toString();<br>
System.out.println(str);<br>
int offs = str.indexOf("getService(\"");<br>
if (offs != -1)<br>
{<br>
offs += "getService(\"".length();<br>
//
Found<br>
int
offe = str.indexOf("\"", offs);<br>
if
(offe != -1)<br>
{<br>
result = str.substring(offs, offe);<br>
}<br>
}<br>
}<br>
return result;<br>
}</span><br>
<br>
It is working, but in the future I rewrite this code, after you finish.<br>
Is this implementation right or not?<br>
<br>
Sergey.</p>On 24/01/07, <b class="gmail_sendername">David Holroyd</b> <<a href="mailto:dave@badgers-in-foil.co.uk">dave@badgers-in-foil.co.uk</a>> wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On Wed, Jan 24, 2007 at 08:01:09AM +0200, Sergey Akopkokhyants wrote:<br>> Is it possible take statements from method, because I need investigate<br>> content of it? I can open the same file in another thread, but I it bad
<br>> idea.<br><br>metaas doesn't provide read-access to statements in a method/block etc.<br>yet, just write-access for code generation.<br><br>The plan is for this to be included at some point, but it is quite a<br>
lot of work.<br><br>What information specifically are you trying to get from the code?<br><br><br><br>dave<br></blockquote></div><br>