Skip to content

Commit aebf407

Browse files
Settle on looking up 'get'-prefixed methods first in KVC
1 parent 2b8f186 commit aebf407

File tree

1 file changed

+7
-22
lines changed

1 file changed

+7
-22
lines changed

ng-core/src/main/java/ng/kvc/NGKeyValueCoding.java

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* FIXME: Decide if we're going to go all the way and do validation and error handling
2323
* FIXME: We should be using cached MethodHandles for improved performance
2424
*
25-
* Lookup order when searching for a readable binding:
25+
* Lookup order when searching for readable binding for key 'smu':
2626
*
2727
* 1. Method "getSmu"
2828
* 2. Method "smu"
@@ -116,26 +116,24 @@ public static void takeValueForKey( final Object object, final Object value, fin
116116

117117
/**
118118
* @return A KVC binding for the given class and key.
119-
*
120-
* FIXME: KVC in WebObjects follows a slightly different method ordering. Our ordering is different in the way that we try for the exact key name first, for both methods and fields. In other terms, our lookup order is the same. Consider if this is the correct approach // Hugi 2022-10-22
121119
*/
122120
private static KVCReadBinding readBindingForKey( final Object object, final String key ) {
123121
Objects.requireNonNull( object );
124122
Objects.requireNonNull( key );
125123

126124
Method method;
127125

128-
// First we try for just the key
129-
method = readMethod( object, key );
126+
final String keyCapitalized = key.substring( 0, 1 ).toUpperCase() + key.substring( 1 );
127+
128+
// Ugly old bean-style getMethod()
129+
method = readMethod( object, "get" + keyCapitalized );
130130

131131
if( method != null ) {
132132
return new MethodReadBinding( method );
133133
}
134134

135-
final String keyCapitalized = key.substring( 0, 1 ).toUpperCase() + key.substring( 1 );
136-
137-
// Now we try the old bean-style getMethod()
138-
method = readMethod( object, "get" + keyCapitalized );
135+
// A method with the exact key name
136+
method = readMethod( object, key );
139137

140138
if( method != null ) {
141139
return new MethodReadBinding( method );
@@ -478,19 +476,6 @@ public static Object convertValueToFieldType( Object value, Class<?> targetType
478476
}
479477
}
480478

481-
// FIXME: Probably not needed?
482-
// public static class NumericMethodReadBinding extends MethodReadBinding {
483-
//
484-
// public NumericMethodReadBinding( Method method ) {
485-
// super( method );
486-
// }
487-
//
488-
// @Override
489-
// public Object valueInObject( Object object ) {
490-
// return super.valueInObject( object );
491-
// }
492-
// }
493-
494479
public static class NumericMethodWriteBinding extends MethodWriteBinding {
495480

496481
public NumericMethodWriteBinding( Method method ) {

0 commit comments

Comments
 (0)