Package asteroid.utils
Class StatementUtils
- java.lang.Object
-
- asteroid.utils.StatementUtils
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classStatementUtils.GroupRepresent a group of statements grouped by a given label.static classStatementUtils.LabelThis class helps to identify a list of statements.
-
Constructor Summary
Constructors Constructor Description StatementUtils()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description List<StatementUtils.Group>applyToStatementsByLabel(List<StatementUtils.Group> source, Map<String,Closure<Statement>> mappings)If you have a given list ofStatementUtils.Groupyou can apply a set of transformations on certain statements within a given group.List<Statement>applyToStatementsByLabelFlatten(List<StatementUtils.Group> source, Map<String,Closure<Statement>> mappings)If you have a given list ofStatementUtils.Groupyou can apply a set of transformations on certain statements within a given group.StatementUtils.LabelextractLabelFrom(Statement stmt)If you would like to take the text from a label in your codeList<StatementUtils.Group>groupStatementsByLabel(BlockStatement blockStmt)Use this function to group expression statements found within a given block statement.
-
-
-
Method Detail
-
groupStatementsByLabel
public List<StatementUtils.Group> groupStatementsByLabel(BlockStatement blockStmt)
Use this function to group expression statements found within a given block statement. Statements will be group inStatementUtils.Groupinstances.- Parameters:
blockStmt- the block statement where the statements we want to group are- Returns:
- a list of
StatementUtils.Group - Since:
- 0.1.5
-
extractLabelFrom
public StatementUtils.Label extractLabelFrom(Statement stmt)
If you would like to take the text from a label in your codecheck: 'is greater than' //...- Parameters:
stmt- The statement we would like to take a label from- Returns:
- an instance of
StatementUtils.Label
-
applyToStatementsByLabelFlatten
public List<Statement> applyToStatementsByLabelFlatten(List<StatementUtils.Group> source, Map<String,Closure<Statement>> mappings)
If you have a given list ofStatementUtils.Groupyou can apply a set of transformations on certain statements within a given group. Lets say we have group all statements in a method and we would like to apply a transformation to statements in the group identified with 'check':
This particular transformation will do nothing, it only returns the same statement.['check': { Group group, ExpressionStatement stmt -> stmt }]- Parameters:
source- the list of groups we want to operate overmappings- a map. Keys are label names and values are closures transforming every statement of the identified group.- Returns:
- all statements (transformed and not transformed) returned in order.
-
applyToStatementsByLabel
public List<StatementUtils.Group> applyToStatementsByLabel(List<StatementUtils.Group> source, Map<String,Closure<Statement>> mappings)
If you have a given list ofStatementUtils.Groupyou can apply a set of transformations on certain statements within a given group. Lets say we have group all statements in a method and we would like to apply a transformation to statements in the group identified with 'check':
This particular transformation will do nothing, it only returns the same statement.['check': { Group group, ExpressionStatement stmt -> stmt }]- Parameters:
source- the list of groups we want to operate overmappings- a map. Keys are label names and values are closures transforming every statement of the identified group.- Returns:
- all statements in their correspondent group.
-
-