package com.axellience.vuegwt.client.definitions;

import com.axellience.vuegwt.client.VueComponent;

import java.util.HashMap;
import java.util.Map;

/**
 * A Cache for generated VueComponentDefinitions.
 * Using static initializer block, VueComponentDefinitions register an instance of themselves in
 * this Cache.
 * VueGWT then use this cache to get definitions for VueComponents.
 * @author Adrien Baron
 */
public class VueComponentDefinitionCache
{
    private static Map<Class<? extends VueComponent>, VueComponentDefinition>
        componentDefinitionsCache = new HashMap<>();

    public static void registerComponent(Class<? extends VueComponent> vueComponentClass,
        VueComponentDefinition componentDefinition)
    {
        componentDefinitionsCache.put(vueComponentClass, componentDefinition);
    }

    public static VueComponentDefinition getComponentDefinitionForClass(
        Class<? extends VueComponent> vueComponentClass)
    {
        VueComponentDefinition componentDefinition =
            componentDefinitionsCache.get(vueComponentClass);
        if (componentDefinition != null)
            return componentDefinition;

        throw new RuntimeException(
            "Couldn't find the given Component " + vueComponentClass.getCanonicalName() +
                ". Are you sure annotations are being processed?");
    }
}

@@ -1183,29 +1183,16 @@
 ception(
-%0A            
 %22Couldn'
@@ -1219,16 +1219,28 @@
 ponent %22
+%0A           
  + vueCo
@@ -1270,18 +1270,16 @@
 alName()
- +
 %0A       
@@ -1287,27 +1287,27 @@
     
-   
++
  %22. 
-A
+Make su
 re you
- sure
+r
  ann
@@ -1334,17 +1334,79 @@
 rocessed
-?
+, and that you added the -generateJsInteropExports flag to GWT.
 %22);%0A    

Improve error message when Component is not found in Cache