Abstract syntax tree classes for working with Java programs


Abstract syntax tree classes for working with Java programs用于Java程序的抽象语法树类。

CodeQL has a large selection of classes for representing the abstract syntax tree of Java programs.

CodeQL有大量的类用于表示Java程序的抽象语法树。

The abstract syntax tree (AST) represents the syntactic structure of a program. Nodes on the AST represent elements such as statements and expressions.

抽象语法树(AST)表示程序的语法结构。AST中的节点代表了诸如语句和表达式等元素。

Statement classes

This table lists all subclasses of Stmt.

本表列出了Stmt的所有子类。

Statement syntax CodeQL class Superclasses Remarks
; EmptyStmt
Expr ; ExprStmt
{ Stmt ... } BlockStmt
if ( Expr ) Stmt else Stmt IfStmt ConditionalStmt
if ( Expr ) Stmt
while ( Expr ) Stmt WhileStmt ConditionalStmt, LoopStmt
do Stmt while ( Expr ) DoStmt ConditionalStmt, LoopStmt
for ( Expr ; Expr ; Expr ) Stmt ForStmt ConditionalStmt, LoopStmt
for ( VarAccess : Expr ) Stmt EnhancedForStmt LoopStmt
switch ( Expr ) { SwitchCase ... } SwitchStmt
try { Stmt ... } finally { Stmt ... } TryStmt
return Expr ; ReturnStmt
return ;
throw Expr ; ThrowStmt
break ; BreakStmt JumpStmt
break label ;
continue ; ContinueStmt JumpStmt
continue label ;
label : Stmt LabeledStmt
synchronized ( Expr ) Stmt SynchronizedStmt
assert Expr : Expr ; AssertStmt
assert Expr ;
TypeAccess name ; LocalVariableDeclStmt
class name { Member ... } ; LocalClassDeclStmt
this ( Expr , ... ) ; ThisConstructorInvocationStmt
super ( Expr , ... ) ; SuperConstructorInvocationStmt
catch ( TypeAccess name ) { Stmt ... } CatchClause can only occur as child of a TryStmt
case Literal : Stmt ... ConstCase can only occur as child of a SwitchStmt
default : Stmt ... DefaultCase can only occur as child of a SwitchStmt

Expression classes

There are many expression classes, so we present them by category. All classes in this section are subclasses of Expr.

表达式类有很多,所以我们按类别来介绍。本节中的所有类都是Expr.Literals的子类。

Literals

All classes in this subsection are subclasses of Literal.

本小节中的所有类都是Literal的子类。

Expression syntax example CodeQL class
true BooleanLiteral
23 IntegerLiteral
23l LongLiteral
4.2f FloatingPointLiteral
4.2 DoubleLiteral
'a' CharacterLiteral
"Hello" StringLiteral
null NullLiteral

Unary expressions

All classes in this subsection are subclasses of UnaryExpr.

本小节中的所有类都是UnaryExpr的子类。

Expression syntax CodeQL class Superclasses Remarks
Expr++ PostIncExpr UnaryAssignExpr
Expr-- PostDecExpr UnaryAssignExpr
++Expr PreIncExpr UnaryAssignExpr
--Expr PreDecExpr UnaryAssignExpr
~Expr BitNotExpr BitwiseExpr see below for other subclasses of BitwiseExpr
-Expr MinusExpr
+Expr PlusExpr
!Expr LogNotExpr LogicExpr see below for other subclasses of LogicExpr

Binary expressions

All classes in this subsection are subclasses of BinaryExpr.

本小节中的所有类都是BinaryExpr的子类。

Expression syntax CodeQL class Superclasses
Expr * Expr MulExpr
Expr / Expr DivExpr
Expr % Expr RemExpr
Expr + Expr AddExpr
Expr - Expr SubExpr
Expr << Expr LShiftExpr
Expr >> Expr RShiftExpr
Expr >>> Expr URShiftExpr
Expr && Expr AndLogicalExpr LogicExpr
Expr ` ` Expr
Expr < Expr LTExpr ComparisonExpr
Expr > Expr GTExpr ComparisonExpr
Expr <= Expr LEExpr ComparisonExpr
Expr >= Expr GEExpr ComparisonExpr
Expr == Expr EQExpr EqualityTest
Expr != Expr NEExpr EqualityTest
Expr & Expr AndBitwiseExpr BitwiseExpr
Expr ` ` Expr OrBitwiseExpr
Expr ^ Expr XorBitwiseExpr BitwiseExpr

Assignment expressions

All classes in this table are subclasses of Assignment.

本表中的所有类都是Assignment的子类。

Expression syntax CodeQL class Superclasses
Expr = Expr AssignExpr
Expr += Expr AssignAddExpr AssignOp
Expr -= Expr AssignSubExpr AssignOp
Expr *= Expr AssignMulExpr AssignOp
Expr /= Expr AssignDivExpr AssignOp
Expr %= Expr AssignRemExpr AssignOp
Expr &= Expr AssignAndExpr AssignOp
Expr ` =` Expr AssignOrExpr
Expr ^= Expr AssignXorExpr AssignOp
Expr <<= Expr AssignLShiftExpr AssignOp
Expr >>= Expr AssignRShiftExpr AssignOp
Expr >>>= Expr AssignURShiftExpr AssignOp

Accesses

Expression syntax examples CodeQL class
this ThisAccess
Outer.this
super SuperAccess
Outer.super
x VarAccess
e.f
a[i] ArrayAccess
f(...) MethodAccess
e.m(...)
String TypeAccess
java.lang.String
? extends Number WildcardTypeAccess
? super Double

A VarAccess that refers to a field is a FieldAccess.

一个指向字段的VarAccess是一个FieldAccess。

Miscellaneous

Expression syntax examples CodeQL class Remarks
(int) f CastExpr
(23 + 42) ParExpr
o instanceof String InstanceOfExpr
Expr ? Expr : Expr ConditionalExpr
String. class TypeLiteral
new A() ClassInstanceExpr
new String[3][2] ArrayCreationExpr
new int[] { 23, 42 }
{ 23, 42 } ArrayInit can only appear as an initializer or as a child of an ArrayCreationExpr只能作为初始化器或ArrayCreationExpr的子代出现。
@Annot(key=val) Annotation

文章作者: SummerSec
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 SummerSec !
  目录