Skip to main content



      Home
Home » Eclipse Projects » Rich Client Platform (RCP) » ast parser
ast parser [message #756261] Fri, 11 November 2011 12:24 Go to next message
Eclipse UserFriend
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>();

@Override
public boolean visit(MethodDeclaration node) {
methods.add(node);
return super.visit(node);
}

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

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

@Override
public boolean visit(MethodInvocation node) {
methods1.add(node);
return super.visit(node);
}

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

and in another class i have:

MethodVisitor visitor = new MethodVisitor();
parse.accept(visitor);

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


for (MethodInvocation method1 : visitor
.getMethods1()) {
System.out.println("Method name: "
+ method1.getName()
);
}
Re: ast parser [message #758385 is a reply to message #756261] Tue, 22 November 2011 19:13 Go to previous message
Eclipse UserFriend
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: Mon Jul 07 02:26:36 EDT 2025

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

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

Back to the top