/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.shardingsphere.sql.parser.binder.statement.ddl;

import lombok.Getter;
import org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext;
import org.apache.shardingsphere.sql.parser.binder.statement.CommonSQLStatementContext;
import org.apache.shardingsphere.sql.parser.binder.type.IndexAvailable;
import org.apache.shardingsphere.sql.parser.binder.type.TableAvailable;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropIndexStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.sqlserver.SQLServerStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.sqlserver.ddl.SQLServerDropIndexStatement;

import java.util.Collection;
import java.util.Collections;

/**
 * Drop index statement context.
 */
@Getter
public final class DropIndexStatementContext extends CommonSQLStatementContext<DropIndexStatement> implements TableAvailable, IndexAvailable {
    
    private final TablesContext tablesContext;
    
    public DropIndexStatementContext(final DropIndexStatement sqlStatement) {
        super(sqlStatement);
        tablesContext = new TablesContext(getTable(sqlStatement));
    }
    
    @Override
    public Collection<SimpleTableSegment> getAllTables() {
        return null == getTable(getSqlStatement()) ? Collections.emptyList() : Collections.singletonList(getTable(getSqlStatement()));
    }
    
    @Override
    public Collection<IndexSegment> getIndexes() {
        return getSqlStatement().getIndexes();
    }
    
    private SimpleTableSegment getTable(final DropIndexStatement sqlStatement) {
        return sqlStatement instanceof SQLServerStatement ? ((SQLServerDropIndexStatement) sqlStatement).getTable() : null;
    }
}

@@ -1474,213 +1474,8 @@
 ent;
-%0Aimport org.apache.shardingsphere.sql.parser.sql.dialect.statement.sqlserver.SQLServerStatement;%0Aimport org.apache.shardingsphere.sql.parser.sql.dialect.statement.sqlserver.ddl.SQLServerDropIndexStatement;
 %0A%0Aim
@@ -1930,25 +1930,16 @@
 Context(
-getTable(
 sqlState
@@ -1942,16 +1942,26 @@
 tatement
+.getTable(
 ));%0A    
@@ -2063,25 +2063,16 @@
 null == 
-getTable(
 getSqlSt
@@ -2080,16 +2080,26 @@
 tement()
+.getTable(
 ) ? Coll
@@ -2146,25 +2146,16 @@
 tonList(
-getTable(
 getSqlSt
@@ -2163,16 +2163,26 @@
 tement()
+.getTable(
 ));%0A    
@@ -2310,222 +2310,6 @@
   %7D%0A
-    %0A    private SimpleTableSegment getTable(final DropIndexStatement sqlStatement) %7B%0A        return sqlStatement instanceof SQLServerStatement ? ((SQLServerDropIndexStatement) sqlStatement).getTable() : null;%0A    %7D%0A
 %7D%0A

modify drop index statement getTable method