diff --git a/src/main/java/org/javarosa/core/model/FormDef.java b/src/main/java/org/javarosa/core/model/FormDef.java index accc8735b5..c1af573594 100755 --- a/src/main/java/org/javarosa/core/model/FormDef.java +++ b/src/main/java/org/javarosa/core/model/FormDef.java @@ -1355,27 +1355,42 @@ public void populateDynamicChoices(ItemsetBinding itemset, TreeReference curQRef ec.setQueryContext(newContext); for (int i = 0; i < matches.size(); i++) { - choices.addElement(buildSelectChoice(matches.elementAt(i), itemset, formInstance, ec, i)); + choices.addElement(buildSelectChoice(matches.elementAt(i), itemset, formInstance, + ec, reporter, i)); } itemset.setChoices(choices); } private SelectChoice buildSelectChoice(TreeReference choiceRef, ItemsetBinding itemset, - DataInstance formInstance, EvaluationContext ec, int index) { + DataInstance formInstance, EvaluationContext ec, + ReducingTraceReporter reporter, int index) { + String label = itemset.labelExpr.evalReadable(formInstance, new EvaluationContext(ec, choiceRef)); + + if(reporter != null) { + InstrumentationUtils.printAndClearTraces(reporter, "ItemSet [label] population"); + } + String value = null; TreeElement copyNode = null; + if (itemset.copyMode) { copyNode = this.getMainInstance().resolveReference(itemset.copyRef.contextualize(choiceRef)); } + if (itemset.valueRef != null) { value = itemset.valueExpr.evalReadable(formInstance, new EvaluationContext(ec, choiceRef)); } + if(reporter != null) { + InstrumentationUtils.printAndClearTraces(reporter, "ItemSet [value] population"); + } + SelectChoice choice = new SelectChoice(label, value != null ? value : "dynamic:" + index, itemset.labelIsItext); + choice.setIndex(index); if (itemset.copyMode) { @@ -1388,11 +1403,11 @@ private SelectChoice buildSelectChoice(TreeReference choiceRef, ItemsetBinding i choice.setSortProperty(evaluatedSortProperty); } - return choice; - if(reporter != null) { - InstrumentationUtils.printAndClearTraces(reporter, "itemset population"); + InstrumentationUtils.printAndClearTraces(reporter, "ItemSet [sort] population"); } + + return choice; } public String toString() { diff --git a/src/test/java/org/javarosa/core/model/utils/test/LocalizerTest.java b/src/test/java/org/javarosa/core/model/utils/test/LocalizerTest.java index 214d2bf9c5..bb85397bd4 100644 --- a/src/test/java/org/javarosa/core/model/utils/test/LocalizerTest.java +++ b/src/test/java/org/javarosa/core/model/utils/test/LocalizerTest.java @@ -643,7 +643,7 @@ public void testLinearSub() { public void run() { holder[0] = Localizer.processArguments("${0}", new String[]{C}); } - }); + }, "Argument processing: " + C); assertEquals(holder[0], C); @@ -653,7 +653,7 @@ public void run() { public void run() { holder[0] = Localizer.processArguments("${0}", new String[]{D}); } - }); + }, "Argument processing: " + D); assertEquals(holder[0], D); @@ -662,7 +662,7 @@ public void run() { public void run() { holder[0] = Localizer.processArguments(holder[0], res); } - }); + }, "Argument processing: " + res[1] + res[0]); assertEquals(holder[0], res[1] + res[0]); @@ -671,13 +671,13 @@ public void run() { public void run() { holder[0] = Localizer.processArguments("$ {0} ${1}", res); } - }); + }, "Argument processing: " + "$ {0} " + res[1]); assertEquals(holder[0], "$ {0} " + res[1]); } - private void runAsync(Runnable test) { + private void runAsync(Runnable test, String label) { Thread t = new Thread(test); t.start(); try { @@ -687,7 +687,7 @@ private void runAsync(Runnable test) { } if (t.isAlive()) { t.stop(); - throw new RuntimeException("Failed to return from recursive argument processing"); + throw new RuntimeException("Failed to return from recursive argument processing: "+ label); } }