/*
 * 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.antler.phrase.visitor.oracle;

import java.util.List;

import org.antlr.v4.runtime.ParserRuleContext;

import io.shardingsphere.core.parsing.antler.phrase.visitor.PhraseVisitor;
import io.shardingsphere.core.parsing.antler.sql.ddl.AlterTableStatement;
import io.shardingsphere.core.parsing.antler.sql.ddl.ColumnDefinition;
import io.shardingsphere.core.parsing.antler.utils.TreeUtils;
import io.shardingsphere.core.parsing.antler.utils.VisitorUtils;
import io.shardingsphere.core.parsing.parser.sql.SQLStatement;

public class OracleModifyColumnVisitor implements PhraseVisitor {

    /** Visit modify column node.
     * @param ancestorNode ancestor node of ast
     * @param statement sql statement
     */
    @Override
    public void visit(final ParserRuleContext ancestorNode, final SQLStatement statement) {
        AlterTableStatement alterStatement = (AlterTableStatement) statement;
        
        ParserRuleContext modifyColumnCtx = TreeUtils.getFirstChildByRuleName(ancestorNode,
                "modifyColumn");
        if (null == modifyColumnCtx) {
            return;
        }

        List<ParserRuleContext> columnNodes = TreeUtils.getAllDescendantByRuleName(modifyColumnCtx, "modifyColProperties");
        if (null == columnNodes) {
            return;
        }

        for (final ParserRuleContext each : columnNodes) {
            // it`s not columndefinition, but can call this method
            ColumnDefinition column = VisitorUtils.visitColumnDefinition(each);
            if (null != column) {
                alterStatement.getUpdateColumns().put(column.getName(), column);
            }
        }
    }

}

@@ -1549,20 +1549,16 @@
 nt;%0A    
-    
 %0A       
@@ -1558,16 +1558,21 @@
         
+List%3C
 ParserRu
@@ -1580,16 +1580,17 @@
 eContext
+%3E
  modifyC
@@ -1597,16 +1597,17 @@
 olumnCtx
+s
  = TreeU
@@ -1618,18 +1618,21 @@
 .get
-FirstChild
+AllDescendant
 ByRu
@@ -1720,16 +1720,17 @@
 olumnCtx
+s
 ) %7B%0A    
@@ -1747,33 +1747,110 @@
 turn;%0A        %7D%0A
+    
 %0A
+        for (ParserRuleContext modifyColumnCtx : modifyColumnCtxs) %7B%0A    
         List%3CPar
@@ -1957,32 +1957,36 @@
 ties%22);%0A        
+    
 if (null == colu
@@ -2000,32 +2000,36 @@
 ) %7B%0A            
+    
 return;%0A        
@@ -2028,19 +2028,31 @@
         
-%7D%0A%0A
+    %7D%0A    %0A    
         
@@ -2094,32 +2094,36 @@
  columnNodes) %7B%0A
+    
             // i
@@ -2185,16 +2185,20 @@
         
+    
 ColumnDe
@@ -2261,32 +2261,36 @@
 h);%0A            
+    
 if (null != colu
@@ -2311,16 +2311,20 @@
         
+  
+  
 alterSta
@@ -2380,16 +2380,34 @@
 olumn);%0A
+                %7D%0A
         

fix oracle alter table modify column