/*
 * #%L
 * Wisdom-Framework
 * %%
 * Copyright (C) 2013 - 2015 Wisdom Framework
 * %%
 * 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.
 * #L%
 */
package org.wisdom.source.ast.visitor;

import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
import com.github.javaparser.ast.expr.AnnotationExpr;
import com.github.javaparser.ast.type.ClassOrInterfaceType;
import com.github.javaparser.ast.visitor.GenericVisitorAdapter;
import org.wisdom.api.Controller;
import org.wisdom.api.DefaultController;

import java.util.List;

import static java.util.Collections.EMPTY_LIST;

/**
 * Visit @{ClassOrInterfaceDeclaration} and to know if the visited class is a Wisdom Controller.
 *
 * @author barjo
 */
public class ClassSourceVisitor extends GenericVisitorAdapter<Boolean,Object>{

    private static final String CONTROL_ANNO_NAME = org.wisdom.api.annotations.Controller.class.getSimpleName();

    public Boolean visit(ClassOrInterfaceDeclaration n, Object arg) {
        List<AnnotationExpr> annos = n.getAnnotations() == null  ? EMPTY_LIST : n.getAnnotations();

        for(AnnotationExpr anno: annos){
            if(anno.getName().getName().equals(CONTROL_ANNO_NAME)){
                return true;
            }

        }

        List<ClassOrInterfaceType> extd = n.getExtends() == null ? EMPTY_LIST:n.getExtends();

        for(ClassOrInterfaceType ctype : extd){
            if(ctype.getName().equals(DefaultController.class.getSimpleName())){
                return true;
            }
        }

        extd = n.getImplements() == null ? EMPTY_LIST : n.getImplements();

        for(ClassOrInterfaceType ctype : extd){
            if(ctype.getName().equals(Controller.class.getSimpleName())){
                return true;
            }
        }

        return false;
    }
}

@@ -1411,73 +1411,488 @@
     
-public Boolean visit(ClassOrInterfaceDeclaration n, Object arg) %7B
+/**%0A     * Visit the Class declaration and return true if it corresponds to a wisdom controller.%0A     *%0A     * @param declaration The class declaration created by the JavaParser.%0A     * @param extra Extra out value argument, not used here.%0A     * @return %3Ccode%3Etrue%3C/code%3E if the declaration correspond to a wisdom controller, %3Ccode%3Efalse%3C/code%3E otherwise.%0A     */%0A    public Boolean visit(ClassOrInterfaceDeclaration declaration, Object extra) %7B%0A%0A        //noinspection unchecked
 %0A   
@@ -1925,16 +1925,26 @@
 annos = 
+declaratio
 n.getAnn
@@ -1974,24 +1974,34 @@
 MPTY_LIST : 
+declaratio
 n.getAnnotat
@@ -2165,32 +2165,65 @@
   %7D%0A%0A        %7D%0A%0A
+        //noinspection unchecked%0A
         List%3CCla
@@ -2241,27 +2241,38 @@
 ceType%3E extd
+s
  = 
+declaratio
 n.getExtends
@@ -2295,16 +2295,26 @@
 TY_LIST:
+declaratio
 n.getExt
@@ -2359,32 +2359,33 @@
 ype ctype : extd
+s
 )%7B%0A            i
@@ -2498,32 +2498,65 @@
    %7D%0A        %7D%0A%0A
+        //noinspection unchecked%0A
         extd = n
@@ -2551,19 +2551,30 @@
     extd
+s
  = 
+declaratio
 n.getImp
@@ -2606,16 +2606,26 @@
 _LIST : 
+declaratio
 n.getImp
@@ -2681,16 +2681,17 @@
 e : extd
+s
 )%7B%0A     

Improve Javadoc