22 * Copyright [2020] FormKiQ Inc. Licensed under the Apache License, Version 2.0 (the "License"); you
33 * may not use this file except in compliance with the License. You may obtain a copy of the License
44 * at
5- *
5+ *
66 * <p>http://www.apache.org/licenses/LICENSE-2.0
77 *
88 * <p>Unless required by applicable law or agreed to in writing, software distributed under the
5959
6060/** Processes {@link Reflectable} {@link ReflectableImport} Annotations. */
6161@ AutoService (Processor .class )
62- @ SupportedAnnotationTypes ({
63- "com.formkiq.graalvm.annotations.Reflectable" ,
64- "com.formkiq.graalvm.annotations.ReflectableImport" ,
65- "com.formkiq.graalvm.annotations.ReflectableClasses" ,
66- "com.formkiq.graalvm.annotations.ReflectableClass" ,
67- "com.formkiq.graalvm.annotations.ReflectableClass.ReflectableClasses"
68- })
62+ @ SupportedAnnotationTypes ({"com.formkiq.graalvm.annotations.Reflectable" ,
63+ "com.formkiq.graalvm.annotations.ReflectableImport" ,
64+ "com.formkiq.graalvm.annotations.ReflectableClasses" ,
65+ "com.formkiq.graalvm.annotations.ReflectableClass" ,
66+ "com.formkiq.graalvm.annotations.ReflectableClass.ReflectableClasses" })
6967@ SupportedSourceVersion (SourceVersion .RELEASE_11 )
7068public class GraalvmReflectAnnontationProcessor extends AbstractProcessor {
7169
@@ -106,8 +104,8 @@ private List<String> findClasses(final Element element, final String key) {
106104 Map <? extends ExecutableElement , ? extends AnnotationValue > elementValues =
107105 annotationMirror .getElementValues ();
108106
109- for (Map .Entry <? extends ExecutableElement , ? extends AnnotationValue > entry :
110- elementValues .entrySet ()) {
107+ for (Map .Entry <? extends ExecutableElement , ? extends AnnotationValue > entry : elementValues
108+ .entrySet ()) {
111109
112110 String simpleNameKey = entry .getKey ().getSimpleName ().toString ();
113111 Object value = entry .getValue ().getValue ();
@@ -146,10 +144,8 @@ private Class<?> forName(final String name) throws ClassNotFoundException {
146144
147145 int lastDotIndex = name .lastIndexOf (PACKAGE_SEPARATOR );
148146 if (lastDotIndex != -1 ) {
149- String innerClassName =
150- name .substring (0 , lastDotIndex )
151- + INNER_CLASS_SEPARATOR
152- + name .substring (lastDotIndex + 1 );
147+ String innerClassName = name .substring (0 , lastDotIndex ) + INNER_CLASS_SEPARATOR
148+ + name .substring (lastDotIndex + 1 );
153149 return forName (innerClassName );
154150 }
155151
@@ -159,22 +155,16 @@ private Class<?> forName(final String name) throws ClassNotFoundException {
159155
160156 String generateReflectConfigPath (final Set <String > keys ) {
161157
162- Set <String > strings =
163- keys .stream ()
164- .map (this ::removePartsContainingDotFollowedByCapital )
165- .filter (m -> m != null && m .length () > 1 )
166- .collect (Collectors .toSet ());
158+ Set <String > strings = keys .stream ().map (this ::removePartsContainingDotFollowedByCapital )
159+ .filter (m -> m != null && m .length () > 1 ).collect (Collectors .toSet ());
167160
168161 if (strings .isEmpty ()) {
169162 strings .add ("default" );
170163 }
171164 final int shortestLength = strings .stream ().mapToInt (String ::length ).min ().getAsInt ();
172165
173166 List <String > list =
174- strings .stream ()
175- .filter (s -> s .length () == shortestLength )
176- .sorted ()
177- .toList ();
167+ strings .stream ().filter (s -> s .length () == shortestLength ).sorted ().toList ();
178168
179169 return list .get (0 );
180170 }
@@ -194,9 +184,7 @@ private String getClassNameByType(final Element element) {
194184 case METHOD :
195185 className = ((TypeElement ) element .getEnclosingElement ()).getQualifiedName ().toString ();
196186 break ;
197- case ENUM :
198- case RECORD :
199- case CLASS :
187+ default :
200188 TypeElement te = (TypeElement ) element ;
201189
202190 List <String > simpleNames = new ArrayList <>();
@@ -216,9 +204,6 @@ private String getClassNameByType(final Element element) {
216204 className = e .substring (0 , pos ) + String .join ("$" , simpleNames );
217205 }
218206 }
219-
220- break ;
221- default :
222207 break ;
223208 }
224209
@@ -249,8 +234,8 @@ private Reflect getReflect(final String className) {
249234 }
250235
251236 @ Override
252- public boolean process (
253- final Set <? extends TypeElement > annotations , final RoundEnvironment roundEnv ) {
237+ public boolean process (final Set <? extends TypeElement > annotations ,
238+ final RoundEnvironment roundEnv ) {
254239
255240 if (roundEnv .processingOver ()) {
256241
@@ -276,8 +261,7 @@ public boolean process(
276261 private Reflect processClass (final Reflect reflect , final Reflectable reflectable ) {
277262
278263 LOGGER .log (LOGLEVEL , "processClass " + reflect .name ());
279- reflect
280- .allDeclaredConstructors (reflectable .allDeclaredConstructors ())
264+ reflect .allDeclaredConstructors (reflectable .allDeclaredConstructors ())
281265 .allDeclaredFields (reflectable .allDeclaredFields ())
282266 .allDeclaredMethods (reflectable .allDeclaredMethods ())
283267 .allPublicConstructors (reflectable .allPublicConstructors ())
@@ -297,8 +281,7 @@ private Reflect processClass(final Reflect reflect, final Reflectable reflectabl
297281 private Reflect processClass (final Reflect reflect , final ReflectableClass reflectable ) {
298282
299283 LOGGER .log (LOGLEVEL , "processClass " + reflect .name ());
300- reflect
301- .allDeclaredConstructors (reflectable .allDeclaredConstructors ())
284+ reflect .allDeclaredConstructors (reflectable .allDeclaredConstructors ())
302285 .allDeclaredFields (reflectable .allDeclaredFields ())
303286 .allDeclaredMethods (reflectable .allDeclaredMethods ())
304287 .allPublicConstructors (reflectable .allPublicConstructors ())
@@ -334,10 +317,8 @@ private void processImportedClass(final String clazz) {
334317 for (Method method : forName .getMethods ()) {
335318 Reflectable reflection = method .getAnnotation (Reflectable .class );
336319 if (reflection != null ) {
337- List <String > parameterTypes =
338- Arrays .stream (method .getParameters ())
339- .map (p -> p .getParameterizedType ().getTypeName ())
340- .collect (Collectors .toList ());
320+ List <String > parameterTypes = Arrays .stream (method .getParameters ())
321+ .map (p -> p .getParameterizedType ().getTypeName ()).collect (Collectors .toList ());
341322
342323 LOGGER .log (LOGLEVEL , "adding Method " + method .getName () + " to " + clazz );
343324 reflect .addMethod (method .getName (), parameterTypes );
@@ -425,22 +406,15 @@ private void processingReflectable(final RoundEnvironment roundEnv) {
425406 case METHOD :
426407 String methodName = element .getSimpleName ().toString ();
427408
428- List <String > parameterTypes =
429- ((ExecutableElement ) element )
430- .getParameters ().stream ()
431- .map (param -> param .asType ().toString ())
432- .collect (Collectors .toList ());
409+ List <String > parameterTypes = ((ExecutableElement ) element ).getParameters ().stream ()
410+ .map (param -> param .asType ().toString ()).collect (Collectors .toList ());
433411
434412 LOGGER .log (LOGLEVEL , "adding Method " + methodName + " to " + className );
435413 reflect .addMethod (methodName , parameterTypes );
436414 break ;
437- case ENUM :
438- case RECORD :
439- case CLASS :
415+ default :
440416 reflect = processClass (reflect , reflectable );
441417 break ;
442- default :
443- throw new RuntimeException ("Unsupported kind of element: " + element .getKind ());
444418 }
445419 }
446420 }
@@ -520,9 +494,8 @@ private void processReflectableClasses(final RoundEnvironment roundEnv) {
520494 }
521495 }
522496
523- Set <? extends Element > reflectableClasses =
524- roundEnv .getElementsAnnotatedWithAny (
525- Set .of (ReflectableClass .class , ReflectableClass .ReflectableClasses .class ));
497+ Set <? extends Element > reflectableClasses = roundEnv .getElementsAnnotatedWithAny (
498+ Set .of (ReflectableClass .class , ReflectableClass .ReflectableClasses .class ));
526499
527500 for (Element element : reflectableClasses ) {
528501 String className = getClassNameByType (element );
@@ -536,8 +509,7 @@ private void processReflectableClasses(final RoundEnvironment roundEnv) {
536509 }
537510
538511 private String removePartsContainingDotFollowedByCapital (final String input ) {
539- return Arrays .stream (input .split ("\\ ." ))
540- .filter (part -> !part .matches ("\\ p{Upper}.*" ))
512+ return Arrays .stream (input .split ("\\ ." )).filter (part -> !part .matches ("\\ p{Upper}.*" ))
541513 .collect (Collectors .joining ("." ));
542514 }
543515
@@ -548,13 +520,8 @@ private void writeOutput() {
548520
549521 String name = generateReflectConfigPath (this .reflects .keySet ());
550522
551- FileObject file =
552- this .processingEnv
553- .getFiler ()
554- .createResource (
555- StandardLocation .CLASS_OUTPUT ,
556- "" ,
557- "META-INF/native-image/" + name + "/reflect-config.json" );
523+ FileObject file = this .processingEnv .getFiler ().createResource (StandardLocation .CLASS_OUTPUT ,
524+ "" , "META-INF/native-image/" + name + "/reflect-config.json" );
558525
559526 List <Map <String , Object >> data =
560527 this .reflects .values ().stream ().map (Reflect ::data ).collect (Collectors .toList ());
0 commit comments