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.parser.GoloASTNode; 013 014import static java.util.Objects.requireNonNull; 015 016public final class Member extends GoloElement { 017 private final String name; 018 019 Member(String name) { 020 super(); 021 this.name = requireNonNull(name); 022 } 023 024 public String getName() { 025 return name; 026 } 027 028 public boolean isPublic() { 029 return !name.startsWith("_"); 030 } 031 032 /** 033 * @inheritDoc 034 */ 035 @Override 036 public Member ofAST(GoloASTNode node) { 037 super.ofAST(node); 038 return this; 039 } 040 041 /** 042 * @inheritDoc 043 */ 044 @Override 045 public void accept(GoloIrVisitor visitor) { 046 visitor.visitMember(this); 047 } 048 049 /** 050 * @inheritDoc 051 */ 052 @Override 053 public void walk(GoloIrVisitor visitor) { 054 // do nothing, not a container 055 } 056 057 058 /** 059 * @inheritDoc 060 */ 061 @Override 062 protected void replaceElement(GoloElement original, GoloElement newElement) { 063 throw cantReplace(original, newElement); 064 } 065 066 /** 067 * @inheritDoc 068 */ 069 @Override 070 public String toString() { 071 return name; 072 } 073}