public final class StatementUtils
extends java.lang.Object
Statement
class.Modifier and Type | Method and Description |
---|---|
static java.util.Collection<Statement> |
getSuccessors(Statement statement)
Returns statements that go after the specified statement.
|
static Statement |
getTopParent(Statement statement)
Returns the top level parent for the specified statement.
|
static java.util.Collection<Statement> |
getTopStatements(Statement statement)
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 statement)
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 |
nearDecStatement(Statement statement)
Returns variable declaration container that is closest to the specified statement.
|
static DecStatement |
nearDecStatement(Statement statement,
java.lang.Enum<?> containerType)
Returns closest declaration container of the specified type to the specified statement.
|
static void |
replace(Statement one,
Statement another)
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 statement)
statement
- The statement which top level sub-statements should be returned.java.lang.IllegalArgumentException
- when argument is null
.public static Statement getTopParent(Statement statement)
statement
- The statement which top level parent should be returned.public static java.util.Collection<Statement> getSuccessors(Statement statement)
statement
- statement which successors are returnedjava.lang.IllegalArgumentException
- when argument is null
.public static boolean isLast(Statement statement)
statement
- 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 one, Statement another)
Finds parent statement for the specified first statement and substitutes it by the second statement.
one
- statement to be replacedanother
- 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 nearDecStatement(Statement statement)
statement
- statement that is included in some degree to the resulting containerpublic static DecStatement nearDecStatement(Statement statement, java.lang.Enum<?> containerType)
Closest container 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 declaration container of the
CfgStatementType.MODULE
type is an x
object.
statement
- statement that is included in some degree to the resulting containercontainerType
- type of the returned objectnull
if there is no such.RetrascopeRuntimeException
- when there is no variable declaration container
of the specified type among parents of the specified statement.