Skip to content

Commit

Permalink
Apply review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dfuchss committed Aug 23, 2023
1 parent f732a2b commit 7e77a22
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,26 @@ private void applyConfiguration(SortedMap<String, String> additionalConfiguratio
applyConfiguration(additionalConfiguration, configurable, currentClassInHierarchy.getSuperclass());
}

/**
* Returns the key (for the configuration file) of a field. If the field is marked as ChildClassConfigurable, the key is based on the class of the
* configurable object. Otherwise, the key is based on the class where the field is defined.
*
* @param configurable the configurable object
* @param currentClassInHierarchy the class where the field is defined
* @param field the field
* @return the key of the field
*/
public static String getKeyOfField(AbstractConfigurable configurable, Class<?> currentClassInHierarchy, Field field) {
Configurable c = field.getAnnotation(Configurable.class);
ChildClassConfigurable ccc = field.getAnnotation(ChildClassConfigurable.class);
Configurable configurableAnnotation = field.getAnnotation(Configurable.class);
ChildClassConfigurable childClassConfigurableAnnotation = field.getAnnotation(ChildClassConfigurable.class);

if (ccc != null && !c.key().isBlank()) {
if (childClassConfigurableAnnotation != null && !configurableAnnotation.key().isBlank()) {
throw new IllegalStateException("You cannot define a key for a field that is marked as ChildClassConfigurable.");
}

String classOfDefinition = ccc == null ? currentClassInHierarchy.getSimpleName() : configurable.getClass().getSimpleName();
String classOfDefinition = childClassConfigurableAnnotation == null ? currentClassInHierarchy.getSimpleName() : configurable.getClass().getSimpleName();

return c.key().isBlank() ? (classOfDefinition + CLASS_ATTRIBUTE_CONNECTOR + field.getName()) : c.key();
return configurableAnnotation.key().isBlank() ? (classOfDefinition + CLASS_ATTRIBUTE_CONNECTOR + field.getName()) : configurableAnnotation.key();
}

private void setValue(Field field, String value) {
Expand Down

0 comments on commit 7e77a22

Please sign in to comment.