jdt可以做语法树分析,并且支持visitor模式对代码进行分析。跟pmd的分析方式一样,我们只要实现 visitor接口即可实现一个插件。

@Service("requestMappingInfoService")
public class RequestMappingInfoServiceImpl implements RequestMappingInfoService { int c = 0; private static OkHttpClient httpClient = new OkHttpClient();
private static GitlabAPI gla = GitlabAPI.connect("https://git.xxx.com", "mytoken");
private static ASTParser parser = ASTParser.newParser(AST.JLS8); //设置Java语言规范版本 static {
parser.setKind(ASTParser.K_COMPILATION_UNIT);
parser.setCompilerOptions(null);
parser.setResolveBindings(true); Map<String, String> compilerOptions = JavaCore.getOptions();
//设置Java语言版本
compilerOptions.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_8);
compilerOptions.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_8);
compilerOptions.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_8);
//设置编译选项
parser.setCompilerOptions(compilerOptions); } private void jdtPrase(byte[] fileContent, String giturl) { parser.setSource(new String(fileContent).toCharArray()); //下个断点可以看看cu的types成员就是整个语法树
CompilationUnit cu = (CompilationUnit) parser.createAST(null); //RequestMappingVisitor是个ASTVisitor的实现类 ,相当于一个插件
        RequestMappingVisitor requestMappingVisitor = new RequestMappingVisitor();
cu.accept(requestMappingVisitor); //利用这个插件visit所有的语法树节点 }
}

最新文章

  1. 找不到方法:&quot;!!0[] System.Array.Empty()&quot;.
  2. swap的应用两个数的交换
  3. C语言学习014:结构化数据类型
  4. Linux里startup.sh 和 shutdown.sh
  5. Kanzi入门
  6. [STL]set/multiset用法详解[自从VS2010开始,set的iterator类型自动就是const的引用类型]
  7. String 方法
  8. This function or variable may be unsafe. Consider using scanf_s instead.
  9. httpd sshd firewalld 服务后面的d的意思
  10. Install Nagios (Agent) nrpe client and plugins in Ubuntu/Debian
  11. Android定制:修改开机启动画面
  12. vs widows服务的开发
  13. Linux设备驱动Hello World程序介绍
  14. statik golang 静态资源嵌入二进制文件工具使用(docker 构建)
  15. javascript Function类型
  16. sql 字符串操作
  17. centos6.8上安装paramiko
  18. java 基础 --集合--013
  19. 利用xcopy在复制文件或文件夹的时候保留其权限
  20. 北京Uber优步司机奖励政策(12月22日)

热门文章

  1. Apollo配置中心转
  2. Redis_发布订阅(Spring Boot)
  3. gitlab仓库服务器搭建
  4. Linux(deepin)安装Oracle JDK
  5. UVALive 3942 Remember the Word 字典树+dp
  6. [转]Mac系统安装软件提示软件已损坏的解决办法
  7. MFC编程之创建Ribbon样式的应用程序框架
  8. markdown完整语法规范3.0+编辑工具介绍
  9. js压缩 uglify(2)
  10. git &amp; github 菜鸟笔记