1313import org .objectweb .asm .util .TraceClassVisitor ;
1414
1515import javax .annotation .processing .Completion ;
16+ import javax .annotation .processing .Filer ;
1617import javax .annotation .processing .ProcessingEnvironment ;
1718import javax .annotation .processing .Processor ;
1819import javax .annotation .processing .RoundEnvironment ;
2324import javax .lang .model .element .ExecutableElement ;
2425import javax .lang .model .element .TypeElement ;
2526import javax .lang .model .type .TypeMirror ;
27+ import javax .tools .JavaFileObject ;
2628import java .io .ByteArrayOutputStream ;
29+ import java .io .IOException ;
30+ import java .io .OutputStream ;
2731import java .io .PrintWriter ;
2832import java .util .Collections ;
2933import java .util .HashMap ;
@@ -76,16 +80,23 @@ public boolean process(Set<? extends TypeElement> annotations,
7680 }
7781 }
7882 }
83+ Filer filer = processingEnvironment .getFiler ();
7984 Map <String , List <Map .Entry <String , MvcHandlerCompiler >>> classes = result .entrySet ().stream ()
8085 .collect (Collectors .groupingBy (e -> e .getValue ().getController ().getName ()));
8186 for (Map .Entry <String , List <Map .Entry <String , MvcHandlerCompiler >>> entry : classes
8287 .entrySet ()) {
8388 try {
8489 List <Map .Entry <String , MvcHandlerCompiler >> handlers = entry .getValue ();
8590 MvcModuleCompiler module = new MvcModuleCompiler (entry .getKey ());
86- modules .put (entry .getKey () + "$Module" , module .compile (handlers ));
91+ String moduleClass = entry .getKey () + "$Module" ;
92+ byte [] moduleBin = module .compile (handlers );
93+ writeClass (filer .createClassFile (moduleClass ), moduleBin );
94+ modules .put (moduleClass , moduleBin );
8795 for (Map .Entry <String , MvcHandlerCompiler > handler : handlers ) {
88- modules .put (handler .getValue ().getGeneratedClass (), handler .getValue ().compile ());
96+ String handleClass = handler .getValue ().getGeneratedClass ();
97+ byte [] handleBin = handler .getValue ().compile ();
98+ writeClass (filer .createClassFile (handleClass ), handleBin );
99+ modules .put (handleClass , handleBin );
89100 }
90101 } catch (Exception x ) {
91102 x .printStackTrace ();
@@ -95,6 +106,12 @@ public boolean process(Set<? extends TypeElement> annotations,
95106 return true ;
96107 }
97108
109+ private void writeClass (JavaFileObject javaFileObject , byte [] bytecode ) throws IOException {
110+ try (OutputStream output = javaFileObject .openOutputStream ()) {
111+ output .write (bytecode );
112+ }
113+ }
114+
98115 /*package*/ MvcHandlerCompiler compilerFor (String methodDescriptor ) {
99116 return result .get (methodDescriptor );
100117 }
0 commit comments