001/* 002 * Copyright (c) 2012-2017 Institut National des Sciences Appliquées de Lyon (INSA-Lyon) 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 */ 009 010package org.eclipse.golo.compiler.ir; 011 012import java.util.Objects; 013import org.eclipse.golo.compiler.parser.GoloASTNode; 014 015public final class ThrowStatement extends GoloStatement { 016 017 private GoloStatement expressionStatement; 018 019 ThrowStatement(GoloStatement expressionStatement) { 020 super(); 021 setExpressionStatement(expressionStatement); 022 } 023 024 @Override 025 public void accept(GoloIrVisitor visitor) { 026 visitor.visitThrowStatement(this); 027 } 028 029 @Override 030 public void walk(GoloIrVisitor visitor) { 031 expressionStatement.accept(visitor); 032 } 033 034 @Override 035 protected void replaceElement(GoloElement original, GoloElement newElement) { 036 if (Objects.equals(original, expressionStatement) && newElement instanceof ExpressionStatement) { 037 setExpressionStatement((ExpressionStatement) newElement); 038 } else { 039 throw cantReplace(original, newElement); 040 } 041 } 042 043 public GoloStatement getExpressionStatement() { 044 return expressionStatement; 045 } 046 047 private void setExpressionStatement(GoloStatement stat) { 048 this.expressionStatement = stat; 049 makeParentOf(stat); 050 } 051 052 @Override 053 public ThrowStatement ofAST(GoloASTNode node) { 054 super.ofAST(node); 055 return this; 056 } 057}