Mercurial > hg > truffle
changeset 12735:bb85b81258a0
modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues()
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Sat, 09 Nov 2013 12:04:24 +0100 |
parents | 2caa21ef52bb |
children | a5b5e1ebab81 |
files | graal/com.oracle.graal.options.test/src/com/oracle/graal/options/test/TestOptionValue.java graal/com.oracle.graal.options/src/com/oracle/graal/options/OptionValue.java |
diffstat | 2 files changed, 66 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/graal/com.oracle.graal.options.test/src/com/oracle/graal/options/test/TestOptionValue.java Fri Nov 08 18:34:57 2013 +0100 +++ b/graal/com.oracle.graal.options.test/src/com/oracle/graal/options/test/TestOptionValue.java Sat Nov 09 12:04:24 2013 +0100 @@ -25,6 +25,8 @@ import static com.oracle.graal.options.test.TestOptionValue.Options.*; import static org.junit.Assert.*; +import java.util.*; + import org.junit.*; import com.oracle.graal.options.*; @@ -99,4 +101,27 @@ // expected } } + + @Test + public void toStringTest() { + assertEquals("com.oracle.graal.options.test.TestOptionValue$Options.Mutable=original", Mutable.toString()); + try (OverrideScope s1 = OptionValue.override(Mutable, "override1")) { + assertEquals("com.oracle.graal.options.test.TestOptionValue$Options.Mutable=override1", Mutable.toString()); + try (OverrideScope s2 = OptionValue.override(Mutable, "override2")) { + assertEquals("com.oracle.graal.options.test.TestOptionValue$Options.Mutable=override2", Mutable.toString()); + } + } + } + + @Test + public void getValuesTest() { + assertEquals(Arrays.asList("original"), Mutable.getValues(null)); + assertEquals(Arrays.asList(true), Stable.getValues(null)); + try (OverrideScope s1 = OptionValue.override(Mutable, "override1")) { + assertEquals(Arrays.asList("override1", "original"), Mutable.getValues(null)); + try (OverrideScope s2 = OptionValue.override(Mutable, "override2")) { + assertEquals(Arrays.asList("override2", "override1", "original"), Mutable.getValues(null)); + } + } + } }
--- a/graal/com.oracle.graal.options/src/com/oracle/graal/options/OptionValue.java Fri Nov 08 18:34:57 2013 +0100 +++ b/graal/com.oracle.graal.options/src/com/oracle/graal/options/OptionValue.java Sat Nov 09 12:04:24 2013 +0100 @@ -194,7 +194,7 @@ @Override public String toString() { - return getName() + "=" + value; + return getName() + "=" + getValue(); } /** @@ -220,6 +220,26 @@ } /** + * Gets the values of this option including overridden values. + * + * @param c the collection to which the values are added. If null, one is allocated. + * @return the collection to which the values were added in order from most overridden to + * current value + */ + @SuppressWarnings("unchecked") + public Collection<T> getValues(Collection<T> c) { + Collection<T> values = c == null ? new ArrayList<T>() : c; + if (!(this instanceof StableOptionValue)) { + OverrideScope overrideScope = overrideScopes.get(); + if (overrideScope != null) { + overrideScope.getOverrides(this, (Collection<Object>) values); + } + } + values.add(value); + return values; + } + + /** * Sets the value of this option. */ @SuppressWarnings("unchecked") @@ -236,6 +256,8 @@ abstract <T> T getOverride(OptionValue<T> option); + abstract void getOverrides(OptionValue<?> option, Collection<Object> c); + public abstract void close(); } @@ -268,6 +290,13 @@ } @Override + void getOverrides(OptionValue<?> key, Collection<Object> c) { + if (key == this.option) { + c.add(value); + } + } + + @Override public void close() { overrideScopes.set(null); } @@ -333,6 +362,17 @@ } @Override + void getOverrides(OptionValue<?> option, Collection<Object> c) { + Object v = overrides.get(option); + if (v != null) { + c.add(v); + } + if (parent != null) { + parent.getOverrides(option, c); + } + } + + @Override public void close() { if (!overrides.isEmpty()) { overrideScopes.set(parent);