Skip to content

Commit

Permalink
Fix inferred type of array properties.
Browse files Browse the repository at this point in the history
The getValue() method on the QDox Type class returns the element type
as a string for array types. The code was using getValue() without
checking whether the type was an array type. The toString() method
returns the type name with array brackets for each array dimension,
which provides the type in the required format.
  • Loading branch information
martiell committed Mar 30, 2012
1 parent e25c3dd commit 84fea80
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
Expand Up @@ -146,7 +146,7 @@ private void attribute(MutableInstance instance, MutableContext context) {
logger.logNoSuchProperty(setter.getName(), cl.getName());
it.remove();
} else {
setter.setType(property.getType().getValue());
setter.setType(property.getType().toString());
setter.setPrimitive(property.getType().isPrimitive());
attribute(setter.getSource(), context);
}
Expand Down
Expand Up @@ -39,11 +39,13 @@

import static org.junit.Assert.assertEquals;

import java.util.ArrayList;
import java.util.List;

import me.springframework.di.Configuration;
import me.springframework.di.ConstructorArgument;
import me.springframework.di.Instance;
import me.springframework.di.PropertySetter;
import me.springframework.di.gen.factory.BeanFactoryGenerator;
import me.springframework.di.gen.factory.BeanFactoryTypes;
import me.springframework.test.Paths;
Expand Down Expand Up @@ -84,4 +86,27 @@ public TestBean(List<Number> x) {
}
}


public void testArrayPropertyHasCorrectType() throws Exception {
Resource resource = new ClassPathResource("/array.xml", getClass());
Configuration configuration = new ConfigurationBuilder()
.addSourceTree(Paths.getFile("src/test/java"))
.withBeanFactoryOf(resource)
.withConversions()
.build();

Instance stringTest = configuration.get("string-test");
assertEquals(ArrayHolder.class.getName(), stringTest.getType());
List<PropertySetter> setters =
new ArrayList<PropertySetter>(stringTest.getSetters());
assertEquals(1, setters.size());
PropertySetter strings = setters.get(0);
assertEquals("java.lang.String[]", strings.getType());
}

static class ArrayHolder {
void setStrings(String[] array) {
}
}

}
17 changes: 17 additions & 0 deletions spring-me-core/src/test/resources/array.xml
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">


<bean class="me.springframework.di.spring.SinkTypeTest$ArrayHolder"
name="string-test">
<property name="strings">
<list>
<value type="java.lang.String">Value 1</value>
<value type="java.lang.String">Value 2</value>
</list>
</property>
</bean>
</beans>

0 comments on commit 84fea80

Please sign in to comment.