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 org.eclipse.golo.compiler.PackageAndClass; 013import org.eclipse.golo.compiler.parser.GoloASTNode; 014 015 016public final class UnionValue extends TypeWithMembers { 017 018 UnionValue(Union union, String name) { 019 super(name); 020 setParentNode(union); 021 } 022 023 @Override 024 public UnionValue ofAST(GoloASTNode node) { 025 super.ofAST(node); 026 return this; 027 } 028 029 @Override 030 public PackageAndClass getPackageAndClass() { 031 return getUnion().getPackageAndClass().createInnerClass(getName()); 032 } 033 034 public Union getUnion() { 035 return (Union) getParentNode().get(); 036 } 037 038 protected String getFactoryDelegateName() { 039 return getUnion().getPackageAndClass().toString() + "." + getName(); 040 } 041 042 @Override 043 protected void setParentNode(GoloElement parent) { 044 if (!(parent instanceof Union)) { 045 throw new IllegalArgumentException("UnionValue can only be defined in a Union"); 046 } 047 super.setParentNode(parent); 048 } 049 050 @Override 051 public void accept(GoloIrVisitor visitor) { 052 visitor.visitUnionValue(this); 053 } 054} 055