1 package at.rseiler.spbee.core.generator;
2
3 import at.rseiler.spbee.core.util.StringCodeWriter;
4 import com.sun.codemodel.JCodeModel;
5
6 import javax.annotation.processing.ProcessingEnvironment;
7 import javax.tools.JavaFileObject;
8 import java.io.IOException;
9 import java.io.Writer;
10
11
12
13
14
15
16 public abstract class AbstractGenerator {
17
18 private final ProcessingEnvironment processingEnv;
19
20 public AbstractGenerator(ProcessingEnvironment processingEnv) {
21 this.processingEnv = processingEnv;
22 }
23
24
25
26
27
28
29
30
31 public void generateClass(JCodeModel model, String qualifiedClassName) throws IOException {
32 StringCodeWriter codeWriter = new StringCodeWriter();
33 model.build(codeWriter);
34 String javaCode = codeWriter.getJavaCode();
35
36 JavaFileObject f = processingEnv.getFiler().createSourceFile(qualifiedClassName);
37 Writer w = f.openWriter();
38 w.write(javaCode);
39 w.close();
40 }
41
42 }