package packIntrospec;

import java.awt.Color;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

public class Accueil
{

	// Démonstration de l'introspection
	
	
	public static void main(String[] args)
	{
		Sphere maSphere = new Sphere(45, 10, 23, 20, Color.green);
		System.out.println("maSphere est de classe " + maSphere.getClass()); // Précédé du mot Class
		System.out.println("maSphere est de classe " + maSphere.getClass().getName());
		System.out.println("maSphere hérite de " + maSphere.getClass().getSuperclass().getName());
		// Les champs de la sphère
		Field[] mesChamps = maSphere.getClass().getDeclaredFields();
		
		System.out.println("Les champs de " + maSphere.getClass().getName());
		for (Field monChamp : mesChamps)
		{
			System.out.println("Champ : " + monChamp.getName() + " de type " + monChamp.getType());
		}
		
		
		// Les accesseurs de la sphère
		Method[] mesMethodes = maSphere.getClass().getMethods();
		//Method[] mesMethodes = maSphere.getClass().getDeclaredMethods();
		System.out.println("Les méthodes de " + maSphere.getClass().getName() + ":");
		for (Method maMethode : mesMethodes)
		{
			System.out.print("Méthode : " + maMethode.getName() + "\t");
			if (Modifier.isAbstract(maMethode.getModifiers()))
			{
				System.out.print(" abstraite");
			}
			
			if (Modifier.isFinal(maMethode.getModifiers()))
			{
				System.out.print(" finale");
			}
			
			if (Modifier.isPrivate(maMethode.getModifiers()))
			{
				System.out.print(" privé");
			}
			
			if (Modifier.isProtected(maMethode.getModifiers()))
			{
				System.out.print(" protégé");
			}
			
			if (Modifier.isPublic(maMethode.getModifiers()))
			{
				System.out.print(" publique");
			}
			
			Class<?>[] mesParams = maMethode.getParameterTypes();

			System.out.print(" (");
			for (Class<?> monParam : mesParams)
			{
				System.out.print(monParam.getName() + ", ");
			}
			System.out.print(") ");
			
			System.out.print(" rend un " + maMethode.getReturnType());
			
			System.out.print("\n En une fois : " + maMethode.toGenericString());
			
			System.out.println("]");
			
		}
		testAnnotation();

	}
	
	public static void testAnnotation()
	{
		Sphere maSphere = new Sphere();
		Class<?> maClasse = maSphere.getClass();
		
		System.out.println("Liste de toutes les annotations de " + maClasse.getName());
		
		Annotation[] mesAnnotations = maClasse.getDeclaredAnnotations();
		for (Annotation monAnnotation : mesAnnotations)
		{
			System.out.println("Annotation : " + monAnnotation.annotationType().getName());
		}
		
		if (maClasse.isAnnotationPresent(Marque.class))
		{
			System.out.println("Il y a une marque sur la sphère");
			Annotation maMarque = maClasse.getAnnotation(Marque.class);
			
			
		}
		else
		{
			System.out.println("Pas d'annotation sur " + maClasse.getName());
		}
		
	}



}
