Call the getExpression()
method of the ExpressionStatement
to get the expression the statement represents. This should be the MethodInvocation
you are looking for.
searching for MethodInvocation through eclipse AST
-
19-07-2023 - |
Pregunta
I am writing an Eclipse plug-in for code formatting and I need to detect method invocations in the AST but I cant seem to do it. I currently using the getNodeType() but it returns EXPRESSION_STATEMENT and when I debug I see that it's expression type is indeed a method invocation yet it still returns an EXPRESSION_STATEMENT type.
(I know i am missing a couple of checks but It doesnt matter currently, assume the Then statement and the Else statement is only one command of system.out.println() )
Any thoughts?
Thanks!
static boolean treatIfMethod(final AST ast, final ASTRewrite r, final IfStatement node){
final ASTNode thenMethod=(ASTNode)((Block)node.getThenStatement()).statements().get(0),
elseMethod=(ASTNode)((Block)node.getElseStatement()).statements().get(0);
if (thenMethod.getNodeType()==ASTNode.METHOD_INVOCATION &&
elseMethod.getNodeType()==ASTNode.METHOD_INVOCATION){
...
}
...
}
Solución
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow