private String createModuleStarter ( final Map < Class < ? > , Set < ? extends Element > > annotationMap , ProcessingEnvironment processingEnv ) { String moduleName ; try { moduleName = getModuleStarterName ( processingEnv ) ; final String starterName = moduleName . substring ( moduleName . lastIndexOf ( ' ' ) + 1 ) ; final String pkg = moduleName . substring ( 0 , moduleName . lastIndexOf ( ' ' ) ) ; final JavaClassSource javaClass = Roaster . create ( JavaClassSource . class ) ; javaClass . setPackage ( pkg ) . setName ( starterName ) ; javaClass . extendSuperType ( AbstractModuleStarter . class ) ; final StringBuilder body = new StringBuilder ( ) ; appendRegistrationPoints ( javaClass , body , annotationMap . get ( RegistrationPoint . class ) ) ; appendRegistrations ( javaClass , body , annotationMap . get ( Register . class ) ) ; appendPreload ( javaClass , body , annotationMap . get ( Preload . class ) ) ; appendBootComponent ( javaClass , body , annotationMap . get ( BootComponent . class ) ) ; if ( ! javaClass . hasMethodSignature ( "start" ) ) { final MethodSource < ? > method = javaClass . addMethod ( ) . setName ( "start" ) . setPublic ( ) . setBody ( body . toString ( ) ) . setReturnTypeVoid ( ) ; method . getJavaDoc ( ) . setFullText ( "{@inheritDoc}" ) ; method . addAnnotation ( Override . class ) ; } else { javaClass . getMethod ( "start" ) . setBody ( javaClass . getMethod ( "start" ) . getBody ( ) + body . toString ( ) ) ; } final Properties prefs = new Properties ( ) ; prefs . load ( this . getClass ( ) . getResourceAsStream ( FORMATTER_PROPERTIES_FILE ) ) ; final String formattedSource = Formatter . format ( prefs , javaClass ) ; // System.out.println(formattedSource); final JavaFileObject jfo = this . processingEnv . getFiler ( ) . createSourceFile ( moduleName ) ; this . processingEnv . getMessager ( ) . printMessage ( Diagnostic . Kind . NOTE , "creating source file: " + jfo . toUri ( ) ) ; final Writer writer = jfo . openWriter ( ) ; writer . write ( formattedSource ) ; writer . close ( ) ; } catch ( final Exception e ) { e . printStackTrace ( ) ; throw new RuntimeException ( e ) ; } return moduleName ; }
Creates module stater class according to the annotations