All,
Arjen and I have just added IntelliBean(tm) support to Spring!
Error messages resulting from typos in XML files will now be accompanied
with suggestions. Some examples:
class Person {
public setName(String name);
public setMyString(String string);
public setMyStrings(String string);
}
<bean class="Person">
<property name="names" value="John"/>
</bean>
--> exception message: Invalid property 'names' ..... Did you mean 'name'?
<bean class="Person">
<!-- notice the lowercase mystring property -->
<property name="mystring" value="blah"/>
</bean>
--> exception message: Invalid property 'mystring' ..... Did you mean
'myString' or 'myStrings'?
Juergen, there's a findPossibleAlternatives() method in the
BeanWrapperImpl and we've added an additional constructor to the
NotWritablePropertyException taking a String[] containing possible
alternatives. A corresponding message is generated at construction time.
I could only find one place to generate possible alternatives in the
BeanWrapperImpl (in the setPropertyValue() method).
There might be some possible optimizations in the Levenshtein algorithms
(using a three-dimensional array instead of a two-dimensional one two
prevent the algorithm from being executed once for every property), but
since the generation of alternatives is only done when throwing an
exception anyway, that's not a big deal I guess for now.
Comments welcome!
regards,
Alef
p.s. modifications in BeanWrapperImpl, BeanWrapperTests,
NotWriteablePropertyException
|