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; 013import org.eclipse.golo.compiler.PackageAndClass; 014 015public final class ModuleImport extends GoloElement { 016 017 private final PackageAndClass packageAndClass; 018 private final boolean implicit; 019 020 ModuleImport(PackageAndClass packageAndClass, boolean implicit) { 021 super(); 022 this.packageAndClass = packageAndClass; 023 this.implicit = implicit; 024 } 025 026 ModuleImport(PackageAndClass packageAndClass) { 027 this(packageAndClass, false); 028 } 029 030 @Override 031 public ModuleImport ofAST(GoloASTNode node) { 032 super.ofAST(node); 033 return this; 034 } 035 036 public PackageAndClass getPackageAndClass() { 037 return packageAndClass; 038 } 039 040 public boolean isImplicit() { 041 return this.implicit; 042 } 043 044 @Override 045 public String toString() { 046 return "ModuleImport{" 047 + "packageAndClass=" + packageAndClass 048 + (implicit ? ", implicit" : "") 049 + '}'; 050 } 051 052 @Override 053 public boolean equals(Object o) { 054 if (this == o) { return true; } 055 if (o == null || getClass() != o.getClass()) { return false; } 056 057 ModuleImport that = (ModuleImport) o; 058 return packageAndClass.equals(that.packageAndClass); 059 } 060 061 @Override 062 public int hashCode() { 063 return packageAndClass.hashCode(); 064 } 065 066 @Override 067 public void accept(GoloIrVisitor visitor) { 068 visitor.visitModuleImport(this); 069 } 070 071 @Override 072 public void walk(GoloIrVisitor visitor) { 073 // nothing to do, not a composite 074 } 075 076 @Override 077 protected void replaceElement(GoloElement original, GoloElement newElement) { 078 throw cantReplace(); 079 } 080}