/*
 * Copyright 2016-2018 shardingsphere.io.
 * <p>
 * Licensed 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.
 * </p>
 */


package io.shardingsphere.core.parsing.antlr.extractor.statement.handler.result;

import java.util.LinkedList;
import java.util.List;

import io.shardingsphere.core.parsing.parser.sql.SQLStatement;
import io.shardingsphere.core.parsing.parser.token.SQLToken;
import lombok.Getter;

/**
 * SQL Tokens extract handler.
 * 
 * @author duhongjun
 */
@Getter
public class SQLTokenExtractResult implements ExtractResult {
    
    private List<SQLToken> sqlTokens = new LinkedList<>();
    
    @Override
    public void inject(SQLStatement statement) {
        for(SQLToken each : sqlTokens) {
            statement.getSQLTokens().add(each);
        }
    }
}

@@ -812,16 +812,146 @@
 tement;%0A
+import io.shardingsphere.core.parsing.parser.sql.ddl.DDLStatement;%0Aimport io.shardingsphere.core.parsing.parser.token.IndexToken;%0A
 import i
@@ -999,24 +999,24 @@
 n.SQLToken;%0A
-
 import lombo
@@ -1160,21 +1160,16 @@
 esult %7B%0A
-    %0A
     priv
@@ -1299,40 +1299,556 @@
     
-for(SQLToken each : sqlTokens) %7B
+String tableName = %22%22;%0A        if(statement instanceof DDLStatement) %7B%0A            DDLStatement ddlStatement = (DDLStatement) statement;%0A            tableName = ddlStatement.getTables().isEmpty() ? %22%22 : ddlStatement.getTables().getSingleTableName();%0A        %7D%0A        for(SQLToken each : sqlTokens) %7B%0A            if(each instanceof IndexToken) %7B%0A                IndexToken indexToken = (IndexToken) each;%0A                if(null == indexToken.getTableName()) %7B%0A                    indexToken.setTableName(tableName);%0A                %7D%0A            %7D
 %0A   

update SQLTokenExtractResult