2222import javax .lang .model .SourceVersion ;
2323import javax .lang .model .element .*;
2424import javax .lang .model .type .DeclaredType ;
25+ import javax .lang .model .type .TypeKind ;
2526import javax .lang .model .type .TypeMirror ;
27+ import javax .lang .model .util .Elements ;
2628import javax .lang .model .util .Types ;
2729import javax .tools .Diagnostic ;
30+ import javax .tools .Diagnostic .Kind ;
2831import javax .tools .JavaFileObject ;
2932import java .io .IOException ;
3033import java .io .Writer ;
@@ -65,7 +68,7 @@ public synchronized void init(ProcessingEnvironment env) {
6568 processingEnvironment .getTypeUtils ();
6669
6770 messager = processingEnvironment .getMessager ();
68- messager .printMessage (Diagnostic .Kind .NOTE , "Redis OM Spring Field Generator Processor " );
71+ messager .printMessage (Diagnostic .Kind .NOTE , "Redis OM Spring Entity Metamodel Generator " );
6972
7073 this .objectTypeElement = processingEnvironment .getElementUtils ().getTypeElement ("java.lang.Object" );
7174 }
@@ -100,6 +103,8 @@ void generateMetaModelClass(final Element annotatedElement) throws IOException {
100103 final String genEntityName = entityName + "$" ;
101104 TypeName entity = TypeName .get (annotatedElement .asType ());
102105
106+ messager .printMessage (Diagnostic .Kind .NOTE , "Generating Entity Metamodel: " + qualifiedGenEntityName );
107+
103108 Map <? extends Element , String > enclosedFields = getInstanceFields (annotatedElement );
104109
105110 final PackageElement packageElement = processingEnvironment .getElementUtils ().getPackageOf (annotatedElement );
@@ -232,7 +237,7 @@ private List<Triple<ObjectGraphFieldSpec, FieldSpec, CodeBlock>> processFieldMet
232237 targetCls = ClassUtils .forName (cls , MetamodelGenerator .class .getClassLoader ());
233238 } catch (ClassNotFoundException cnfe ) {
234239 messager .printMessage (Diagnostic .Kind .WARNING ,
235- "Processing class " + entityName + " could not resolve " + cls + " while checking for nested indexables " );
240+ "Processing class " + entityName + " could not resolve " + cls + " while checking for nested @Indexed " );
236241 fieldMetamodelSpec .addAll (processNestedIndexableFields (entity , chain ));
237242 }
238243
@@ -244,6 +249,8 @@ private List<Triple<ObjectGraphFieldSpec, FieldSpec, CodeBlock>> processFieldMet
244249 case GEO -> targetInterceptor = GeoField .class ;
245250 case VECTOR -> targetInterceptor = VectorField .class ;
246251 }
252+ } else if (indexed != null && targetCls == null && isEnum (processingEnv , fieldType )) {
253+ targetInterceptor = TextTagField .class ;
247254 } else if (targetCls != null ) {
248255 //
249256 // Any Character class -> Tag Search Field
@@ -493,8 +500,6 @@ private Map<? extends Element, String> getInstanceFields(Element element) {
493500 // Todo: Filter out methods that returns void or Void
494501 .collect (Collectors .toMap (e -> e .getSimpleName ().toString (), Function .identity ()));
495502
496- messager .printMessage (Diagnostic .Kind .NOTE , "getters size() ==> " + getters .size ());
497-
498503 final Set <String > isGetters = getters .values ().stream ()
499504 // todo: Filter out methods only returning boolean or Boolean
500505 .map (Element ::getSimpleName ).map (Object ::toString ).filter (n -> n .startsWith (IS_PREFIX )).map (n -> n .substring (2 ))
@@ -790,4 +795,14 @@ public static String replaceIfIllegalJavaIdentifierCharacter(final String word)
790795 private static final Set <String > JAVA_USED_WORDS_LOWER_CASE = Collections
791796 .unmodifiableSet (JAVA_USED_WORDS .stream ().map (String ::toLowerCase ).collect (Collectors .toSet ()));
792797
798+ private boolean isEnum (ProcessingEnvironment processingEnv , TypeMirror typeMirror ) {
799+ Types typeUtils = processingEnv .getTypeUtils ();
800+
801+ Element element = typeUtils .asElement (typeMirror );
802+ if (element != null ) {
803+ return element .getKind () == ElementKind .ENUM ;
804+ } else {
805+ return false ;
806+ }
807+ }
793808}
0 commit comments