public final class StatementUtils
extends java.lang.Object
Statement
class.Modifier and Type | Method and Description |
---|---|
static Statement |
getPredecessor(Statement stmt)
Returns the statement that comes before the specified statement.
|
static java.util.Collection<Statement> |
getSuccessors(Statement stmt)
Returns statements that go after the specified statement.
|
static Statement |
getTopParent(Statement stmt)
Returns the top level parent for the specified statement.
|
static java.util.Collection<Statement> |
getTopStatements(Statement stmt)
Returns the collection of top level statements of the specified one.
|
static DecStatement |
getVariableContainer(Statement stmt,
ru.ispras.fortress.expression.NodeVariable var)
Returns node that contains a declaration of the specified variable.
|
static DecStatement |
getVariableContainer(Statement node,
java.lang.String name)
Returns node that contains a declaration of variable with the specified name.
|
static boolean |
isLast(Statement stmt)
Checks whether the specified statement has successors or not.
|
static boolean |
isType(CfgStatementType type,
Statement... nodes)
Checks whether the specified nodes are of the specified type.
|
static boolean |
isType(java.lang.Enum<?> type,
Statement... nodes)
Checks whether the specified nodes are of the specified type.
|
static DecStatement |
nearStatement(Statement stmt)
Returns variable declaration container that is closest to the specified statement.
|
static Statement |
nearStatement(Statement stmt,
java.lang.Enum<?> type)
Returns closest statement of the specified type to the specified statement.
|
static void |
replace(Statement orig,
Statement substitute)
Replaces the first statement by the second statement.
|
public static boolean isType(java.lang.Enum<?> type, Statement... nodes)
type
- node typenodes
- nodes to be checkedtrue
if all the specified nodes are of the specified type,
false
otherwise.java.lang.IllegalArgumentException
- when either the specified type is null
or the specified array of nodes is empty.public static boolean isType(CfgStatementType type, Statement... nodes)
type
- node typenodes
- nodes to be checkedtrue
if all the specified nodes are of the specified type,
false
otherwise.java.lang.IllegalArgumentException
- when either the specified type is null
or the specified array of nodes is empty.public static java.util.Collection<Statement> getTopStatements(Statement stmt)
stmt
- The statement which top level sub-statements should be returned.java.lang.IllegalArgumentException
- when argument is null
.public static Statement getTopParent(Statement stmt)
stmt
- The statement which top level parent should be returned.public static Statement getPredecessor(Statement stmt)
stmt
- The statement which predecessor is returned.public static java.util.Collection<Statement> getSuccessors(Statement stmt)
stmt
- statement which successors are returnedjava.lang.IllegalArgumentException
- when argument is null
.public static boolean isLast(Statement stmt)
stmt
- statement that is checkedtrue
when the specified statement has no successors, false
otherwise.java.lang.IllegalArgumentException
- when argument is null
.public static void replace(Statement orig, Statement substitute)
Finds parent statement for the specified first statement and substitutes it by the second statement.
orig
- statement to be replacedsubstitute
- statement that substitutes the first argumentjava.lang.IllegalArgumentException
- when any of arguments is null
java.lang.IllegalArgumentException
- when first argument does not have parent statement.public static DecStatement getVariableContainer(Statement node, java.lang.String name)
node
- root node which and which child nodes are checkedname
- variable namenull
when the specified node and all the it's children
do not contain such declarationjava.lang.IllegalArgumentException
- when any of arguments is null
.public static DecStatement getVariableContainer(Statement stmt, ru.ispras.fortress.expression.NodeVariable var)
stmt
- The statement that (and which parents) should be checked for declaration.var
- The variable which declaration should be returned.null
if there is no such at any level.public static DecStatement nearStatement(Statement stmt)
stmt
- statement that is included in some degree to the resulting containerpublic static Statement nearStatement(Statement stmt, java.lang.Enum<?> type)
Closest statement is in terms of statement inclusion. For example, we have a
CfgModule
object x
that includes CfgProcess
object y
that
includes some statement. For that statement the closest statement of the
CfgStatementType.MODULE
type is an x
object.
stmt
- statement that is included in some degree to the resulting onetype
- type of the returned objectnull
if there is no such.RetrascopeException
- when there is no variable declaration container
of the specified type among parents of the specified statement.