append("\"").append(path.getValue()).append("\","). append("0x").append(Long.toHexString(template.templateModel.getMD5())).append("L,"). append(path.getName()).append(".class,"). append(provider.getTemplateStubType().getName()).append(".class"). append(");\n");
append("\"").append(path.getValue()).append("\","). append("0x").append(Long.toHexString(template.templateModel.getMD5())).append("L,"). append(path.getName()).append(".class,"). append(provider.getTemplateStubType().getName()).append(".class"). append(");\n");
Class<?> clazz = context.getClassLoader().loadClass(resolved.getName().toString()); Field f = clazz.getField("DESCRIPTOR"); desc = (TemplateDescriptor)f.get(null);
public TemplatesDescriptor( ApplicationDescriptor application, ClassLoader loader, JSON config) throws Exception { ArrayList<BeanDescriptor> beans = new ArrayList<BeanDescriptor>(); List<TemplateDescriptor> templates = new ArrayList<TemplateDescriptor>(); // String packageName = config.getString("package"); Name pkg = Name.parse(packageName); // Load templates for (String fqn : config.getList("templates", String.class)) { Class<?> clazz = loader.loadClass(fqn); Field f = clazz.getField("DESCRIPTOR"); TemplateDescriptor descriptor = (TemplateDescriptor)f.get(null); templates.add(descriptor); juzu.impl.common.Path.Absolute path = (juzu.impl.common.Path.Absolute)juzu.impl.common.Path.parse(descriptor.getPath()); Path qualifier; if (pkg.isPrefix(path.getName())) { juzu.impl.common.Path.Relative relativePath = juzu.impl.common.Path.relative(path.getName().subName(pkg.size()), path.getExt()); qualifier = new PathLiteral(relativePath.getCanonical()); } else { qualifier = new PathLiteral(path.getCanonical()); } beans.add(BeanDescriptor.createFromImpl(Template.class, null, Arrays.<Annotation>asList(qualifier), descriptor.getType())); } // this.templates = templates; this.pkg = pkg; this.beans = beans; }
public TemplatesDescriptor( ApplicationDescriptor application, ClassLoader loader, JSON config) throws Exception { ArrayList<BeanDescriptor> beans = new ArrayList<BeanDescriptor>(); List<TemplateDescriptor> templates = new ArrayList<TemplateDescriptor>(); // String packageName = config.getString("package"); Name pkg = Name.parse(packageName); // Load templates for (String fqn : config.getList("templates", String.class)) { Class<?> clazz = loader.loadClass(fqn); Field f = clazz.getField("DESCRIPTOR"); TemplateDescriptor descriptor = (TemplateDescriptor)f.get(null); templates.add(descriptor); juzu.impl.common.Path.Absolute path = (juzu.impl.common.Path.Absolute)juzu.impl.common.Path.parse(descriptor.getPath()); Path qualifier; if (pkg.isPrefix(path.getName())) { juzu.impl.common.Path.Relative relativePath = juzu.impl.common.Path.relative(path.getName().subName(pkg.size()), path.getExt()); qualifier = new PathLiteral(relativePath.getCanonical()); } else { qualifier = new PathLiteral(path.getCanonical()); } beans.add(BeanDescriptor.createFromImpl(Template.class, null, Arrays.<Annotation>asList(qualifier), descriptor.getType())); } // this.templates = templates; this.pkg = pkg; this.beans = beans; }
public Template add(Path.Absolute path, Iterable<TemplateRefMetaModel> refs) { if (qn.isPrefix(path.getName())) { TemplateMetaModel template = templates.get(path); if (template == null) {
public Template add(Path.Absolute path, Iterable<TemplateRefMetaModel> refs) { if (qn.isPrefix(path.getName())) { TemplateMetaModel template = templates.get(path); if (template == null) {
Class<?> clazz = context.getClassLoader().loadClass(resolved.getName().toString()); Field f = clazz.getField("DESCRIPTOR"); desc = (TemplateDescriptor)f.get(null);
private void resolvedQualified( TemplateProvider<?> provider, TemplateMetaModel template, Element[] elements) { // Path.Absolute path = template.getPath(); if (classCache.containsKey(path)) { log.info("Template class " + path + " was found in cache"); } else { Path.Absolute resolvedPath = owner.resolvePath(path); Writer writer = null; try { FileObject classFile = owner.application.getProcessingContext().createSourceFile(resolvedPath.getName(), elements); writer = classFile.openWriter(); emitClass(provider, template, elements, writer); classCache.put(path, classFile); log.info("Generated template class " + path + " as " + classFile.toUri() + " with originating elements " + Arrays.asList(elements)); } catch (IOException e) { e.printStackTrace(); throw TemplateMetaModel.CANNOT_WRITE_TEMPLATE_CLASS.failure(e, elements[0], path); } finally { Tools.safeClose(writer); } } } }
private void resolvedQualified( TemplateProvider<?> provider, TemplateMetaModel template, Element[] elements) { // Path.Absolute path = template.getPath(); if (classCache.containsKey(path)) { log.info("Template class " + path + " was found in cache"); } else { Path.Absolute resolvedPath = owner.resolvePath(path); Writer writer = null; try { FileObject classFile = owner.application.getProcessingContext().createSourceFile(resolvedPath.getName(), elements); writer = classFile.openWriter(); emitClass(provider, template, elements, writer); classCache.put(path, classFile); log.info("Generated template class " + path + " as " + classFile.toUri() + " with originating elements " + Arrays.asList(elements)); } catch (IOException e) { e.printStackTrace(); throw TemplateMetaModel.CANNOT_WRITE_TEMPLATE_CLASS.failure(e, elements[0], path); } finally { Tools.safeClose(writer); } } } }
@Override public JSON getDescriptor(ApplicationMetaModel application) { JSON config = new JSON(); AbstractContainerMetaModel metaModel = application.getChild(TemplateContainerMetaModel.KEY); LinkedHashSet<String> templates = new LinkedHashSet<String>(); for (TemplateRefMetaModel ref : metaModel.getChildren(TemplateRefMetaModel.class)) { if (ref instanceof ElementMetaModel) { templates.add(((ElementMetaModel)ref).getPath().getName().toString()); } } config.map("templates", templates); config.set("package", metaModel.getQN().toString()); return config; } }
@Override public JSON getDescriptor(ApplicationMetaModel application) { JSON config = new JSON(); AbstractContainerMetaModel metaModel = application.getChild(TemplateContainerMetaModel.KEY); LinkedHashSet<String> templates = new LinkedHashSet<String>(); for (TemplateRefMetaModel ref : metaModel.getChildren(TemplateRefMetaModel.class)) { if (ref instanceof ElementMetaModel) { templates.add(((ElementMetaModel)ref).getPath().getName().toString()); } } config.map("templates", templates); config.set("package", metaModel.getQN().toString()); return config; } }
@Test public void testResolveDotInRawName() throws Exception { Name name = Name.parse("foo"); Path path = Path.parse("a.b.c"); Path.Absolute file = name.resolve(path); assertEquals("foo", file.getDirs().toString()); assertEquals("a.b.c", file.getSimpleName()); assertEquals("b.c", file.ext); assertEquals("a", file.getRawName()); assertEquals("foo.a", file.getName().toString()); }
@Test public void testResolveUp() throws Exception { Name name = Name.parse("foo.bar"); Path.Absolute file = name.resolve("../juu/daa.txt"); assertEquals("foo.juu", file.getDirs().toString()); assertEquals("daa.txt", file.getSimpleName()); assertEquals("txt", file.getExt()); assertEquals("daa", file.getRawName()); assertEquals("foo.juu.daa", file.getName().toString()); }
@Override public final void emit(EmitContext context, TemplateModel<ASTNode.Template> templateModel) throws TemplateException, IOException { GroovyTemplateEmitter emitter = new GroovyTemplateEmitter(templateModel.getPath().getName()); EmitPhase tcc = new EmitPhase(context); tcc.emit(emitter, templateModel.getModel()); Path.Absolute path = templateModel.getPath(); path = path.as(path.getRawName() + "_", "groovy"); context.createResource(path, emitter.toString()); } }
TagHandler resolveApplicationTagHandler(String name) { TagMetaModel tag = getChild(Key.of(name, TagMetaModel.class)); if (tag != null) { TemplateMetaModel template = tag.getChild(TemplateMetaModel.KEY); Path.Absolute path = template.getPath(); return new SimpleTag(name, path.getName().toString()); } return null; }
@Test public void testResolveUp() throws Exception { Name name = Name.parse("foo.bar"); Path.Absolute file = name.resolve("../juu/daa.txt"); assertEquals("foo.juu", file.getDirs().toString()); assertEquals("daa.txt", file.getSimpleName()); assertEquals("txt", file.getExt()); assertEquals("daa", file.getRawName()); assertEquals("foo.juu.daa", file.getName().toString()); }
@Test public void testResolveDotInRawName() throws Exception { Name name = Name.parse("foo"); Path path = Path.parse("a.b.c"); Path.Absolute file = name.resolve(path); assertEquals("foo", file.getDirs().toString()); assertEquals("a.b.c", file.getSimpleName()); assertEquals("b.c", file.ext); assertEquals("a", file.getRawName()); assertEquals("foo.a", file.getName().toString()); }
@Override public final void emit(EmitContext context, TemplateModel<ASTNode.Template> templateModel) throws TemplateException, IOException { GroovyTemplateEmitter emitter = new GroovyTemplateEmitter(templateModel.getPath().getName()); EmitPhase tcc = new EmitPhase(context); tcc.emit(emitter, templateModel.getModel()); Path.Absolute path = templateModel.getPath(); path = path.as(path.getRawName() + "_", "groovy"); context.createResource(path, emitter.toString()); } }
TagHandler resolveApplicationTagHandler(String name) { TagMetaModel tag = getChild(Key.of(name, TagMetaModel.class)); if (tag != null) { TemplateMetaModel template = tag.getChild(TemplateMetaModel.KEY); Path.Absolute path = template.getPath(); return new SimpleTag(name, path.getName().toString()); } return null; }