// Path: compiler/src/main/java/pl/edu/radomski/navigator/utils/AnnotationValidator.java
// public class AnnotationValidator {
//     protected static boolean isPublic(Element annotatedClass) {
//         return annotatedClass.getModifiers().contains(Modifier.PUBLIC);
//     }
// 
//     protected static boolean isPackage(Element annotatedClass) {
//         return !isPublic(annotatedClass) && !isProtected(annotatedClass) && !isPrivate(annotatedClass);
//     }
// 
//     protected static boolean isProtected(Element annotatedClass) {
//         return annotatedClass.getModifiers().contains(Modifier.PROTECTED);
//     }
// 
//     protected static boolean isPrivate(Element annotatedClass) {
//         return annotatedClass.getModifiers().contains(Modifier.PRIVATE);
//     }
// 
//     protected static boolean isAbstract(Element annotatedClass) {
//         return annotatedClass.getModifiers().contains(Modifier.ABSTRACT);
//     }
// 
//     protected static boolean hasOneOfModifiers(Element element, Modifier... modifiers) {
//         for (Modifier modifier : modifiers) {
//             if (element.getModifiers().contains(modifier)) {
//                 return true;
//             }
//         }
//         return false;
//     }
// 
// 
//     public static <T extends Class> boolean isAnnotated(Element variableElement, T t) {
//         return variableElement.getAnnotation(t) != null;
//     }
// }
// 
// Path: compiler/src/main/java/pl/edu/radomski/navigator/utils/CollectionUtils.java
// public class CollectionUtils {
// 
// 
//     public static <K, E> void addToHashMapWithList(Map<K, List<E>> map, K key, E element) {
//         if (map.get(key) == null) {
//             map.put(key, new ArrayList<E>());
//         }
//         map.get(key).add(element);
//     }
// 
//     public static <K, E> List<E> getElementFromMapWithList(Map<K, List<E>> map) {
//         ArrayList<E> list = new ArrayList<>();
//         for (List<E> element : map.values()) {
//             list.addAll(element);
//         }
//         return list;
//     }
// 
// }
// 
// Path: compiler/src/main/java/pl/edu/radomski/navigator/exceptions/VariableElementValidationException.java
// public class VariableElementValidationException extends Exception {
//     public ArrayList<String> errors;
// 
//     public VariableElementValidationException(ArrayList<String> errors) {
//         this.errors = errors;
//     }
// }
// 
// Path: compiler/src/main/java/pl/edu/radomski/navigator/param/ParamAnnotatedVariableElementValidator.java
// public class ParamAnnotatedVariableElementValidator extends AnnotationValidator {
//     private static final String ANNOTATION = "@" + Param.class.getCanonicalName();
// 
//     public static ArrayList<String> isValid(VariableElement variableElement) {
//         ArrayList<String> errors = new ArrayList<>();
//         if (isPrivate(variableElement)) {
//             errors.add(String.format("Fields annotated with %s must NOT be private.", ANNOTATION));
//         }
//         return errors;
//     }
// 
// }


import pl.edu.radomski.navigator.Navigable;
import pl.edu.radomski.navigator.Param;
import pl.edu.radomski.navigator.Result;
import pl.edu.radomski.navigator.exceptions.VariableElementValidationException;
import pl.edu.radomski.navigator.param.ParamAnnotatedVariableElementValidator;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
import pl.edu.radomski.navigator.utils.AnnotationValidator;
import pl.edu.radomski.navigator.utils.CollectionUtils;
/*
 * Navigator
 * Copyright (C)  2015 Adam Radomski
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
 * USA
 */

package pl.edu.radomski.navigator.navigable;




/**
 * Created by adam on 8/18/15.
 */
public class NavigableAnnotatedClass {


