# HG changeset patch # User Doug Simon # Date 1383995064 -3600 # Node ID bb85b81258a0ad8f10425b95efcfab0bad415580 # Parent 2caa21ef52bbfbb8221559982e322bfcf76ad080 modified OptionValue.toString() to use the current, possibly overriding value; added OptionValue.getValues() diff -r 2caa21ef52bb -r bb85b81258a0 graal/com.oracle.graal.options.test/src/com/oracle/graal/options/test/TestOptionValue.java --- 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)); + } + } + } } diff -r 2caa21ef52bb -r bb85b81258a0 graal/com.oracle.graal.options/src/com/oracle/graal/options/OptionValue.java --- 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 getValues(Collection c) { + Collection values = c == null ? new ArrayList() : c; + if (!(this instanceof StableOptionValue)) { + OverrideScope overrideScope = overrideScopes.get(); + if (overrideScope != null) { + overrideScope.getOverrides(this, (Collection) values); + } + } + values.add(value); + return values; + } + + /** * Sets the value of this option. */ @SuppressWarnings("unchecked") @@ -236,6 +256,8 @@ abstract T getOverride(OptionValue option); + abstract void getOverrides(OptionValue option, Collection c); + public abstract void close(); } @@ -268,6 +290,13 @@ } @Override + void getOverrides(OptionValue key, Collection 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 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);