src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/BlockStatement.java

Print this page

        

*** 34,67 **** public class BlockStatement extends Statement { private static final long serialVersionUID = 1L; /** Block to execute. */ private final Block block; /** * Constructor * * @param block the block to execute */ public BlockStatement(final Block block) { ! this(block.getFirstStatementLineNumber(), block); } /** * Constructor * * @param lineNumber line number * @param block the block to execute */ ! public BlockStatement(final int lineNumber, final Block block) { super(lineNumber, block.getToken(), block.getFinish()); this.block = block; } ! private BlockStatement(final BlockStatement blockStatement, final Block block) { super(blockStatement); this.block = block; } /** * Use this method to create a block statement meant to replace a single statement. * @param stmt the statement to replace --- 34,71 ---- 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, true); } /** * Constructor * * @param lineNumber line number * @param block the block to execute */ ! 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, 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,97 **** * @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)); } @Override public boolean isTerminal() { return block.isTerminal(); } @Override public Node accept(final NodeVisitor<? extends LexicalContext> visitor) { if (visitor.enterBlockStatement(this)) { return visitor.leaveBlockStatement(setBlock((Block)block.accept(visitor))); } --- 84,105 ---- * @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), 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,126 **** */ public BlockStatement setBlock(final Block block) { if (this.block == block) { return this; } ! return new BlockStatement(this, block); } } --- 127,134 ---- */ public BlockStatement setBlock(final Block block) { if (this.block == block) { return this; } ! return new BlockStatement(this, block, synthetic); } }