diff --git a/ng-core/src/main/java/ng/kvc/NGKeyValueCodingSupport.java b/ng-core/src/main/java/ng/kvc/NGKeyValueCodingSupport.java index f1d4421b..3e7669e0 100644 --- a/ng-core/src/main/java/ng/kvc/NGKeyValueCodingSupport.java +++ b/ng-core/src/main/java/ng/kvc/NGKeyValueCodingSupport.java @@ -17,11 +17,12 @@ public class NGKeyValueCodingSupport { * * FIXME: Currently only using exact keys, missing all the KVC method name munging, strip prefixes (underbar, "get") etc. // Hugi 2024-10-10 * FIXME: Altogether experimental, we'll have to have a better look at this design-wise // Hugi 2024-10-10 + * FIXME: We're probably going to want a separate method that can check instances as well (for example, applicable when we add support for rseolving keys on Maps) // Hugi 2024-10-10 */ - public static List availableKeyPaths( Object object ) { + public static List availableKeyPaths( final Class objectClass ) { final List result = new ArrayList<>(); - for( Method method : object.getClass().getMethods() ) { + for( Method method : objectClass.getClass().getMethods() ) { if( method.getParameterCount() == 0 ) { if( !method.getReturnType().isAssignableFrom( Void.class ) ) { result.add( method.getName() ); @@ -29,7 +30,7 @@ public static List availableKeyPaths( Object object ) { } } - for( Field field : object.getClass().getFields() ) { + for( Field field : objectClass.getClass().getFields() ) { result.add( field.getName() ); } @@ -39,17 +40,16 @@ public static List availableKeyPaths( Object object ) { /** * @return A list of suggestions for the given key when trying to apply it to the given object. Really just a list of the object's available keys, ordered by the edit distance from the proposed key */ - public static List suggestions( Object object, String proposedKey ) { + public static List suggestions( final Object object, final String proposedKey ) { record Suggestion( int distance, String key ) {} - return availableKeyPaths( object ) + return availableKeyPaths( object.getClass() ) .stream() .map( key -> new Suggestion( distanceLevenshtein( key, proposedKey ), key ) ) .sorted( Comparator.comparing( Suggestion::distance ) ) .map( Suggestion::key ) .toList(); - } /**