1 Reply Latest reply on Sep 30, 2014 3:20 PM by gastaldi

    Roaster: JavaClassSource to file

    jmini

      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);

      }