| [Help] About ASTNode [message #639255] |
Mon, 15 November 2010 13:34  |
Kam Ng Messages: 13 Registered: November 2010 Location: Hong Kong |
Junior Member |
|
|
Hello,
public void getInvokingMethode(String code) {
ASTParser parser = ASTParser.newParser(AST.JLS3);
parser.setSource(code.toCharArray());
parser.setKind(ASTParser.K_EXPRESSION);
ASTNode node = parser.createAST(null);
if (node.getNodeType() == ASTNode.METHOD_INVOCATION) {
MethodInvocation methodInvocation = (MethodInvocation) node;
System.out.println("Invoking method : "+ methodInvocation.getName());
}
}
I am using the code above and I am tring to get the API usage inside a method.
Since the parameter that I input is a java file, so I can only get the ASTNode.COMPILATION_UNIT.
How can I change the node position? For example, change to ASTNode.METHOD_INVOCATION
or somewhere else.
Kam
[Updated on: Mon, 15 November 2010 13:35] Report message to a moderator
|
|
|
|
|
| Re: [Help] About ASTNode [message #639537 is a reply to message #639393] |
Tue, 16 November 2010 15:16  |
Olivier Thomann Messages: 517 Registered: July 2009 |
Senior Member |
|
|
If you provide the kind K_EXPRESSION, then you need to pass in only an expression.
If you provide a compilation unit, then you should specify the kind to be a K_COMPILATION_UNIT and you can then simply use a NodeFinder call to find the corresponding expression if you know at what position the expression is located.
HTH,
--
Olivier
|
|
|
Powered by
FUDForum. Page generated in 0.05839 seconds