001/* 002 * Copyright (c) 2012-2018 Institut National des Sciences Appliquées de Lyon (INSA Lyon) and others 003 * 004 * This program and the accompanying materials are made available under the 005 * terms of the Eclipse Public License 2.0 which is available at 006 * http://www.eclipse.org/legal/epl-2.0. 007 * 008 * SPDX-License-Identifier: EPL-2.0 009 */ 010 011package gololang.ir; 012 013import java.util.List; 014 015/** 016 * Alternative nodes, such as `match` or `case`. 017 * <p> This interface is mainly a fluent builder for a {@link WhenClause} container. 018 */ 019public interface Alternatives<T extends GoloElement<?>> { 020 021 /** 022 * Defines a new alternative clause. 023 * 024 * <p>This is a builder method. 025 * 026 * @param cond an expression node defining the clause. 027 */ 028 Alternatives<T> when(Object cond); 029 030 /** 031 * Defines the action of the previous clause. 032 * 033 * <p>This is a builder method.</p> 034 * 035 * <p>It <em>must</em> be called after a call to {@code when}. For instance 036 * <pre class="listing"><code class="lang-java" data-lang="java"> 037 * alternative.when(condition).then(action); 038 * </code></pre> 039 * 040 * @param action the action to execute in this clause. Its type depends on the kind of alternative 041 * (i.e. the {@link WhenClause} constructed) 042 */ 043 Alternatives<T> then(Object action); 044 045 /** 046 * Defines the default alternative clause. 047 * 048 * <p>This is a builder method. 049 * 050 * @param action the action to execute in this clause. Its type depends on the kind of alternative 051 * (i.e. the {@link WhenClause} constructed) 052 */ 053 Alternatives<T> otherwise(Object action); 054 055 List<WhenClause<T>> getClauses(); 056 057 T getOtherwise(); 058}