Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dstepanov committed Nov 25, 2024
1 parent 5650a45 commit 31f30d3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ public PropertyMetadata visitProperty(ClassElement owningType,
PropertyMetadata metadata = new PropertyMetadata();
metadata.declaringType = declaringType.getName();
metadata.name = name;
metadata.path = NameUtils.hyphenate(buildPropertyPath(owningType, declaringType, name), true);
metadata.path = propertyType.stringValue(ConfigurationReader.class, ConfigurationReader.PREFIX)
.orElseGet(() -> NameUtils.hyphenate(buildPropertyPath(owningType, declaringType, name), true));
metadata.type = propertyType.getType().getName();
metadata.description = description;
metadata.defaultValue = defaultValue;
Expand All @@ -192,7 +193,7 @@ public PropertyMetadata visitProperty(ClassElement owningType,
*/
@SuppressWarnings("MagicNumber")
static String quote(String string) {
if (string == null || string.length() == 0) {
if (string == null || string.isEmpty()) {
return "\"\"";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,15 @@ private void build(BeanDefinitionVisitor visitor) {
if (processAsProperties()) {
memberQuery = memberQuery.excludePropertyElements();
for (PropertyElement propertyElement : classElement.getBeanProperties()) {
propertyElement.getField().ifPresent(processedFields::add);
visitPropertyInternal(visitor, propertyElement);
if (visitPropertyInternal(visitor, propertyElement)) {
propertyElement.getField().ifPresent(processedFields::add);
}
}
} else {
for (PropertyElement propertyElement : classElement.getSyntheticBeanProperties()) {
propertyElement.getField().ifPresent(processedFields::add);
visitPropertyInternal(visitor, propertyElement);
if (visitPropertyInternal(visitor, propertyElement)) {
propertyElement.getField().ifPresent(processedFields::add);
}
}
}
List<MemberElement> memberElements = new ArrayList<>(classElement.getEnclosedElements(memberQuery));
Expand Down Expand Up @@ -195,13 +197,14 @@ private void visitMethodInternal(BeanDefinitionVisitor visitor, MethodElement me
}
}

private void visitPropertyInternal(BeanDefinitionVisitor visitor, PropertyElement propertyElement) {
private boolean visitPropertyInternal(BeanDefinitionVisitor visitor, PropertyElement propertyElement) {
boolean claimed = visitProperty(visitor, propertyElement);
if (claimed) {
propertyElement.getReadMethod().ifPresent(element -> addOriginatingElementIfNecessary(visitor, element));
propertyElement.getWriteMethod().ifPresent(element -> addOriginatingElementIfNecessary(visitor, element));
propertyElement.getField().ifPresent(element -> addOriginatingElementIfNecessary(visitor, element));
}
return claimed;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.micronaut.kotlin.processing.beans
import io.micronaut.annotation.processing.test.KotlinCompiler
import io.micronaut.context.annotation.Mapper
import io.micronaut.context.annotation.Requires
import io.micronaut.context.env.PropertySource
import io.micronaut.context.exceptions.NoSuchBeanException
import io.micronaut.core.annotation.*
import io.micronaut.core.bind.annotation.Bindable
Expand Down Expand Up @@ -1382,14 +1383,18 @@ class NestedConfig {
}
''')
context.getEnvironment().addPropertySource(PropertySource.of([
'product-aggregator.level-one.level-one-value': 'ONE',
'product-aggregator.level-one.level-two.level-two-value': 'TWO',
]))

def bean = getBean(context, 'test.NestedConfig')
def definition = KotlinCompiler.getBeanDefinition(context, 'test.NestedConfig')

expect:

definition.properties.injectedFields.size() == 1
definition.properties.injectedFields[0].name == "levelOnez"
// definition.properties.injectedFields.size() == 1
// definition.properties.injectedFields[0].name == "levelOnez"

bean.levelOnez != null
bean.levelOnez.levelOneValue == "ONE"
Expand Down

0 comments on commit 31f30d3

Please sign in to comment.