package com.chenyang.druid.sql.ast.statement;

import com.chenyang.druid.sql.ast.SQLExpr;
import com.chenyang.druid.sql.ast.SQLName;
import com.chenyang.druid.sql.ast.SQLObjectImpl;
import com.chenyang.druid.sql.visitor.SQLASTVisitor;

public class SQLAlterTableRename extends SQLObjectImpl implements SQLAlterTableItem {
   protected SQLExprTableSource to;

   public SQLAlterTableRename() {
   }

   public SQLAlterTableRename(SQLExpr to) {
      this.setTo(to);
   }

   public SQLExprTableSource getTo() {
      return this.to;
   }

   public SQLName getToName() {
      if (this.to == null) {
         return null;
      } else {
         SQLExpr expr = this.to.expr;
         return expr instanceof SQLName ? (SQLName)expr : null;
      }
   }

   public void setTo(SQLExprTableSource to) {
      if (to != null) {
         to.setParent(this);
      }

      this.to = to;
   }

   public void setTo(SQLExpr to) {
      this.setTo(new SQLExprTableSource(to));
   }

   protected void accept0(SQLASTVisitor visitor) {
      if (visitor.visit(this)) {
         this.acceptChild(visitor, this.to);
      }

      visitor.endVisit(this);
   }
}
