package com.oracle.js.parser.ir;
import com.oracle.js.parser.ir.visitor.NodeVisitor;
import com.oracle.js.parser.ir.visitor.TranslatorNodeVisitor;
public class ImportNode extends Node {
private final LiteralNode<String> moduleSpecifier;
private final ImportClauseNode importClause;
private final FromNode from;
public ImportNode(final long token, final int start, final int finish, final LiteralNode<String> moduleSpecifier) {
this(token, start, finish, moduleSpecifier, null, null);
}
public ImportNode(final long token, final int start, final int finish, final ImportClauseNode importClause, final FromNode from) {
this(token, start, finish, null, importClause, from);
}
private ImportNode(final long token, final int start, final int finish, final LiteralNode<String> moduleSpecifier, ImportClauseNode importClause, FromNode from) {
super(token, start, finish);
this.moduleSpecifier = moduleSpecifier;
this.importClause = importClause;
this.from = from;
}
private ImportNode(final ImportNode node, final LiteralNode<String> moduleSpecifier, ImportClauseNode importClause, FromNode from) {
super(node);
this.moduleSpecifier = moduleSpecifier;
this.importClause = importClause;
this.from = from;
}
public LiteralNode<String> getModuleSpecifier() {
return moduleSpecifier;
}
public ImportClauseNode getImportClause() {
return importClause;
}
public FromNode getFrom() {
return from;
}
public ImportNode setModuleSpecifier(LiteralNode<String> moduleSpecifier) {
if (this.moduleSpecifier == moduleSpecifier) {
return this;
}
return new ImportNode(this, moduleSpecifier, importClause, from);
}
public ImportNode setImportClause(ImportClauseNode importClause) {
if (this.importClause == importClause) {
return this;
}
return new ImportNode(this, moduleSpecifier, importClause, from);
}
public ImportNode setFrom(FromNode from) {
if (this.from == from) {
return this;
}
return new ImportNode(this, moduleSpecifier, importClause, from);
}
@Override
@SuppressWarnings("unchecked")
public Node accept(NodeVisitor<? extends LexicalContext> visitor) {
if (visitor.enterImportNode(this)) {
LiteralNode<String> newModuleSpecifier = moduleSpecifier == null ? null
: (LiteralNode<String>) moduleSpecifier.accept(visitor);
ImportClauseNode newImportClause = importClause == null ? null
: (ImportClauseNode) importClause.accept(visitor);
FromNode newFrom = from == null ? null
: (FromNode) from.accept(visitor);
return visitor.leaveImportNode(
setModuleSpecifier(newModuleSpecifier).setImportClause(newImportClause).setFrom(newFrom));
}
return this;
}
@Override
public <R> R accept(TranslatorNodeVisitor<? extends LexicalContext, R> visitor) {
return visitor.enterImportNode(this);
}
@Override
public void toString(StringBuilder sb, boolean printType) {
sb.append("import");
sb.append(' ');
if (moduleSpecifier != null) {
moduleSpecifier.toString(sb, printType);
} else {
importClause.toString(sb, printType);
sb.append(' ');
from.toString(sb, printType);
}
sb.append(';');
}
}