[metaas-dev] Re: statements
Sergey Akopkokhyants
akserg at gmail.com
Thu Jan 25 12:15:59 UTC 2007
Hi, David!
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:
this.service = ServiceLocator.getInstance().getService("*CallMeService*");
I did next:
1) I add:
- uk.co.badgersinfoil.metaas.dom.ASMethod
*public ASTStatementList getStmt();*
- uk.co.badgersinfoil.metaas.impl.ASTASMethod (Implementation);
*public ASTStatementList getStmt()
{
return this.stmtList;
}*
And implement in my code information reader from *ASTStatementList*.
2) In my business method invoke new one:
*// Find Service name
* *// TODO: Use Implement read method statement from MetAS in Future
* *ASTStatementList stmts = method.getStmt(); // My hack method for take
method content
* *serviceName = findServiceName(stmts);
*
3) This is information reader method:
private String findServiceName(ASTStatementList stmts)
{
String result = null;
LinkedListTree linkedListTree = stmts.getAST();
LinkedListToken currentListToken = linkedListTree.getStartToken();
LinkedListToken stopListToken = linkedListTree.getStopToken();
List lines = new ArrayList();
StringBuffer sb = new StringBuffer();
String tonk = currentListToken.getText();
while ( (currentListToken = currentListToken.getNext()) != null)
{
if (currentListToken.equals(stopListToken))
{
if ( (sb.toString().length() > 0) &&
(!sb.toString().equals(";")) )
lines.add(sb.toString());
break;
}
System.out.print(tonk);
sb.append(tonk);
tonk = currentListToken.getText();
if (tonk.equals(";"))
{
lines.add(sb.toString());
sb = new StringBuffer();
}
};
System.out.println();
for (int j = 0; j < lines.size(); j++)
{
String str = lines.get(j).toString();
System.out.println(str);
int offs = str.indexOf("getService(\"");
if (offs != -1)
{
offs += "getService(\"".length();
// Found
int offe = str.indexOf("\"", offs);
if (offe != -1)
{
result = str.substring(offs, offe);
}
}
}
return result;
}
It is working, but in the future I rewrite this code, after you finish.
Is this implementation right or not?
Sergey.
On 24/01/07, David Holroyd <dave at badgers-in-foil.co.uk> wrote:
>
> On Wed, Jan 24, 2007 at 08:01:09AM +0200, Sergey Akopkokhyants wrote:
> > Is it possible take statements from method, because I need investigate
> > content of it? I can open the same file in another thread, but I it bad
> > idea.
>
> metaas doesn't provide read-access to statements in a method/block etc.
> yet, just write-access for code generation.
>
> The plan is for this to be included at some point, but it is quite a
> lot of work.
>
> What information specifically are you trying to get from the code?
>
>
>
> dave
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.badgers-in-foil.co.uk/pipermail/metaas-dev/attachments/20070125/76ad0d19/attachment.htm
More information about the metaas-dev
mailing list