Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » ast parser
ast parser [message #756261] Fri, 11 November 2011 17:24 Go to next message
katsikiwtis  is currently offline katsikiwtis Friend
Messages: 2
Registered: November 2011
Junior Member
Hi,how can I get the names of the methods invoked in each method declaration of a program using ast (Abstract Syntax Tree) parser? So far, I have managed to get all the names of the methods' declaration and all the names of the methods being invoked in the programme, but I want to know which method call which methods. For example, I want to know that method m1 calls methods mA and mB, while method m2 calls methods mC and mD, etc. It seems to be that my problem is that MethodDeclaration class has no GetInvokedMethodName in its api. I 've written this class:

public class MethodVisitor extends astVisitor {
List<MethodDeclaration> methods = new ArrayList<MethodDeclaration>();

public boolean visit(MethodDeclaration node) {
return super.visit(node);

public List<MethodDeclaration> getMethods() {
return methods;

List<MethodInvocation> methods1 = new ArrayList<MethodInvocation>();

public boolean visit(MethodInvocation node) {
return super.visit(node);

public List<MethodInvocation> getMethods1() {
return methods1;

and in another class i have:

MethodVisitor visitor = new MethodVisitor();

for (MethodDeclaration method : visitor
.getMethods()) {
System.out.println("Method name: "
+ method.getName()
+ " Return type: "
+ method.getReturnType2()
+ " Is constructor: "
+ method.isConstructor()
+ " Method invoked: "

for (MethodInvocation method1 : visitor
.getMethods1()) {
System.out.println("Method name: "
+ method1.getName()
Re: ast parser [message #758385 is a reply to message #756261] Wed, 23 November 2011 00:13 Go to previous message
Eiji Adachi is currently offline Eiji AdachiFriend
Messages: 8
Registered: November 2011
Junior Member
Maybe you could climb up the tree when you visit MethodInvocation by calling getParent until you get to a ASTNode that is instanceof MethodDeclaration. Then, you will get the relationship you want.
Previous Topic:Determine Nature of Closed Project
Next Topic:How to get Package Explorer window in RCP Application
Goto Forum:

Current Time: Thu Sep 20 00:04:45 GMT 2018

Powered by FUDForum. Page generated in 0.04165 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top