1515import java .nio .file .Files ;
1616import java .nio .file .Paths ;
1717import java .util .*;
18- import java .util .function .Consumer ;
18+ import java .util .function .BiConsumer ;
1919import java .util .stream .Collectors ;
2020import java .util .stream .Stream ;
2121
@@ -71,10 +71,10 @@ static String string(ProcessingEnvironment environment, String option, String de
7171 }
7272
7373 protected MvcContext context ;
74- private Consumer < String > output ;
74+ private BiConsumer < Diagnostic . Kind , String > output ;
7575 private final Set <Object > processed = new HashSet <>();
7676
77- public JoobyProcessor (Consumer < String > output ) {
77+ public JoobyProcessor (BiConsumer < Diagnostic . Kind , String > output ) {
7878 this .output = output ;
7979 }
8080
@@ -88,38 +88,42 @@ public synchronized void init(ProcessingEnvironment processingEnvironment) {
8888 ofNullable (output )
8989 .orElseGet (
9090 () ->
91- message ->
92- processingEnvironment
93- .getMessager ()
94- .printMessage (Diagnostic .Kind .OTHER , message )));
91+ (kind , message ) ->
92+ processingEnvironment .getMessager ().printMessage (kind , message )));
9593 super .init (processingEnvironment );
9694 }
9795
9896 @ Override
9997 public boolean process (Set <? extends TypeElement > annotations , RoundEnvironment roundEnv ) {
100- if (roundEnv .processingOver ()) {
101- context .debug ("Output:" );
102- context .getRouters ().forEach (it -> context .debug (" %s.java" , it .getGeneratedType ()));
103- if (context .generateServices ()) {
104- doServices (context .getProcessingEnvironment ().getFiler (), context .getRouters ());
105- }
106- return false ;
107- } else {
108- var routeMap = buildRouteRegistry (annotations , roundEnv );
109- for (var router : routeMap .values ()) {
110- try {
111- var sourceCode = router .toSourceCode (null );
112- var sourceLocation = router .getGeneratedFilename ();
113- onGeneratedSource (toJavaFileObject (sourceLocation , sourceCode ));
114- context .debug ("router %s: %s" , router .getTargetType (), router .getGeneratedType ());
115- router .getRoutes ().forEach (it -> context .debug (" %s" , it ));
116- writeSource (router , sourceLocation , sourceCode );
117- context .add (router );
118- } catch (IOException cause ) {
119- throw new RuntimeException ("Unable to generate: " + router .getTargetType (), cause );
98+ try {
99+ if (roundEnv .processingOver ()) {
100+ context .debug ("Output:" );
101+ context .getRouters ().forEach (it -> context .debug (" %s.java" , it .getGeneratedType ()));
102+ if (context .generateServices ()) {
103+ doServices (context .getProcessingEnvironment ().getFiler (), context .getRouters ());
104+ }
105+ return false ;
106+ } else {
107+ var routeMap = buildRouteRegistry (annotations , roundEnv );
108+ for (var router : routeMap .values ()) {
109+ try {
110+ var sourceCode = router .toSourceCode (null );
111+ var sourceLocation = router .getGeneratedFilename ();
112+ onGeneratedSource (toJavaFileObject (sourceLocation , sourceCode ));
113+ context .debug ("router %s: %s" , router .getTargetType (), router .getGeneratedType ());
114+ router .getRoutes ().forEach (it -> context .debug (" %s" , it ));
115+ writeSource (router , sourceLocation , sourceCode );
116+ context .add (router );
117+ } catch (IOException cause ) {
118+ throw new RuntimeException ("Unable to generate: " + router .getTargetType (), cause );
119+ }
120120 }
121+ return true ;
121122 }
122- return true ;
123+ } catch (Exception cause ) {
124+ context .error (
125+ Optional .ofNullable (cause .getMessage ()).orElse ("Unable to generate routes" ), cause );
126+ throw sneakyThrow0 (cause );
123127 }
124128 }
125129
0 commit comments