    public static NavigableAnnotatedClass from(TypeElement typeElement) throws VariableElementValidationException {

        Navigable annotation = typeElement.getAnnotation(Navigable.class);

        NavigableAnnotatedClass navigableAnnotatedClass = new NavigableAnnotatedClass(typeElement, annotation.group());
        HashMap<String, List<VariableElement>> paramAnnotatedFields = new HashMap<>();
        HashMap<String, List<VariableElement>> resultAnnotatedFields = new HashMap<>();
        ArrayList<String> errors;
        Param paramAnnotation;
        Result resultAnnotation;
        for (Element element : typeElement.getEnclosedElements()) {
            if (!(element instanceof VariableElement)) {
                continue;
            }
            VariableElement variableElement = (VariableElement) element;
// Path: compiler/src/main/java/pl/edu/radomski/navigator/utils/AnnotationValidator.java
// public class AnnotationValidator {
//     protected static boolean isPublic(Element annotatedClass) {
//         return annotatedClass.getModifiers().contains(Modifier.PUBLIC);
//     }
// 
//     protected static boolean isPackage(Element annotatedClass) {
//         return !isPublic(annotatedClass) && !isProtected(annotatedClass) && !isPrivate(annotatedClass);
//     }
// 
//     protected static boolean isProtected(Element annotatedClass) {
//         return annotatedClass.getModifiers().contains(Modifier.PROTECTED);
//     }
// 
//     protected static boolean isPrivate(Element annotatedClass) {
//         return annotatedClass.getModifiers().contains(Modifier.PRIVATE);
//     }
// 
//     protected static boolean isAbstract(Element annotatedClass) {
//         return annotatedClass.getModifiers().contains(Modifier.ABSTRACT);
//     }
// 
//     protected static boolean hasOneOfModifiers(Element element, Modifier... modifiers) {
//         for (Modifier modifier : modifiers) {
//             if (element.getModifiers().contains(modifier)) {
//                 return true;
//             }
//         }
//         return false;
//     }
// 
// 
//     public static <T extends Class> boolean isAnnotated(Element variableElement, T t) {
//         return variableElement.getAnnotation(t) != null;
//     }
// }
// 
// Path: compiler/src/main/java/pl/edu/radomski/navigator/utils/CollectionUtils.java
// public class CollectionUtils {
// 
// 
//     public static <K, E> void addToHashMapWithList(Map<K, List<E>> map, K key, E element) {
//         if (map.get(key) == null) {
//             map.put(key, new ArrayList<E>());
//         }
//         map.get(key).add(element);
//     }
// 
//     public static <K, E> List<E> getElementFromMapWithList(Map<K, List<E>> map) {
//         ArrayList<E> list = new ArrayList<>();
//         for (List<E> element : map.values()) {
//             list.addAll(element);
//         }
//         return list;
//     }
// 
// }
// 
// Path: compiler/src/main/java/pl/edu/radomski/navigator/exceptions/VariableElementValidationException.java
// public class VariableElementValidationException extends Exception {
//     public ArrayList<String> errors;
// 
//     public VariableElementValidationException(ArrayList<String> errors) {
//         this.errors = errors;
//     }
// }
// 
// Path: compiler/src/main/java/pl/edu/radomski/navigator/param/ParamAnnotatedVariableElementValidator.java
// public class ParamAnnotatedVariableElementValidator extends AnnotationValidator {
//     private static final String ANNOTATION = "@" + Param.class.getCanonicalName();
// 
//     public static ArrayList<String> isValid(VariableElement variableElement) {
//         ArrayList<String> errors = new ArrayList<>();
//         if (isPrivate(variableElement)) {
//             errors.add(String.format("Fields annotated with %s must NOT be private.", ANNOTATION));
//         }
//         return errors;
//     }
// 
// }


// Path: compiler/src/main/java/pl/edu/radomski/navigator/navigable/NavigableAnnotatedClass.java
import pl.edu.radomski.navigator.Navigable;
import pl.edu.radomski.navigator.Param;
import pl.edu.radomski.navigator.Result;
import pl.edu.radomski.navigator.exceptions.VariableElementValidationException;
import pl.edu.radomski.navigator.param.ParamAnnotatedVariableElementValidator;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
import pl.edu.radomski.navigator.utils.AnnotationValidator;
import pl.edu.radomski.navigator.utils.CollectionUtils;

/*
 * Navigator
 * Copyright (C)  2015 Adam Radomski
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
 * USA
 */

package pl.edu.radomski.navigator.navigable;




/**
 * Created by adam on 8/18/15.
 */
public class NavigableAnnotatedClass {


    public static NavigableAnnotatedClass from(TypeElement typeElement) throws VariableElementValidationException {

        Navigable annotation = typeElement.getAnnotation(Navigable.class);

        NavigableAnnotatedClass navigableAnnotatedClass = new NavigableAnnotatedClass(typeElement, annotation.group());
        HashMap<String, List<VariableElement>> paramAnnotatedFields = new HashMap<>();
        HashMap<String, List<VariableElement>> resultAnnotatedFields = new HashMap<>();
        ArrayList<String> errors;
        Param paramAnnotation;
        Result resultAnnotation;
        for (Element element : typeElement.getEnclosedElements()) {
            if (!(element instanceof VariableElement)) {
                continue;
            }
            VariableElement variableElement = (VariableElement) element;
            if (AnnotationValidator.isAnnotated(variableElement, Param.class)) {