CodeQL documentation

Abstract syntax tree classes for working with Java programs

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

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

Statement classes

This table lists all subclasses of 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.

Literals

All classes in this subsection are subclasses of 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.

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

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.

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
@Annot(key=val) Annotation