Classes for working with Java code ================================== CodeQL has a large selection of classes for working with Java statements and expressions. .. _Expr: https://help.semmle.com/qldoc/java/semmle/code/java/Expr.qll/type.Expr$Expr.html .. _Stmt: https://help.semmle.com/qldoc/java/semmle/code/java/Statement.qll/type.Statement$Stmt.html .. _VarAccess: https://help.semmle.com/qldoc/java/semmle/code/java/Expr.qll/type.Expr$VarAccess.html .. _SwitchCase: https://help.semmle.com/qldoc/java/semmle/code/java/Statement.qll/type.Statement$SwitchCase.html .. _TypeAccess: https://help.semmle.com/qldoc/java/semmle/code/java/Expr.qll/type.Expr$TypeAccess.html .. _Member: https://help.semmle.com/qldoc/java/semmle/code/java/Member.qll/type.Member$Member.html .. _Literal: https://help.semmle.com/qldoc/java/semmle/code/java/Expr.qll/type.Expr$Literal.html Statement classes ----------------- This table lists all subclasses of `Stmt`_. +------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------+---------------------------------------------+ | Statement syntax | CodeQL class | Superclasses | Remarks | +========================================================================+===========================================================================================================================================================+===================================+=============================================+ | ``;`` | `EmptyStmt `__ | | | +------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------+---------------------------------------------+ | `Expr`_ ``;`` | `ExprStmt `__ | | | +------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------+---------------------------------------------+ | ``{`` `Stmt`_ ``... }`` | `Block `__ | | | +------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------+---------------------------------------------+ | ``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 example | CodeQL class | Superclasses | Remarks | +===========================+=================+=====================+===================================================+ | ``x++`` | ``PostIncExpr`` | ``UnaryAssignExpr`` | | +---------------------------+-----------------+---------------------+---------------------------------------------------+ | ``x--`` | ``PostDecExpr`` | ``UnaryAssignExpr`` | | +---------------------------+-----------------+---------------------+---------------------------------------------------+ | ``++x`` | ``PreIncExpr`` | ``UnaryAssignExpr`` | | +---------------------------+-----------------+---------------------+---------------------------------------------------+ | ``--x`` | ``PreDecExpr`` | ``UnaryAssignExpr`` | | +---------------------------+-----------------+---------------------+---------------------------------------------------+ | ``~x`` | ``BitNotExpr`` | ``BitwiseExpr`` | see below for other subclasses of ``BitwiseExpr`` | +---------------------------+-----------------+---------------------+---------------------------------------------------+ | ``-x`` | ``MinusExpr`` | | | +---------------------------+-----------------+---------------------+---------------------------------------------------+ | ``+x`` | ``PlusExpr`` | | | +---------------------------+-----------------+---------------------+---------------------------------------------------+ | ``!x`` | ``LogNotExpr`` | ``LogicExpr`` | see below for other subclasses of ``LogicExpr`` | +---------------------------+-----------------+---------------------+---------------------------------------------------+ Binary expressions ~~~~~~~~~~~~~~~~~~ All classes in this subsection are subclasses of `BinaryExpr `__. +---------------------------+--------------------+--------------------+ | Expression syntax example | CodeQL class | Superclasses | +===========================+====================+====================+ | ``x * y`` | ``MulExpr`` | | +---------------------------+--------------------+--------------------+ | ``x / y`` | ``DivExpr`` | | +---------------------------+--------------------+--------------------+ | ``x % y`` | ``RemExpr`` | | +---------------------------+--------------------+--------------------+ | ``x + y`` | ``AddExpr`` | | +---------------------------+--------------------+--------------------+ | ``x - y`` | ``SubExpr`` | | +---------------------------+--------------------+--------------------+ | ``x << y`` | ``LShiftExpr`` | | +---------------------------+--------------------+--------------------+ | ``x >> y`` | ``RShiftExpr`` | | +---------------------------+--------------------+--------------------+ | ``x >>> y`` | ``URShiftExpr`` | | +---------------------------+--------------------+--------------------+ | ``x && y`` | ``AndLogicalExpr`` | ``LogicExpr`` | +---------------------------+--------------------+--------------------+ | ``x || y`` | ``OrLogicalExpr`` | ``LogicExpr`` | +---------------------------+--------------------+--------------------+ | ``x < y`` | ``LTExpr`` | ``ComparisonExpr`` | +---------------------------+--------------------+--------------------+ | ``x > y`` | ``GTExpr`` | ``ComparisonExpr`` | +---------------------------+--------------------+--------------------+ | ``x <= y`` | ``LEExpr`` | ``ComparisonExpr`` | +---------------------------+--------------------+--------------------+ | ``x >= y`` | ``GEExpr`` | ``ComparisonExpr`` | +---------------------------+--------------------+--------------------+ | ``x == y`` | ``EQExpr`` | ``EqualityTest`` | +---------------------------+--------------------+--------------------+ | ``x != y`` | ``NEExpr`` | ``EqualityTest`` | +---------------------------+--------------------+--------------------+ | ``x & y`` | ``AndBitwiseExpr`` | ``BitwiseExpr`` | +---------------------------+--------------------+--------------------+ | ``x | y`` | ``OrBitwiseExpr`` | ``BitwiseExpr`` | +---------------------------+--------------------+--------------------+ | ``x ^ y`` | ``XorBitwiseExpr`` | ``BitwiseExpr`` | +---------------------------+--------------------+--------------------+ Assignment expressions ~~~~~~~~~~~~~~~~~~~~~~ All classes in this table are subclasses of `Assignment `__. +---------------------------+-----------------------+--------------+ | Expression syntax example | CodeQL class | Superclasses | +===========================+=======================+==============+ | ``x = y`` | ``AssignExpr`` | | +---------------------------+-----------------------+--------------+ | ``x += y`` | ``AssignAddExpr`` | ``AssignOp`` | +---------------------------+-----------------------+--------------+ | ``x -= y`` | ``AssignSubExpr`` | ``AssignOp`` | +---------------------------+-----------------------+--------------+ | ``x *= y`` | ``AssignMulExpr`` | ``AssignOp`` | +---------------------------+-----------------------+--------------+ | ``x /= y`` | ``AssignDivExpr`` | ``AssignOp`` | +---------------------------+-----------------------+--------------+ | ``x %= y`` | ``AssignRemExpr`` | ``AssignOp`` | +---------------------------+-----------------------+--------------+ | ``x &= y`` | ``AssignAndExpr`` | ``AssignOp`` | +---------------------------+-----------------------+--------------+ | ``x |= y`` | ``AssignOrExpr`` | ``AssignOp`` | +---------------------------+-----------------------+--------------+ | ``x ^= y`` | ``AssignXorExpr`` | ``AssignOp`` | +---------------------------+-----------------------+--------------+ | ``x <<= y`` | ``AssignLShiftExpr`` | ``AssignOp`` | +---------------------------+-----------------------+--------------+ | ``x >>= y`` | ``AssignRShiftExpr`` | ``AssignOp`` | +---------------------------+-----------------------+--------------+ | ``x >>>= y`` | ``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 `__. 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 `__ |   | +------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------+