src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/BlockStatement.java
Print this page
@@ -34,34 +34,38 @@
public class BlockStatement extends Statement {
private static final long serialVersionUID = 1L;
/** Block to execute. */
private final Block block;
+ /** is this a synthetic block? */
+ private boolean synthetic;
/**
* Constructor
*
* @param block the block to execute
*/
public BlockStatement(final Block block) {
- this(block.getFirstStatementLineNumber(), block);
+ this(block.getFirstStatementLineNumber(), block, true);
}
/**
* Constructor
*
* @param lineNumber line number
* @param block the block to execute
*/
- public BlockStatement(final int lineNumber, final Block block) {
+ public BlockStatement(final int lineNumber, final Block block, final boolean synthetic) {
super(lineNumber, block.getToken(), block.getFinish());
this.block = block;
+ this.synthetic = synthetic;
}
- private BlockStatement(final BlockStatement blockStatement, final Block block) {
+ private BlockStatement(final BlockStatement blockStatement, final Block block, final boolean synthetic) {
super(blockStatement);
this.block = block;
+ this.synthetic = synthetic;
}
/**
* Use this method to create a block statement meant to replace a single statement.
* @param stmt the statement to replace
@@ -80,18 +84,22 @@
* @param newStmts the statements for the new block statement
* @return a block statement with the new statements. It will have the line number, and token of the
* original statement.
*/
public static BlockStatement createReplacement(final Statement stmt, final int finish, final List<Statement> newStmts) {
- return new BlockStatement(stmt.getLineNumber(), new Block(stmt.getToken(), finish, newStmts));
+ return new BlockStatement(stmt.getLineNumber(), new Block(stmt.getToken(), finish, newStmts), true);
}
@Override
public boolean isTerminal() {
return block.isTerminal();
}
+ public boolean isSynthetic() {
+ return synthetic;
+ }
+
@Override
public Node accept(final NodeVisitor<? extends LexicalContext> visitor) {
if (visitor.enterBlockStatement(this)) {
return visitor.leaveBlockStatement(setBlock((Block)block.accept(visitor)));
}
@@ -119,8 +127,8 @@
*/
public BlockStatement setBlock(final Block block) {
if (this.block == block) {
return this;
}
- return new BlockStatement(this, block);
+ return new BlockStatement(this, block, synthetic);
}
}