Commit 50920190 authored by Stephane Nicoll's avatar Stephane Nicoll

Polish default value for arrays

See gh-1996
parent f821fdff
...@@ -144,8 +144,9 @@ The JSON object contained in the `properties` array can contain the following at ...@@ -144,8 +144,9 @@ The JSON object contained in the `properties` array can contain the following at
|`defaultValue` |`defaultValue`
| Object | Object
| The default value which will be used if the property is not specified. May be omitted | The default value which will be used if the property is not specified. Can also be an
if the default value is not known. array of value(s) if the type of the property is an array. May be omitted if the default
value is not known.
|`deprecated` |`deprecated`
| boolean | boolean
......
...@@ -124,7 +124,11 @@ public class JavaCompilerFieldValuesParser implements FieldValuesParser { ...@@ -124,7 +124,11 @@ public class JavaCompilerFieldValuesParser implements FieldValuesParser {
if (arrayValues != null) { if (arrayValues != null) {
Object[] result = new Object[arrayValues.size()]; Object[] result = new Object[arrayValues.size()];
for (int i = 0; i < arrayValues.size(); i++) { for (int i = 0; i < arrayValues.size(); i++) {
result[i] = getValue(arrayValues.get(i), null); Object value = getValue(arrayValues.get(i), null);
if (value == null) { // One of the elements could not be resolved
return defaultValue;
}
result[i] = value;
} }
return result; return result;
} }
......
...@@ -84,6 +84,7 @@ public abstract class AbstractFieldValuesProcessorTests { ...@@ -84,6 +84,7 @@ public abstract class AbstractFieldValuesProcessorTests {
assertThat(values.get("stringArrayConst"), equalToObject(new Object[]{"OK", "KO"})); assertThat(values.get("stringArrayConst"), equalToObject(new Object[]{"OK", "KO"}));
assertThat(values.get("stringArrayConstElements"), equalToObject(new Object[] {"c"})); assertThat(values.get("stringArrayConstElements"), equalToObject(new Object[] {"c"}));
assertThat(values.get("integerArray"), equalToObject(new Object[] {42, 24})); assertThat(values.get("integerArray"), equalToObject(new Object[] {42, 24}));
assertThat(values.get("unknownArray"), nullValue());
} }
private Matcher<Object> equalToObject(Object object) { private Matcher<Object> equalToObject(Object object) {
......
...@@ -90,4 +90,6 @@ public class FieldValues { ...@@ -90,4 +90,6 @@ public class FieldValues {
private Integer[] integerArray = new Integer[] {42, 24}; private Integer[] integerArray = new Integer[] {42, 24};
private FieldValues[] unknownArray = new FieldValues[] {new FieldValues()};
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment