[forge-users] Roaster: JavaClassSource to file

forge-users at lists.jboss.org forge-users at lists.jboss.org
Tue Sep 30 14:05:27 EDT 2014


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.write(javaClass.toString(), f, Charsets.UTF_8);

Posted by forums
Original post: https://developer.jboss.org/message/905590#905590

More information about the forge-users mailing list