protected DefaultEvaluatorFactory(CollQueryTemplates templates, ClassLoader classLoader) { this.templates = templates; if (classLoader instanceof URLClassLoader) { this.factory = new JDKEvaluatorFactory((URLClassLoader) classLoader); } else { // for OSGi compatibility this.factory = new ECJEvaluatorFactory(classLoader); } }
@Override public T apply(F input) { return ev.evaluate(input); } };
protected DefaultEvaluatorFactory(CollQueryTemplates templates, URLClassLoader classLoader, JavaCompiler compiler) { this.templates = templates; this.factory = new JDKEvaluatorFactory(classLoader, compiler); }
@Test public void entitySerializer() throws Exception { new EntitySerializer(typeMappings, Collections.<String>emptyList()) .serialize(type, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); }
private void write(Serializer serializer, String path, SerializerConfig serializerConfig, EntityType type) throws IOException { File targetFile = new File(targetFolder, path); generatedFiles.add(targetFile); Writer w = writerFor(targetFile); try { CodeWriter writer = createScalaSources ? new ScalaWriter(w) : new JavaWriter(w); serializer.serialize(type, serializerConfig, writer); } finally { w.close(); } }
protected void entityAccessor(EntityType model, Property field, CodeWriter writer) throws IOException { Type queryType = typeMappings.getPathType(field.getType(), model, false); writer.beginPublicMethod(queryType, field.getEscapedName()); writer.line("if (", field.getEscapedName(), " == null) {"); writer.line(" ", field.getEscapedName(), " = new ", writer.getRawName(queryType), "(forProperty(\"", field.getName(), "\"));"); writer.line("}"); writer.line(RETURN, field.getEscapedName(), SEMICOLON); writer.end(); }
protected void addFullConstructor(EntityType model, CodeWriter writer) throws IOException { // public empty constructor writer.beginConstructor(); writer.end(); // full constructor writer.beginConstructor(model.getProperties(), propertyToParameter); for (Property property : model.getProperties()) { writer.line("this.", property.getEscapedName(), " = ", property.getEscapedName(), ";"); } writer.end(); }
@Override public String apply(EntityType entity) { String uncapSimpleName = StringUtils.uncapitalize(entity.getInnerType().getSimpleName()); if (SourceVersion.isKeyword(uncapSimpleName)) { uncapSimpleName = uncapSimpleName + "$"; } return uncapSimpleName; } }
protected void introJavadoc(CodeWriter writer, EntityType model) throws IOException { Type queryType = typeMappings.getPathType(model, model, true); writer.javadoc(queryType.getSimpleName() + " is a Querydsl query type for " + model.getSimpleName()); }
protected void introPackage(CodeWriter writer, EntityType model) throws IOException { Type queryType = typeMappings.getPathType(model, model, false); if (!queryType.getPackageName().isEmpty()) { writer.packageDecl(queryType.getPackageName()); } }
public static void assertCompiles(String name, String source) { URLClassLoader parent = (URLClassLoader) CompileUtils.class.getClassLoader(); SimpleCompiler compiler = new SimpleCompiler(); MemFileManager fileManager = new MemFileManager(parent, compiler.getStandardFileManager(null, null, null)); String classpath = SimpleCompiler.getClassPath(parent); List<String> compilationOptions = Arrays.asList("-classpath", classpath, "-g:none"); // compile SimpleJavaFileObject javaFileObject = new MemSourceFileObject(name, source); Writer out = new StringWriter(); JavaCompiler.CompilationTask task = compiler.getTask(out, fileManager, null, compilationOptions, null, Collections.singletonList(javaFileObject)); if (!task.call()) { Assert.fail("Compilation of " + source + " failed.\n" + out.toString()); } }
protected void entityField(EntityType model, Property field, SerializerConfig config, CodeWriter writer) throws IOException { Type queryType = typeMappings.getPathType(field.getType(), model, false); if (field.isInherited()) { writer.line("// inherited"); } if (config.useEntityAccessors()) { writer.protectedField(queryType, field.getEscapedName()); } else { writer.publicFinal(queryType, field.getEscapedName()); } }
protected void outro(EntityType model, CodeWriter writer) throws IOException { writer.end(); }
private static CodeWriter suppressAllWarnings(CodeWriter writer) throws IOException { return writer.suppressWarnings("all", "rawtypes", "unchecked"); }
@Test public void embeddableSerializer() throws Exception { new EmbeddableSerializer(typeMappings,Collections.<String>emptyList()) .serialize(type, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); }
protected void outro(EntityType model, CodeWriter writer) throws IOException { writer.end(); }
@Test public void supertypeSerializer() throws IOException { new SupertypeSerializer(typeMappings,Collections.<String>emptyList()) .serialize(type, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); }
@Test public void projectionSerializer() throws IOException { new ProjectionSerializer(typeMappings) .serialize(type, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); } }