2828import java .lang .reflect .Field ;
2929import java .lang .reflect .Method ;
3030import java .net .URL ;
31+ import java .nio .charset .StandardCharsets ;
3132import java .nio .file .Files ;
3233import java .util .ArrayList ;
3334import java .util .Arrays ;
@@ -78,9 +79,9 @@ public class GraalvmReflectAnnontationProcessor extends AbstractProcessor {
7879 /** The package separator character: '.'. */
7980 private static final char PACKAGE_SEPARATOR = '.' ;
8081 /** {@link Gson}. */
81- private Gson gson = new GsonBuilder ().disableHtmlEscaping ().create ();
82+ private final Gson gson = new GsonBuilder ().disableHtmlEscaping ().create ();
8283 /** {@link List} of {@link Reflect}. */
83- private Map <String , Reflect > reflects = new HashMap <>();
84+ private final Map <String , Reflect > reflects = new HashMap <>();
8485
8586 private TypeElement asTypeElement (final TypeMirror typeMirror ) {
8687 Types typeUtils = this .processingEnv .getTypeUtils ();
@@ -117,7 +118,7 @@ private List<String> findClasses(final Element element, final String key) {
117118 List <? extends AnnotationValue > typeMirrors = (List <? extends AnnotationValue >) value ;
118119
119120 for (AnnotationValue val : typeMirrors ) {
120- String clazz = (( TypeMirror ) val .getValue () ).toString ();
121+ String clazz = val .getValue ().toString ();
121122
122123 LOGGER .log (LOGLEVEL , "processing ImportedClass " + clazz );
123124 processImportedClass (clazz );
@@ -160,7 +161,7 @@ String generateReflectConfigPath(final Set<String> keys) {
160161
161162 Set <String > strings =
162163 keys .stream ()
163- .map (m -> removePartsContainingDotFollowedByCapital ( m ) )
164+ .map (this :: removePartsContainingDotFollowedByCapital )
164165 .filter (m -> m != null && m .length () > 1 )
165166 .collect (Collectors .toSet ());
166167
@@ -173,7 +174,7 @@ String generateReflectConfigPath(final Set<String> keys) {
173174 strings .stream ()
174175 .filter (s -> s .length () == shortestLength )
175176 .sorted ()
176- .collect ( Collectors . toList () );
177+ .toList ();
177178
178179 return list .get (0 );
179180 }
@@ -194,6 +195,7 @@ private String getClassNameByType(final Element element) {
194195 className = ((TypeElement ) element .getEnclosingElement ()).getQualifiedName ().toString ();
195196 break ;
196197 case ENUM :
198+ case RECORD :
197199 case CLASS :
198200 TypeElement te = (TypeElement ) element ;
199201
@@ -211,7 +213,7 @@ private String getClassNameByType(final Element element) {
211213
212214 int pos = e .indexOf (simpleNames .get (0 ));
213215 if (pos > 0 ) {
214- className = e .substring (0 , pos ) + simpleNames . stream (). collect ( Collectors . joining ( "$" ) );
216+ className = e .substring (0 , pos ) + String . join ( "$" , simpleNames );
215217 }
216218 }
217219
@@ -275,12 +277,12 @@ private Reflect processClass(final Reflect reflect, final Reflectable reflectabl
275277
276278 LOGGER .log (LOGLEVEL , "processClass " + reflect .name ());
277279 reflect
278- .allDeclaredConstructors (Boolean . valueOf ( reflectable .allDeclaredConstructors () ))
279- .allDeclaredFields (Boolean . valueOf ( reflectable .allDeclaredFields () ))
280- .allDeclaredMethods (Boolean . valueOf ( reflectable .allDeclaredMethods () ))
281- .allPublicConstructors (Boolean . valueOf ( reflectable .allPublicConstructors () ))
282- .allPublicFields (Boolean . valueOf ( reflectable .allPublicFields () ))
283- .allPublicMethods (Boolean . valueOf ( reflectable .allPublicMethods () ));
280+ .allDeclaredConstructors (reflectable .allDeclaredConstructors ())
281+ .allDeclaredFields (reflectable .allDeclaredFields ())
282+ .allDeclaredMethods (reflectable .allDeclaredMethods ())
283+ .allPublicConstructors (reflectable .allPublicConstructors ())
284+ .allPublicFields (reflectable .allPublicFields ())
285+ .allPublicMethods (reflectable .allPublicMethods ());
284286
285287 return reflect ;
286288 }
@@ -296,12 +298,12 @@ private Reflect processClass(final Reflect reflect, final ReflectableClass refle
296298
297299 LOGGER .log (LOGLEVEL , "processClass " + reflect .name ());
298300 reflect
299- .allDeclaredConstructors (Boolean . valueOf ( reflectable .allDeclaredConstructors () ))
300- .allDeclaredFields (Boolean . valueOf ( reflectable .allDeclaredFields () ))
301- .allDeclaredMethods (Boolean . valueOf ( reflectable .allDeclaredMethods () ))
302- .allPublicConstructors (Boolean . valueOf ( reflectable .allPublicConstructors () ))
303- .allPublicFields (Boolean . valueOf ( reflectable .allPublicFields () ))
304- .allPublicMethods (Boolean . valueOf ( reflectable .allPublicMethods () ));
301+ .allDeclaredConstructors (reflectable .allDeclaredConstructors ())
302+ .allDeclaredFields (reflectable .allDeclaredFields ())
303+ .allDeclaredMethods (reflectable .allDeclaredMethods ())
304+ .allPublicConstructors (reflectable .allPublicConstructors ())
305+ .allPublicFields (reflectable .allPublicFields ())
306+ .allPublicMethods (reflectable .allPublicMethods ());
305307
306308 return reflect ;
307309 }
@@ -333,7 +335,7 @@ private void processImportedClass(final String clazz) {
333335 Reflectable reflection = method .getAnnotation (Reflectable .class );
334336 if (reflection != null ) {
335337 List <String > parameterTypes =
336- Arrays .asList (method .getParameters ()). stream ( )
338+ Arrays .stream (method .getParameters ())
337339 .map (p -> p .getParameterizedType ().getTypeName ())
338340 .collect (Collectors .toList ());
339341
@@ -374,7 +376,7 @@ private void processImportFiles(final Element element) {
374376
375377 for (String file : reflectImport .files ()) {
376378
377- if (file .length () > 0 ) {
379+ if (! file .isEmpty () ) {
378380 try {
379381
380382 ClassLoader classLoader = getClass ().getClassLoader ();
@@ -431,14 +433,14 @@ private void processingReflectable(final RoundEnvironment roundEnv) {
431433
432434 LOGGER .log (LOGLEVEL , "adding Method " + methodName + " to " + className );
433435 reflect .addMethod (methodName , parameterTypes );
434-
435436 break ;
436437 case ENUM :
438+ case RECORD :
437439 case CLASS :
438440 reflect = processClass (reflect , reflectable );
439441 break ;
440442 default :
441- break ;
443+ throw new RuntimeException ( "Unsupported kind of element: " + element . getKind ()) ;
442444 }
443445 }
444446 }
@@ -555,9 +557,9 @@ private void writeOutput() {
555557 "META-INF/native-image/" + name + "/reflect-config.json" );
556558
557559 List <Map <String , Object >> data =
558- this .reflects .values ().stream ().map (r -> r . data () ).collect (Collectors .toList ());
560+ this .reflects .values ().stream ().map (Reflect :: data ).collect (Collectors .toList ());
559561
560- try (Writer w = new OutputStreamWriter (file .openOutputStream (), "UTF-8" )) {
562+ try (Writer w = new OutputStreamWriter (file .openOutputStream (), StandardCharsets . UTF_8 )) {
561563 w .write (this .gson .toJson (data ));
562564 }
563565
0 commit comments