利用AST扫描java文件 获得 类中的函数列表

eclipse工程的类文件.classpath的内容:
<? xml version ="1.0" encoding ="UTF-8" ?>
< classpath >
   < classpathentry kind ="src" path ="src" />
   < classpathentry kind ="con" path ="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6" />
   < classpathentry kind ="lib" path ="D:/eclipse/plugins/org.eclipse.jdt.core_3.6.1.v_A68_R36x.jar" />
   < classpathentry kind ="lib" path ="D:/eclipse/plugins/org.eclipse.core.runtime_3.6.0.v20100505.jar" />
   < classpathentry kind ="lib" path ="D:/eclipse/plugins/org.eclipse.equinox.common_3.6.0.v20100503.jar" />
   < classpathentry kind ="lib" path ="D:/eclipse/plugins/org.eclipse.core.resources_3.6.0.R36x_v20100825-0600.jar" />
   < classpathentry kind ="lib" path ="D:/eclipse/plugins/org.eclipse.core.jobs_3.5.1.R36x_v20100824.jar" />
   < classpathentry kind ="lib" path ="D:/eclipse/plugins/org.eclipse.osgi_3.6.1.R36x_v20100806.jar" />
   < classpathentry kind ="lib" path ="D:/eclipse/plugins/org.eclipse.core.contenttype_3.4.100.v20100505-1235.jar" />
   < classpathentry kind ="lib" path ="D:/eclipse/plugins/org.eclipse.equinox.preferences_3.3.0.v20100503.jar" />
   < classpathentry kind ="lib" path ="lib/commons-io-1.3.2.jar" />
   < classpathentry kind ="output" path ="bin" />
</ classpath >

不过,ast无法获取到 一些编译后绑定的信息(只有在作为eclipse插件运行时,才能获取到的信息)。还是会有一些局限性。如果真的想要获取到类的函数列表(或者函数内,调用其他函数的信息),通过asm字节码扫描是更好的方法。

特别注意的是:包名必须为:org.eclipse.jdt.core.dom1
如果不信,你可以改成其他包名试试看.:)

你可能感兴趣的:(eclipse,ast)