JDT:获取Java类每个方法的注释
来源:互联网 发布:java 项目经验编写 编辑:程序博客网 时间:2024/05/18 20:07
//step1:获取ICompilationUnit
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject project = root.getProject("test");
try {
project.open(null /* IProgressMonitor */);
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
IJavaProject javaProject = JavaCore.create(project);
IType lwType = null;
try {
lwType = javaProject.findType("net.chenxs.Test");
} catch (JavaModelException e) {
e.printStackTrace();
}
//step2:提取JavaDoc
ICompilationUnit lwCompilationUnit = lwType.getCompilationUnit();
try {
SourceType type = (SourceType) lwCompilationUnit.getAllTypes()[0];
IBuffer buffer = lwCompilationUnit.getBuffer();
IMethod[] methods = type.getMethods();
IBuffer buffer1 = lwCompilationUnit.getBuffer();
for(int i=0; i<methods.length;i++){
IMethod method =methods[i];
ISourceRange range = method.getJavadocRange();//获取JavaDoc的范围区间
if(range != null){
System.out.println(range.getOffset() + " " + range.getLength());
System.out.println(buffer1.getText(range.getOffset(),range.getLength()));;
}
}
} catch (JavaModelException e) {
e.printStackTrace();
}
注:通过ast也是可以的;
ASTParser astParser = ASTParser.newParser(AST.JLS3);
astParser.setKind(ASTParser.K_COMPILATION_UNIT);
astParser.setSource(lwCompilationUnit);
CompilationUnit unit = (CompilationUnit) astParser.createAST(null);
TypeDeclaration type = (TypeDeclaration) unit.types().get(0);
MethodDeclaration[] methods = type.getMethods();
for(int i=0; i<methods.length;i++){
MethodDeclaration method = methods[i];
Javadoc doc = method.getJavadoc();
if(doc != null){
System.out.println(doc);
}
}
- JDT:获取Java类每个方法的注释
- Java 使用反射获取类、方法、属性上的注释
- 将java工程文件打成jar包并且保留每个java文件的方法注释方法
- [Java]获取java方法注释实例
- JAVA获取每个月的天数
- JAVA获取每个月的天数
- 调用eclipse的JDT编译java源代码
- ORACLE获取表字段、注释的方法
- 调用JDT需要涉及到的类
- JDT提供的工具类JavaConventions
- 每个Java类都有的toString方法
- 每个Java类都有的equals方法
- JAVA获取类的方法
- 每个类有很多方法,每个对象的类型不同
- JDT - Java element hierarchy
- Java Model in JDT
- 用Java显示获取每个汉字的拼音首字母
- java 获取英文语句中每个字母出现的次数
- NSString 字符串处理方法集合
- Android开发学习笔记:5大布局方式详解
- JDT:从JavaProject中获取编译单元(ICompilationUnit)
- boost bind 实现方法
- Android之浅谈Gallery
- JDT:获取Java类每个方法的注释
- 接收一次性广播,开启服务永久监听
- linux下socket编写常用头文件
- 设备坐标、逻辑坐标、物理坐标的区别与转换
- Windows XP远程桌面连接设置图解教程
- win2008如何用命令设置文件夹权限
- 收集的几种exe嵌入网页的方法(1)
- iPhone图形开发绘图小结
- 顺序队列的应用