< prev index next >

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

Print this page

        

*** 33,44 **** */ @Immutable public final class CatchNode extends Statement { private static final long serialVersionUID = 1L; ! /** Exception identifier. */ ! private final IdentNode exception; /** Exception condition. */ private final Expression exceptionCondition; /** Catch body. */ --- 33,44 ---- */ @Immutable public final class CatchNode extends Statement { private static final long serialVersionUID = 1L; ! /** Exception binding identifier or binding pattern. */ ! private final Expression exception; /** Exception condition. */ private final Expression exceptionCondition; /** Catch body. */
*** 50,74 **** * Constructors * * @param lineNumber lineNumber * @param token token * @param finish finish ! * @param exception variable name of exception * @param exceptionCondition exception condition * @param body catch body * @param isSyntheticRethrow true if this node is a synthetically generated rethrow node. */ ! public CatchNode(final int lineNumber, final long token, final int finish, final IdentNode exception, final Expression exceptionCondition, final Block body, final boolean isSyntheticRethrow) { super(lineNumber, token, finish); ! this.exception = exception == null ? null : exception.setIsInitializedHere(); this.exceptionCondition = exceptionCondition; this.body = body; this.isSyntheticRethrow = isSyntheticRethrow; } ! private CatchNode(final CatchNode catchNode, final IdentNode exception, final Expression exceptionCondition, final Block body, final boolean isSyntheticRethrow) { super(catchNode); this.exception = exception; this.exceptionCondition = exceptionCondition; this.body = body; --- 50,80 ---- * Constructors * * @param lineNumber lineNumber * @param token token * @param finish finish ! * @param exception variable name or pattern of exception * @param exceptionCondition exception condition * @param body catch body * @param isSyntheticRethrow true if this node is a synthetically generated rethrow node. */ ! public CatchNode(final int lineNumber, final long token, final int finish, final Expression exception, final Expression exceptionCondition, final Block body, final boolean isSyntheticRethrow) { super(lineNumber, token, finish); ! if (exception instanceof IdentNode) { ! this.exception = ((IdentNode) exception).setIsInitializedHere(); ! } else if ((exception instanceof LiteralNode) || (exception instanceof ObjectNode)) { ! this.exception = exception; ! } else { ! throw new IllegalArgumentException("invalid catch parameter"); ! } this.exceptionCondition = exceptionCondition; this.body = body; this.isSyntheticRethrow = isSyntheticRethrow; } ! private CatchNode(final CatchNode catchNode, final Expression exception, final Expression exceptionCondition, final Block body, final boolean isSyntheticRethrow) { super(catchNode); this.exception = exception; this.exceptionCondition = exceptionCondition; this.body = body;
*** 81,95 **** */ @Override public Node accept(final NodeVisitor<? extends LexicalContext> visitor) { if (visitor.enterCatchNode(this)) { return visitor.leaveCatchNode( ! setException((IdentNode)exception.accept(visitor)). ! setExceptionCondition(exceptionCondition == null ? null : (Expression)exceptionCondition.accept(visitor)). ! setBody((Block)body.accept(visitor))); } - return this; } @Override public boolean isTerminal() { --- 87,100 ---- */ @Override public Node accept(final NodeVisitor<? extends LexicalContext> visitor) { if (visitor.enterCatchNode(this)) { return visitor.leaveCatchNode( ! setException((Expression) exception.accept(visitor)). ! setExceptionCondition(exceptionCondition == null ? null : (Expression) exceptionCondition.accept(visitor)). ! setBody((Block) body.accept(visitor))); } return this; } @Override public boolean isTerminal() {
*** 107,121 **** } sb.append(')'); } /** * Get the identifier representing the exception thrown * @return the exception identifier */ ! public IdentNode getException() { ! return exception; } /** * Get the exception condition for this catch block * @return the exception condition --- 112,137 ---- } sb.append(')'); } /** + * Get the binding pattern representing the exception thrown + * + * @return the exception binding pattern + */ + public Expression getException() { + return exception; + } + + /** * Get the identifier representing the exception thrown + * * @return the exception identifier + * @throws ClassCastException if exception set is not binding identifier */ ! public IdentNode getExceptionIdentifier() { ! return (IdentNode) exception; } /** * Get the exception condition for this catch block * @return the exception condition
*** 144,160 **** return body; } /** * Resets the exception of a catch block ! * @param exception new exception * @return new catch node if changed, same otherwise */ ! public CatchNode setException(final IdentNode exception) { if (this.exception == exception) { return this; } return new CatchNode(this, exception, exceptionCondition, body, isSyntheticRethrow); } private CatchNode setBody(final Block body) { if (this.body == body) { --- 160,182 ---- return body; } /** * Resets the exception of a catch block ! * ! * @param exception new exception which can be binding identifier or binding ! * pattern * @return new catch node if changed, same otherwise */ ! public CatchNode setException(final Expression exception) { if (this.exception == exception) { return this; } + /*check if exception is legitimate*/ + if (!((exception instanceof IdentNode) || (exception instanceof LiteralNode) || (exception instanceof ObjectNode))) { + throw new IllegalArgumentException("invalid catch parameter"); + } return new CatchNode(this, exception, exceptionCondition, body, isSyntheticRethrow); } private CatchNode setBody(final Block body) { if (this.body == body) {
< prev index next >