@@ -72,8 +72,9 @@ public abstract class ProcessorSessionFactory extends MockSessionFactory {
72
72
public static MockSessionFactory create (
73
73
ProcessingEnvironment environment ,
74
74
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 );
77
78
}
78
79
79
80
static final Mocker <ProcessorSessionFactory > instance = Mocker .variadic (ProcessorSessionFactory .class );
@@ -88,16 +89,19 @@ public static MockSessionFactory create(
88
89
private final Elements elementUtil ;
89
90
private final Types typeUtil ;
90
91
private final Filer filer ;
92
+ private final boolean indexing ;
91
93
private final Map <String , String > entityNameMappings ;
92
94
private final Map <String , Set <String >> enumTypesByValue ;
93
95
94
96
public ProcessorSessionFactory (
95
97
ProcessingEnvironment processingEnvironment ,
98
+ boolean indexing ,
96
99
Map <String ,String > entityNameMappings ,
97
100
Map <String , Set <String >> enumTypesByValue ) {
98
101
elementUtil = processingEnvironment .getElementUtils ();
99
102
typeUtil = processingEnvironment .getTypeUtils ();
100
103
filer = processingEnvironment .getFiler ();
104
+ this .indexing = indexing ;
101
105
this .entityNameMappings = entityNameMappings ;
102
106
this .enumTypesByValue = enumTypesByValue ;
103
107
}
@@ -220,15 +224,25 @@ Set<String> getEnumTypesForValue(String value) {
220
224
if ( result != null ) {
221
225
return result ;
222
226
}
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 () ) );
226
240
}
227
241
catch (IOException ignore ) {
228
242
}
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 () ) );
232
246
}
233
247
catch (IOException ignore ) {
234
248
}
@@ -503,27 +517,13 @@ private TypeElement findEntityByUnqualifiedName(String entityName) {
503
517
if ( cached != null ) {
504
518
return cached ;
505
519
}
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
+ }
527
527
}
528
528
529
529
TypeElement symbol =
@@ -543,6 +543,26 @@ private TypeElement findEntityByUnqualifiedName(String entityName) {
543
543
return null ;
544
544
}
545
545
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
+
546
566
public static TypeElement findEntityByUnqualifiedName (String entityName , ModuleElement module ) {
547
567
for (Element element : module .getEnclosedElements ()) {
548
568
if (element .getKind () == ElementKind .PACKAGE ) {
0 commit comments