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 org.eclipse.golo.compiler.PackageAndClass; 014 015public final class ModuleImport extends GoloElement<ModuleImport> implements ToplevelGoloElement { 016 017 private final PackageAndClass packageAndClass; 018 private final boolean implicit; 019 020 private ModuleImport(PackageAndClass packageAndClass, boolean implicit) { 021 super(); 022 this.packageAndClass = packageAndClass; 023 this.implicit = implicit; 024 } 025 026 public static ModuleImport implicit(Object name) { 027 return new ModuleImport(PackageAndClass.of(name), true); 028 } 029 030 public static ModuleImport of(Object name) { 031 if (name instanceof ModuleImport) { 032 return (ModuleImport) name; 033 } 034 return new ModuleImport(PackageAndClass.of(name), false); 035 } 036 037 protected ModuleImport self() { return this; } 038 039 public PackageAndClass getPackageAndClass() { 040 return packageAndClass; 041 } 042 043 public boolean isImplicit() { 044 return this.implicit; 045 } 046 047 /** 048 * {@inheritDoc} 049 */ 050 @Override 051 public String toString() { 052 return "ModuleImport{" 053 + "packageAndClass=" + packageAndClass 054 + (implicit ? ", implicit" : "") 055 + '}'; 056 } 057 058 /** 059 * {@inheritDoc} 060 */ 061 @Override 062 public boolean equals(Object o) { 063 if (this == o) { return true; } 064 if (o == null || getClass() != o.getClass()) { return false; } 065 066 ModuleImport that = (ModuleImport) o; 067 return packageAndClass.equals(that.packageAndClass); 068 } 069 070 /** 071 * {@inheritDoc} 072 */ 073 @Override 074 public int hashCode() { 075 return packageAndClass.hashCode(); 076 } 077 078 /** 079 * {@inheritDoc} 080 */ 081 @Override 082 public void accept(GoloIrVisitor visitor) { 083 visitor.visitModuleImport(this); 084 } 085 086 /** 087 * {@inheritDoc} 088 */ 089 @Override 090 protected void replaceElement(GoloElement<?> original, GoloElement<?> newElement) { 091 throw cantReplace(); 092 } 093}