JavaParser使用指南

您所在的位置:网站首页 java中parse函数用法 JavaParser使用指南

JavaParser使用指南

2024-01-20 01:59| 来源: 网络整理| 查看: 265

抱歉这个博客是很久以前写的,现在我已经不用javaparser了,这个包也一直在更新所以这篇博客参考意义不大。

大家可以根据官网的例子去试试。

JavaParser使用指南 前言 入门-Start JavaParser Class CompilationUnit Class Visitor Classes A Simple Visitor Comments Pretty Printing and Lexical Preservation Javaparser-Solving Symbols and References Ex1: 获取变量(引用)的类型 Ex2: 使用absolute name直接解析类型 Ex3 Resolving a Type in a context Ex4 Resolving method calls Ex5 Using the Combined Type Solver Ex6 Using the MemoryTypeSolver JavaSymbolSolver

前言

以下翻译自官网的书

入门-Start JavaParser Class

用途:把Java源码转换成 JavaParser定义的Statement对象

Eg:

Statement expression = JavaParser.parseStatement("int a=0;"); CompilationUnit Class

用途:是一个完整的类文件的表示 在AST中,你可以把这个类看成是AST的根节点

Visitor Classes

用途:用于找到某个类型的节点

A Simple Visitor package com.github.javaparser; import com.github.javaparser.*; import com.github.javaparser.ast.*; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.body.EnumDeclaration; import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.symbolsolver.JavaSymbolSolver; import com.github


【本文地址】


今日新闻


推荐新闻


    CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3