/*
 * 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;

import java.util.Collection;

import org.antlr.v4.runtime.ParserRuleContext;

import io.shardingsphere.core.parsing.antlr.extractor.statement.handler.result.ExtractResult;
import io.shardingsphere.core.parsing.antlr.extractor.statement.handler.result.SQLTokenExtractResult;
import io.shardingsphere.core.parsing.antlr.extractor.statement.util.ASTUtils;
import io.shardingsphere.core.parsing.parser.token.IndexToken;
import io.shardingsphere.core.util.SQLUtil;

/**
 * Multiple index names extract handler.
 *
 * @author duhongjun
 */
public final class IndexesNameExtractHandler implements ASTExtractHandler {

    @Override
    public ExtractResult extract(final ParserRuleContext ancestorNode) {
        Collection<ParserRuleContext> result = ASTUtils.getAllDescendantNodes(ancestorNode, RuleName.INDEX_NAME);
        if (result.isEmpty()) {
            return null;
        }
        SQLTokenExtractResult extractResult = new SQLTokenExtractResult();
        for (ParserRuleContext each : result) {
            extractResult.getSqlTokens().add(new IndexToken(each.getStop().getStartIndex(), SQLUtil.getNameWithoutSchema(each.getText()), null));
        }
        return extractResult;
    }
}

@@ -766,16 +766,57 @@
 ntext;%0A%0A
+import com.google.common.base.Optional;%0A%0A
 import i
@@ -1339,16 +1339,20 @@
 ndler %7B%0A
+    
 %0A    @Ov
@@ -1369,16 +1369,25 @@
  public 
+Optional%3C
 ExtractR
@@ -1383,32 +1383,33 @@
 al%3CExtractResult
+%3E
  extract(final P
@@ -1479,22 +1479,30 @@
 ontext%3E 
-result
+indexNameNodes
  = ASTUt
@@ -1575,22 +1575,30 @@
     if (
-result
+indexNameNodes
 .isEmpty
@@ -1622,20 +1622,33 @@
  return 
-null
+Optional.absent()
 ;%0A      
@@ -1681,24 +1681,17 @@
 tResult 
-extractR
+r
 esult = 
@@ -1757,22 +1757,30 @@
  each : 
-result
+indexNameNodes
 ) %7B%0A    
@@ -1787,24 +1787,17 @@
         
-extractR
+r
 esult.ge
@@ -1939,17 +1939,27 @@
  return 
-e
+Optional.%3CE
 xtractRe
@@ -1962,16 +1962,27 @@
 ctResult
+%3Eof(result)
 ;%0A    %7D%0A

use optional for checkstyle