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 static java.util.Objects.requireNonNull; 014 015public final class Member extends GoloElement<Member> { 016 017 private final String name; 018 019 private Member(String name) { 020 super(); 021 this.name = requireNonNull(name); 022 } 023 024 public static Member of(Object o) { 025 if (o instanceof Member) { 026 return (Member) o; 027 } 028 return new Member(o.toString()); 029 } 030 031 protected Member self() { return this; } 032 033 public String getName() { 034 return name; 035 } 036 037 public boolean isPublic() { 038 return !name.startsWith("_"); 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 protected void replaceElement(GoloElement<?> original, GoloElement<?> newElement) { 054 throw cantReplace(original, newElement); 055 } 056 057 /** 058 * {@inheritDoc} 059 */ 060 @Override 061 public String toString() { 062 return String.format("<%s>", name); 063 } 064}