JDT AST学习笔记
学有所成啦!见https://github.com/Foxssss/ASTLearning
1.在IfStmt中的ThenStmt有两种情况:
if (a == b)
a = 1;
if (a == b) {
a = 1;
}
区别在于后者的ThenStmt是Block的一个实例,而前者不是,即对于后者而言,IfStatement.getThenStatement() instanceof Block
为真。
2.AST节点类
整体结构包括CompilationUnit类(编译单元)、TypeDeclaration类(类型声明)、MethodDeclaration类(方法声明);
语句包括Block类(语句块)、ExpressionStatement类(表达式)、IfStatement(if语句)、WhileStatement类(while语句)、EmptyStatement类(空语句)、BreakStatement类和ContinueStatement类;
表达式包括MethodInvocation类(方法调用)、Assignment类(赋值表达式)(“=”、“+=”、“-=”、“*=”、“/=”)、InfixExpression类(中缀表达式)(“+”、“-”、”*”、“/”、“%”、“==”、“!=”、“<”、“<=”、“>=”、“&&”、“||”。)、 PrefixExpression类(前缀表达式)(“+”PLUS “-”MINUS “!”NOT)、ParenthesizedExpression类(带括号的表达式)、NumberLiteral类(整数)、Name类(simple)。