Details
-
Improvement
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
0.3-incubating
-
None
Description
Current Situation
Currently key resolution is very complex and leads to many different keys potentially being looked up. Given the following class:
package a.b.c; public class Injected{ @Config("myProp", "myFallbackProp") private String property; }
Would evaluate to the following key lookup chain:
a.b.c.Injected.myProp a.b.c.Injected.myFallbackProp Injected.myProp Injected.myFallbackProp myProp myFallbackProp
Proposal
This is weird to the user, so the proposal is to
- Separate the main from the fallback keys
- Allow to define how to combine the (field)property key, with the class key.
Therefore the @Config annotation should be adapted as follows:
public @interface Config { String UNCONFIGURED_VALUE = ...; String key() default ""; KeyResolution keyResolution() default KeyResolution.AUTO; String[] alternateKeys() default {}; String defaultValue() default UNCONFIGURED_VALUE; boolean required() default true; }
Herebythe enum type KeyResolution defines how the property key(s) are evaluated:
- AUTO: This is the default key resolution strateg. The targeting key is evaluated as follows:
- The containing class does not have a @ConfigSection annotation and the field/method does not have a @Config annotation:
the main key equals to
Owning.class.getSimpleName() + '.' + propertyKey.
{{This equals to }}RELATIVE_SIMPLE. - The containing class does not have a @ConfigArea annotation:
the main key equals to
propertyKey.
This equals to ABSOLUTE
- The containing class does not have a @ConfigSection annotation and the field/method does not have a @Config annotation:
-
- The containing class does have a @ConfigArea annotation:
the main key equals to
_sectionAnnotation.getValue() + '.' + propertyKe_y.
- The containing class does have a @ConfigArea annotation:
- RELATIVE_SIMPLE: The targeting key is evaluated to
Owner.class.getSimpleName() + '.' + * propertyKey - RELATIVE_FQN: ** The targeting key is evaluated to
Owner.class.getName() + '.' + * propertyKey - ABSOLUTE: The targeting key is evaluated to propertyKey.
Hereby this resolution policy only applies to the main property key, modelled by key(), whereas fallback keys always are considered as ABSOLUTE keys.
Example
Given the following class:
package a.b.c; public class Injected{ @Config(key="myProp", fallbackKeys={"myFallbackProp"}) private String property; }
Would evaluate to the following key lookup chain:
Injected.myProp myFallbackProp
Using KeyResolution.ABSOLUTE the keys would be:
myProp myFallbackProp
Using KeyResolution.RELATIVE_FQN the keys would be:
a.b.c.Injected.myProp myFallbackProp
This drastically reduces the keyset and makes the resolution more explicit and less magic IMO.