How to count all the method calls in JDK using Eclipse JDT

╄→尐↘猪︶ㄣ 提交于 2019-12-11 16:41:04

问题


I have to count all the methods in JDK, for each class, count the method calls it received; for each method, count the number of times this method is called;

Hint: Use Eclipse JDT to create Abstract Syntax tree.

Can any body please explain how should I approach this problem. A brief algorithm would be great help. Thanks


回答1:


You can approach your problem using the below steps:

  1. First convert your java class to a CompilationUnit so that it can be traversed.
  2. Then use the ASTVisitor pattern to visit the MethodDeclaration node (method call)
  3. Do a reference search for the MethodDeclaration using JDT SearchEngine capabilities

Refer the below posts:

  • Eclipse create CompilationUnit from .java file
  • How to convert AST to JDT Java model
  • How to get all the references of static field with JDT


来源:https://stackoverflow.com/questions/27278507/how-to-count-all-the-method-calls-in-jdk-using-eclipse-jdt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!