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

import com.alibaba.druid.sql.ast.SQLExpr;
import com.alibaba.druid.sql.ast.SQLName;
import com.alibaba.druid.sql.ast.SQLObject;
import com.alibaba.druid.sql.ast.SQLReplaceable;
import com.alibaba.druid.sql.ast.SQLStatementImpl;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class SQLDescribeStatement extends SQLStatementImpl implements SQLReplaceable {
   protected SQLName object;
   protected SQLName column;
   protected boolean extended;
   protected boolean formatted;
   protected SQLObjectType objectType;
   protected List<SQLExpr> partition = new ArrayList();

   public SQLName getObject() {
      return this.object;
   }

   public void setObject(SQLName object) {
      this.object = object;
   }

   public SQLName getColumn() {
      return this.column;
   }

   public void setColumn(SQLName column) {
      if (column != null) {
         column.setParent(this);
      }

      this.column = column;
   }

   public List<SQLExpr> getPartition() {
      return this.partition;
   }

   public void setPartition(List<SQLExpr> partition) {
      this.partition = partition;
   }

   public SQLObjectType getObjectType() {
      return this.objectType;
   }

   public void setObjectType(SQLObjectType objectType) {
      this.objectType = objectType;
   }

   public boolean isExtended() {
      return this.extended;
   }

   public void setExtended(boolean extended) {
      this.extended = extended;
   }

   public boolean isFormatted() {
      return this.formatted;
   }

   public void setFormatted(boolean formatted) {
      this.formatted = formatted;
   }

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

      visitor.endVisit(this);
   }

   public List<SQLObject> getChildren() {
      return Arrays.asList(this.object, this.column);
   }

   public boolean replace(SQLExpr expr, SQLExpr target) {
      if (this.object == expr) {
         this.setObject((SQLName)target);
         return true;
      } else if (this.column == expr) {
         this.setColumn((SQLName)target);
         return true;
      } else {
         return false;
      }
   }
}
