public GroovyTemplateEmitter(Name name) { if (name != null) { pkg = name.getParent(); String id = "C" + name.getIdentifier(); constants = pkg.append(id); } else { pkg = null; constants = Name.parse("Constants"); } }
ApplicationMetaModel(ElementHandle.Package handle, String baseName) { // if (baseName == null) { String s = handle.getPackageName().toString(); int index = s.lastIndexOf('.'); baseName = Character.toUpperCase(s.charAt(index + 1)) + s.substring(index + 2); } // this.handle = handle; this.modified = false; this.baseName = baseName; }
@Override public boolean equals(Object obj) { if (obj == this) { return true; } else if (obj instanceof Type) { Type that = (Type)obj; return name.equals(that.name); } return false; }
@Test public void testParent() { Name abc = Name.parse("a.b.c"); Name ab = abc.getParent(); assertEquals(Name.parse("a.b"), ab); Name a = ab.getParent(); assertEquals(a, ab.getParent()); assertEquals(Name.parse("a"), a); Name empty = a.getParent(); assertEquals(Name.parse(""), empty); assertEquals(0, empty.size()); assertEquals(0, empty.length()); assertEquals((Object)null, empty.getParent()); }
@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()); }
private Path(Name pkg, String rawName, String ext) { this.canonical = null; this.name = pkg.append(rawName); this.ext = ext; }
if (annotations != null) { JSON controllerJSON = new JSON(); config.set(controller.getHandle().getName().toString(), controllerJSON); if (key.getType().equals(Name.create(RequiresGuest.class))) { controllerJSON.set("require", "guest"); } else if (key.getType().equals(Name.create(RequiresAuthentication.class))) { controllerJSON.set("require", "authenticate"); } else if (key.getType().equals(Name.create(RequiresUser.class))) { controllerJSON.set("require", "user"); JSON controllerJSON = config.getJSON(controller.getHandle().getName().toString()); if (controllerJSON == null) { controllerJSON = new JSON(); config.set(controller.getHandle().getName().toString(), controllerJSON);
void emitApplication(ProcessingContext env, ApplicationMetaModel application) throws ProcessingException { PackageElement elt = env.get(application.getHandle()); Name fqn = application.getName().append("Application"); writer = applicationFile.openWriter(); writer.append("package ").append(fqn.getParent()).append(";\n"); writer.append("public class ").append(fqn.getIdentifier()).append(" {\n"); writer.append("public ").append(fqn.getIdentifier()).append("() throws Exception {\n"); writer.append("this.descriptor = ").append(APPLICATION_DESCRIPTOR).append(".create(getClass());\n"); writer.append("}\n");
@Override public void processAnnotationAdded(ApplicationMetaModel metaModel, AnnotationKey key, AnnotationState added) { ElementHandle.Package pkg = metaModel.getHandle(); if (key.getElement().getPackageName().equals(pkg.getPackageName())) { String name = (String)added.get("name"); if (name == null) { name = metaModel.getBaseName() + "Portlet"; } enabledMap.put(pkg, new String[]{name, metaModel.getName().toString()}); toEmit.add(pkg); } }
public Path.Absolute resolvePath(Path path) { return qn.resolve(path); }
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 JavaFile<I> assertAddJavaSource(String name) { Name n = Name.parse(name); FileResource<I> source = assertAddSource(name, "java", "package " + n.getParent() + ";\npublic class " + n.getIdentifier() + " {}\n"); return new JavaFile<I>(source); }
private void emitConfig(AnnotationKey key, AnnotationState added) { if (key.getType().equals(Name.create(RequiresGuest.class)) || key.getType().equals(Name.create(RequiresUser.class)) || key.getType().equals(Name.create(RequiresAuthentication.class)) || key.getType().equals(Name.create(RequiresRoles.class)) || key.getType().equals(Name.create(RequiresPermissions.class)) || key.getType().equals(Name.create(Login.class)) || key.getType().equals(Name.create(Logout.class))) { if (key.getElement() instanceof ElementHandle.Method) { Map<AnnotationKey, AnnotationState> annotations = methods.get(key.getElement()); if (annotations == null) { annotations = new HashMap<AnnotationKey, AnnotationState>(); methods.put(key.getElement(), annotations); } annotations.put(key, added); } else if (key.getElement() instanceof ElementHandle.Type) { if (key.getType().equals(Name.create(RequiresGuest.class)) || key.getType().equals(Name.create(RequiresAuthentication.class)) || key.getType().equals(Name.create(RequiresUser.class))) { Map<AnnotationKey, AnnotationState> annotations = controllers.get(key.getElement()); if (annotations == null) { annotations = new HashMap<AnnotationKey, AnnotationState>(); controllers.put(key.getElement(), annotations); } annotations.put(key, added); } else throw new UnsupportedOperationException("Unsupported " + key.getType() + " at " + key.getElement()); } } }
/** * Parse the name. * * @param s the char sequence to parse * @return the name * @throws IllegalArgumentException if the name is not valid */ public static Name parse(CharSequence s) throws IllegalArgumentException { int len = s.length(); return parse(s, 0, len); }
/** * Returns the path raw name. * * @return the raw name */ public String getRawName() { return name.getIdentifier(); }