[forge-users] Roaster: JavaClassSource to file

George Gastaldi ggastald at redhat.com
Tue Sep 30 15:20:34 EDT 2014


The best way is to call the toString() method and save it to a file



> Em 30/09/2014, às 11:06, forge-users at lists.jboss.org escreveu:
> 
> Hi,
> 
> I have started to use Roaster (standalone) to generate some java code.
> 
> When you havea org.jboss.forge.roaster.model.source.JavaClassSource, what is the best way to write the content into a file?
> 
> I could not find anything. How are other developers using Roaster?
> 
> I came up with this method (based on google guava):
> 
> public static void toFile(JavaClassSource javaClass, File srcFolder) throws IOException {
>   File f = srcFolder;
>   String[] parts = javaClass.getPackage().split("\\.");
>   for (String n : parts) {
>     f = new File(f, n);
>   }
>   f = new File(f, javaClass.getName() + ".java");
>   Files.createParentDirs(f);
>   Files.write(javaClass.toString(), f, Charsets.UTF_8);
> }
> 
> Posted by forums
> Original post: https://developer.jboss.org/message/905590#905590
> 
> _______________________________________________
> forge-users mailing list
> forge-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/forge-users



More information about the forge-users mailing list