@@ -72,8 +72,9 @@ public abstract class ProcessorSessionFactory extends MockSessionFactory {
7272 public static MockSessionFactory create (
7373 ProcessingEnvironment environment ,
7474 Map <String ,String > entityNameMappings ,
75- Map <String , Set <String >> enumTypesByValue ) {
76- return instance .make (environment , entityNameMappings , enumTypesByValue );
75+ Map <String , Set <String >> enumTypesByValue ,
76+ boolean indexing ) {
77+ return instance .make (environment , indexing , entityNameMappings , enumTypesByValue );
7778 }
7879
7980 static final Mocker <ProcessorSessionFactory > instance = Mocker .variadic (ProcessorSessionFactory .class );
@@ -88,16 +89,19 @@ public static MockSessionFactory create(
8889 private final Elements elementUtil ;
8990 private final Types typeUtil ;
9091 private final Filer filer ;
92+ private final boolean indexing ;
9193 private final Map <String , String > entityNameMappings ;
9294 private final Map <String , Set <String >> enumTypesByValue ;
9395
9496 public ProcessorSessionFactory (
9597 ProcessingEnvironment processingEnvironment ,
98+ boolean indexing ,
9699 Map <String ,String > entityNameMappings ,
97100 Map <String , Set <String >> enumTypesByValue ) {
98101 elementUtil = processingEnvironment .getElementUtils ();
99102 typeUtil = processingEnvironment .getTypeUtils ();
100103 filer = processingEnvironment .getFiler ();
104+ this .indexing = indexing ;
101105 this .entityNameMappings = entityNameMappings ;
102106 this .enumTypesByValue = enumTypesByValue ;
103107 }
@@ -220,15 +224,25 @@ Set<String> getEnumTypesForValue(String value) {
220224 if ( result != null ) {
221225 return result ;
222226 }
223- try (Reader reader = filer .getResource (StandardLocation .SOURCE_OUTPUT , ENTITY_INDEX , value )
224- .openReader (true ); BufferedReader buffered = new BufferedReader (reader ) ) {
225- return Set .of (split (" " , buffered .readLine ()));
227+ if ( indexing ) {
228+ final Set <String > indexed = getIndexedEnumTypesByValue (value );
229+ enumTypesByValue .put (value , indexed );
230+ return indexed ;
231+ }
232+ //TODO: else do a full scan like in findEntityByUnqualifiedName()
233+ return null ;
234+ }
235+
236+ private @ Nullable Set <String > getIndexedEnumTypesByValue (String value ) {
237+ try (Reader reader = filer .getResource ( StandardLocation .SOURCE_OUTPUT , ENTITY_INDEX , value )
238+ .openReader ( true ); BufferedReader buffered = new BufferedReader ( reader )) {
239+ return Set .of ( split ( " " , buffered .readLine () ) );
226240 }
227241 catch (IOException ignore ) {
228242 }
229- try (Reader reader = filer .getResource (StandardLocation .CLASS_PATH , ENTITY_INDEX , '.' + value )
230- .openReader (true ); BufferedReader buffered = new BufferedReader (reader ) ) {
231- return Set .of (split (" " , buffered .readLine ()) );
243+ try (Reader reader = filer .getResource ( StandardLocation .CLASS_PATH , ENTITY_INDEX , '.' + value )
244+ .openReader ( true ); BufferedReader buffered = new BufferedReader ( reader ) ) {
245+ return Set .of ( split ( " " , buffered .readLine () ) );
232246 }
233247 catch (IOException ignore ) {
234248 }
@@ -503,27 +517,13 @@ private TypeElement findEntityByUnqualifiedName(String entityName) {
503517 if ( cached != null ) {
504518 return cached ;
505519 }
506- final String qualifiedName = entityNameMappings .get (entityName );
507- if ( qualifiedName != null ) {
508- final TypeElement result = elementUtil .getTypeElement (qualifiedName );
509- entityCache .put (entityName , result );
510- return result ;
511- }
512- try (Reader reader = filer .getResource ( StandardLocation .SOURCE_OUTPUT , ENTITY_INDEX , entityName )
513- .openReader (true ); BufferedReader buffered = new BufferedReader (reader ) ) {
514- final TypeElement result = elementUtil .getTypeElement (buffered .readLine ());
515- entityCache .put (entityName , result );
516- return result ;
517- }
518- catch (IOException ignore ) {
519- }
520- try (Reader reader = filer .getResource (StandardLocation .CLASS_PATH , ENTITY_INDEX , entityName )
521- .openReader (true ); BufferedReader buffered = new BufferedReader (reader ) ) {
522- final TypeElement result = elementUtil .getTypeElement (buffered .readLine ());
523- entityCache .put (entityName , result );
524- return result ;
525- }
526- catch (IOException ignore ) {
520+
521+ if ( indexing ) {
522+ final TypeElement indexedEntity = findIndexedEntityByQualifiedName ( entityName );
523+ if ( indexedEntity != null ) {
524+ entityCache .put (entityName , indexedEntity );
525+ return indexedEntity ;
526+ }
527527 }
528528
529529 TypeElement symbol =
@@ -543,6 +543,26 @@ private TypeElement findEntityByUnqualifiedName(String entityName) {
543543 return null ;
544544 }
545545
546+ private @ Nullable TypeElement findIndexedEntityByQualifiedName (String entityName ) {
547+ final String qualifiedName = entityNameMappings .get (entityName );
548+ if ( qualifiedName != null ) {
549+ return elementUtil .getTypeElement (qualifiedName );
550+ }
551+ try (Reader reader = filer .getResource ( StandardLocation .SOURCE_OUTPUT , ENTITY_INDEX , entityName )
552+ .openReader (true ); BufferedReader buffered = new BufferedReader (reader ) ) {
553+ return elementUtil .getTypeElement (buffered .readLine ());
554+ }
555+ catch (IOException ignore ) {
556+ }
557+ try (Reader reader = filer .getResource (StandardLocation .CLASS_PATH , ENTITY_INDEX , entityName )
558+ .openReader (true ); BufferedReader buffered = new BufferedReader (reader ) ) {
559+ return elementUtil .getTypeElement (buffered .readLine ());
560+ }
561+ catch (IOException ignore ) {
562+ }
563+ return null ;
564+ }
565+
546566 public static TypeElement findEntityByUnqualifiedName (String entityName , ModuleElement module ) {
547567 for (Element element : module .getEnclosedElements ()) {
548568 if (element .getKind () == ElementKind .PACKAGE ) {
0 commit comments