public void process(TemplateMetaModelPlugin plugin) throws ProcessingException { // TemplatesMetaModel metaModel = application.getChild(TemplatesMetaModel.KEY); // Evict templates that are out of date log.log("Synchronizing existing templates " + templates.keySet()); for (Iterator<Template<?>> i = templates.values().iterator(); i.hasNext(); ) { Template<?> template = i.next(); FileObject resource = application.resolveResource(TemplatesMetaModel.LOCATION, template.getRelativePath()); if (resource == null) { // That will generate a template not found error i.remove(); log.log("Detected template removal " + template.getRelativePath()); } else if (resource.getLastModified() > template.getLastModified()) { // That will force the regeneration of the template i.remove(); log.log("Detected stale template " + template.getRelativePath()); } else { log.log("Template " + template.getRelativePath() + " is valid"); } } // Build missing templates log.log("Building missing templates"); Map<Path.Relative, Template<?>> copy = new HashMap<Path.Relative, Template<?>>(templates); for (TemplateMetaModel templateMeta : metaModel) { Template<?> template = copy.get(templateMeta.getPath()); if (template == null) { log.log("Compiling template " + templateMeta.getPath()); ModelTemplateProcessContext compiler = new ModelTemplateProcessContext( templateMeta, new HashMap<Path, Template<?>>(copy), application.getProcessingContext()); Collection<Template<?>> resolved = compiler.resolve(templateMeta); for (Template<?> added : resolved) { copy.put(added.getRelativePath(), added); } } } templates = copy; // Generate missing files from template for (Template<?> template : templates.values()) { // Path originPath = template.getOrigin(); TemplateMetaModel templateMeta = metaModel.get(originPath); // // We compute the class elements from the field elements (as eclipse will make the // relationship) Set<Name> types = new LinkedHashSet<Name>(); for (TemplateRefMetaModel ref : templateMeta.getRefs()) { ElementHandle.Field handle = ref.getHandle(); types.add(handle.getFQN()); } final Element[] elements = new Element[types.size()]; int index = 0; for (Name type : types) { elements[index++] = application.getProcessingContext().getTypeElement(type); } // If CCE that would mean there is an internal bug TemplateProvider<?> provider = (TemplateProvider<?>) plugin.providers.get(template.getRelativePath().getExt()); // Resolve the qualified class resolvedQualified(provider, template, elements); // resolveScript(template, plugin, elements); } }