Sat, 07 Nov 2020 10:30:02 +0800
Added tag mips-jdk8u275-b01 for changeset eb6ee6a5f2fe
jlahoda@2813 | 1 | /* |
jlahoda@2813 | 2 | * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
jlahoda@2813 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jlahoda@2813 | 4 | * |
jlahoda@2813 | 5 | * This code is free software; you can redistribute it and/or modify it |
jlahoda@2813 | 6 | * under the terms of the GNU General Public License version 2 only, as |
jlahoda@2813 | 7 | * published by the Free Software Foundation. |
jlahoda@2813 | 8 | * |
jlahoda@2813 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jlahoda@2813 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jlahoda@2813 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jlahoda@2813 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
jlahoda@2813 | 13 | * accompanied this code). |
jlahoda@2813 | 14 | * |
jlahoda@2813 | 15 | * You should have received a copy of the GNU General Public License version |
jlahoda@2813 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
jlahoda@2813 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jlahoda@2813 | 18 | * |
jlahoda@2813 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
jlahoda@2813 | 20 | * or visit www.oracle.com if you need additional information or have any |
jlahoda@2813 | 21 | * questions. |
jlahoda@2813 | 22 | */ |
jlahoda@2813 | 23 | |
jlahoda@2813 | 24 | /* |
jlahoda@2813 | 25 | * @test |
jlahoda@2813 | 26 | * @bug 8039262 |
jlahoda@2813 | 27 | * @summary Ensure that using Types.membersClosure does not increase the number of listeners on the |
jlahoda@2813 | 28 | * class's members Scope. |
jlahoda@2813 | 29 | */ |
jlahoda@2813 | 30 | |
jlahoda@2813 | 31 | import com.sun.tools.javac.code.Scope; |
jlahoda@2813 | 32 | import com.sun.tools.javac.code.Symbol; |
jlahoda@2813 | 33 | import com.sun.tools.javac.code.Symtab; |
jlahoda@2813 | 34 | import com.sun.tools.javac.code.Types; |
jlahoda@2813 | 35 | import com.sun.tools.javac.file.JavacFileManager; |
jlahoda@2813 | 36 | import com.sun.tools.javac.util.Context; |
jlahoda@2813 | 37 | import com.sun.tools.javac.util.Names; |
jlahoda@2813 | 38 | import java.lang.reflect.Field; |
jlahoda@2813 | 39 | import java.util.Collection; |
jlahoda@2813 | 40 | |
jlahoda@2813 | 41 | public class ScopeListenerTest { |
jlahoda@2813 | 42 | |
jlahoda@2813 | 43 | public static void main(String[] args) throws Exception { |
jlahoda@2813 | 44 | new ScopeListenerTest().run(); |
jlahoda@2813 | 45 | } |
jlahoda@2813 | 46 | |
jlahoda@2813 | 47 | void run() throws Exception { |
jlahoda@2813 | 48 | Context context = new Context(); |
jlahoda@2813 | 49 | JavacFileManager.preRegister(context); |
jlahoda@2813 | 50 | Types types = Types.instance(context); |
jlahoda@2813 | 51 | Symtab syms = Symtab.instance(context); |
jlahoda@2813 | 52 | Names names = Names.instance(context); |
jlahoda@2813 | 53 | types.membersClosure(syms.stringType, true); |
jlahoda@2813 | 54 | types.membersClosure(syms.stringType, false); |
jlahoda@2813 | 55 | |
jlahoda@2813 | 56 | Field listenersField = Scope.class.getDeclaredField("listeners"); |
jlahoda@2813 | 57 | |
jlahoda@2813 | 58 | listenersField.setAccessible(true); |
jlahoda@2813 | 59 | |
jlahoda@2813 | 60 | int listenerCount = |
jlahoda@2813 | 61 | ((Collection) listenersField.get(syms.stringType.tsym.members())).size(); |
jlahoda@2813 | 62 | |
jlahoda@2813 | 63 | for (int i = 0; i < 100; i++) { |
jlahoda@2813 | 64 | types.membersClosure(syms.stringType, true); |
jlahoda@2813 | 65 | types.membersClosure(syms.stringType, false); |
jlahoda@2813 | 66 | } |
jlahoda@2813 | 67 | |
jlahoda@2813 | 68 | int newListenerCount |
jlahoda@2813 | 69 | = ((Collection) listenersField.get(syms.stringType.tsym.members())).size(); |
jlahoda@2813 | 70 | |
jlahoda@2813 | 71 | if (listenerCount != newListenerCount) { |
jlahoda@2813 | 72 | throw new AssertionError("Orig listener count: " + listenerCount + |
jlahoda@2813 | 73 | "; new listener count: " + newListenerCount); |
jlahoda@2813 | 74 | } |
jlahoda@2813 | 75 | |
jlahoda@2813 | 76 | for (Symbol s : types.membersClosure(syms.stringType, true).getElements()) |
jlahoda@2813 | 77 | ; |
jlahoda@2813 | 78 | for (Symbol s : types.membersClosure(syms.stringType, false).getElementsByName(names.fromString("substring"))) |
jlahoda@2813 | 79 | ; |
jlahoda@2813 | 80 | } |
jlahoda@2813 | 81 | |
jlahoda@2813 | 82 | } |