diff --git a/src/share/classes/com/sun/tools/javac/code/Scope.java b/src/share/classes/com/sun/tools/javac/code/Scope.java index 066715f582bce6512eaa37a3eaae524a809cd077..db96649e99ae200774d46231aa26bb99b7fbd6e9 100644 --- a/src/share/classes/com/sun/tools/javac/code/Scope.java +++ b/src/share/classes/com/sun/tools/javac/code/Scope.java @@ -649,7 +649,7 @@ public class Scope { public Iterator iterator() { return new CompoundScopeIterator(subScopes) { Iterator nextIterator(Scope s) { - return s.getElements().iterator(); + return s.getElements(sf).iterator(); } }; } diff --git a/test/tools/javac/scope/7017664/CompoundScopeTest.java b/test/tools/javac/scope/7017664/CompoundScopeTest.java index a6e1065670e6b2f64609fa66e02263c2c2161bdb..eda1836ef30989137c2f33c631b4df8b9968f45d 100644 --- a/test/tools/javac/scope/7017664/CompoundScopeTest.java +++ b/test/tools/javac/scope/7017664/CompoundScopeTest.java @@ -23,7 +23,7 @@ /* * @test - * @bug 7017664 + * @bug 7017664 7036906 * @summary Basher for CompoundScopes */ @@ -127,8 +127,17 @@ public class CompoundScopeTest { } } log("testing scope: " + root); - checkElems(root); - checkShadowed(root); + checkElems(root, null); + checkElems(root, new OddFilter()); + checkShadowed(root, null); + checkShadowed(root, new OddFilter()); + } + } + + class OddFilter implements Filter { + public boolean accepts(Symbol s) { + Name numPart = s.name.subName(1, s.name.length()); + return Integer.parseInt(numPart.toString()) % 2 != 0; } } @@ -165,15 +174,20 @@ public class CompoundScopeTest { * Check that CompoundScope.getElements() correctly visits all symbols * in all subscopes (in the correct order) */ - void checkElems(CompoundScope cs) { - List allSymbols = elems; + void checkElems(CompoundScope cs, Filter sf) { int count = 0; - for (Symbol s : cs.getElements()) { + ListBuffer found = ListBuffer.lb(); + List allSymbols = sf == null ? + elems : + filter(elems, sf); + int expectedCount = allSymbols.length(); + for (Symbol s : sf == null ? cs.getElements() : cs.getElements(sf)) { checkSameSymbols(s, allSymbols.head); allSymbols = allSymbols.tail; + found.append(s); count++; } - if (count != elems.size()) { + if (count != expectedCount) { error("CompoundScope.getElements() did not returned enough symbols"); } } @@ -182,22 +196,35 @@ public class CompoundScopeTest { * Check that CompoundScope.getElements() correctly visits all symbols * with a given name in all subscopes (in the correct order) */ - void checkShadowed(CompoundScope cs) { + void checkShadowed(CompoundScope cs, Filter sf) { for (Map.Entry> shadowedEntry : shadowedMap.entrySet()) { int count = 0; - List shadowed = shadowedEntry.getValue(); + List shadowed = sf == null ? + shadowedEntry.getValue() : + filter(shadowedEntry.getValue(), sf); + int expectedCount = shadowed.length(); Name name = shadowedEntry.getKey(); - for (Symbol s : cs.getElementsByName(name)) { + for (Symbol s : sf == null ? cs.getElementsByName(name) : cs.getElementsByName(name, sf)) { checkSameSymbols(s, shadowed.head); shadowed = shadowed.tail; count++; } - if (count != shadowedEntry.getValue().size()) { + if (count != expectedCount) { error("CompoundScope.lookup() did not returned enough symbols for name " + name); } } } + List filter(List elems, Filter sf) { + ListBuffer res = ListBuffer.lb(); + for (Symbol s : elems) { + if (sf.accepts(s)) { + res.append(s); + } + } + return res.toList(); + } + void checkSameSymbols(Symbol found, Symbol req) { if (found != req) { error("Symbol mismatch - found : " + found + ":" + found.hashCode() + "\n" +