@@ -52,13 +52,15 @@ public final class ReflectionConfigurationParser<T> extends ConfigurationParser
5252 "allDeclaredClasses" , "allRecordComponents" , "allPermittedSubclasses" , "allNestMembers" , "allSigners" ,
5353 "allPublicClasses" , "methods" , "queriedMethods" , "fields" , CONDITIONAL_KEY ,
5454 "queryAllDeclaredConstructors" , "queryAllPublicConstructors" , "queryAllDeclaredMethods" , "queryAllPublicMethods" , "unsafeAllocated" );
55+ private final boolean printMissingElements ;
5556
5657 public ReflectionConfigurationParser (ReflectionConfigurationParserDelegate <T > delegate ) {
57- this (delegate , true );
58+ this (delegate , true , false );
5859 }
5960
60- public ReflectionConfigurationParser (ReflectionConfigurationParserDelegate <T > delegate , boolean strictConfiguration ) {
61+ public ReflectionConfigurationParser (ReflectionConfigurationParserDelegate <T > delegate , boolean strictConfiguration , boolean printMissingElements ) {
6162 super (strictConfiguration );
63+ this .printMissingElements = printMissingElements ;
6264 this .delegate = delegate ;
6365 }
6466
@@ -91,7 +93,7 @@ private void parseClass(EconomicMap<String, Object> data) {
9193 */
9294 TypeResult <T > result = delegate .resolveType (condition , className , true );
9395 if (!result .isPresent ()) {
94- handleError ("Could not resolve class " + className + " for reflection configuration." , result .getException ());
96+ handleMissingElement ("Could not resolve class " + className + " for reflection configuration." , result .getException ());
9597 return ;
9698 }
9799 T clazz = result .get ();
@@ -199,7 +201,7 @@ private void parseClass(EconomicMap<String, Object> data) {
199201 break ;
200202 }
201203 } catch (LinkageError e ) {
202- handleError ("Could not register " + delegate .getTypeName (clazz ) + ": " + name + " for reflection." , e );
204+ handleMissingElement ("Could not register " + delegate .getTypeName (clazz ) + ": " + name + " for reflection." , e );
203205 }
204206 }
205207 }
@@ -218,9 +220,9 @@ private void parseField(EconomicMap<String, Object> data, T clazz) {
218220 try {
219221 delegate .registerField (clazz , fieldName , allowWrite );
220222 } catch (NoSuchFieldException e ) {
221- handleError ("Field " + formatField (clazz , fieldName ) + " not found." );
223+ handleMissingElement ("Field " + formatField (clazz , fieldName ) + " not found." );
222224 } catch (LinkageError e ) {
223- handleError ("Could not register field " + formatField (clazz , fieldName ) + " for reflection." , e );
225+ handleMissingElement ("Could not register field " + formatField (clazz , fieldName ) + " for reflection." , e );
224226 }
225227 }
226228
@@ -251,9 +253,9 @@ private void parseMethod(boolean queriedOnly, EconomicMap<String, Object> data,
251253 delegate .registerMethod (queriedOnly , clazz , methodName , methodParameterTypes );
252254 }
253255 } catch (NoSuchMethodException e ) {
254- handleError ("Method " + formatMethod (clazz , methodName , methodParameterTypes ) + " not found." );
256+ handleMissingElement ("Method " + formatMethod (clazz , methodName , methodParameterTypes ) + " not found." );
255257 } catch (LinkageError e ) {
256- handleError ("Could not register method " + formatMethod (clazz , methodName , methodParameterTypes ) + " for reflection." , e );
258+ handleMissingElement ("Could not register method " + formatMethod (clazz , methodName , methodParameterTypes ) + " for reflection." , e );
257259 }
258260 } else {
259261 try {
@@ -267,7 +269,7 @@ private void parseMethod(boolean queriedOnly, EconomicMap<String, Object> data,
267269 throw new JSONParserException ("Method " + formatMethod (clazz , methodName ) + " not found" );
268270 }
269271 } catch (LinkageError e ) {
270- handleError ("Could not register method " + formatMethod (clazz , methodName ) + " for reflection." , e );
272+ handleMissingElement ("Could not register method " + formatMethod (clazz , methodName ) + " for reflection." , e );
271273 }
272274 }
273275 }
@@ -278,7 +280,7 @@ private List<T> parseMethodParameters(T clazz, String methodName, List<Object> t
278280 String typeName = asString (type , "types" );
279281 TypeResult <T > typeResult = delegate .resolveType (ConfigurationCondition .alwaysTrue (), typeName , true );
280282 if (!typeResult .isPresent ()) {
281- handleError ("Could not register method " + formatMethod (clazz , methodName ) + " for reflection." , typeResult .getException ());
283+ handleMissingElement ("Could not register method " + formatMethod (clazz , methodName ) + " for reflection." , typeResult .getException ());
282284 return null ;
283285 }
284286 result .add (typeResult .get ());
@@ -303,15 +305,17 @@ private String formatMethod(T clazz, String methodName, List<T> paramTypes) {
303305 return delegate .getTypeName (clazz ) + '.' + methodName + '(' + parameterTypeNames + ')' ;
304306 }
305307
306- private static void handleError (String message ) {
307- handleError (message , null );
308+ private void handleMissingElement (String message ) {
309+ handleMissingElement (message , null );
308310 }
309311
310- private static void handleError (String msg , Throwable cause ) {
311- String message = msg ;
312- if (cause != null ) {
313- message += " Reason: " + formatError (cause ) + '.' ;
312+ private void handleMissingElement (String msg , Throwable cause ) {
313+ if (printMissingElements ) {
314+ String message = msg ;
315+ if (cause != null ) {
316+ message += " Reason: " + formatError (cause ) + '.' ;
317+ }
318+ LogUtils .warning (message );
314319 }
315- LogUtils .warning (message );
316320 }
317321}
0 commit comments