Sat, 22 Dec 2018 13:10:38 -0800
Added tag jdk8u202-b25 for changeset 15d8c732039b
sadayapalam@2812 | 1 | /* |
sadayapalam@2812 | 2 | * Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. |
sadayapalam@2812 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
sadayapalam@2812 | 4 | * |
sadayapalam@2812 | 5 | * This code is free software; you can redistribute it and/or modify it |
sadayapalam@2812 | 6 | * under the terms of the GNU General Public License version 2 only, as |
sadayapalam@2812 | 7 | * published by the Free Software Foundation. |
sadayapalam@2812 | 8 | * |
sadayapalam@2812 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
sadayapalam@2812 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
sadayapalam@2812 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
sadayapalam@2812 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
sadayapalam@2812 | 13 | * accompanied this code). |
sadayapalam@2812 | 14 | * |
sadayapalam@2812 | 15 | * You should have received a copy of the GNU General Public License version |
sadayapalam@2812 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
sadayapalam@2812 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
sadayapalam@2812 | 18 | * |
sadayapalam@2812 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
sadayapalam@2812 | 20 | * or visit www.oracle.com if you need additional information or have any |
sadayapalam@2812 | 21 | * questions. |
sadayapalam@2812 | 22 | */ |
sadayapalam@2812 | 23 | |
sadayapalam@2812 | 24 | /* |
sadayapalam@2812 | 25 | * @test |
sadayapalam@2812 | 26 | * @bug 8080842 |
sadayapalam@2812 | 27 | * @summary Ensure Scope impl can cope with remove() when a field and method share the name. |
sadayapalam@2812 | 28 | */ |
sadayapalam@2812 | 29 | |
sadayapalam@2812 | 30 | import com.sun.tools.javac.util.*; |
sadayapalam@2812 | 31 | import com.sun.tools.javac.code.*; |
sadayapalam@2812 | 32 | import com.sun.tools.javac.code.Scope.*; |
sadayapalam@2812 | 33 | import com.sun.tools.javac.code.Symbol.*; |
sadayapalam@2812 | 34 | import com.sun.tools.javac.file.JavacFileManager; |
sadayapalam@2812 | 35 | |
sadayapalam@2812 | 36 | public class RemoveSymbolUnitTest { |
sadayapalam@2812 | 37 | |
sadayapalam@2812 | 38 | Context context; |
sadayapalam@2812 | 39 | Names names; |
sadayapalam@2812 | 40 | Symtab symtab; |
sadayapalam@2812 | 41 | |
sadayapalam@2812 | 42 | public static void main(String... args) throws Exception { |
sadayapalam@2812 | 43 | new RemoveSymbolUnitTest().run(); |
sadayapalam@2812 | 44 | } |
sadayapalam@2812 | 45 | |
sadayapalam@2812 | 46 | public void run() { |
sadayapalam@2812 | 47 | context = new Context(); |
sadayapalam@2812 | 48 | JavacFileManager.preRegister(context); // required by ClassReader which is required by Symtab |
sadayapalam@2812 | 49 | names = Names.instance(context); |
sadayapalam@2812 | 50 | symtab = Symtab.instance(context); |
sadayapalam@2812 | 51 | |
sadayapalam@2812 | 52 | Name hasNext = names.fromString("hasNext"); |
sadayapalam@2812 | 53 | ClassSymbol clazz = new ClassSymbol(0, |
sadayapalam@2812 | 54 | names.fromString("X"), |
sadayapalam@2812 | 55 | Type.noType, |
sadayapalam@2812 | 56 | symtab.unnamedPackage); |
sadayapalam@2812 | 57 | |
sadayapalam@2812 | 58 | VarSymbol v = new VarSymbol(0, hasNext, Type.noType, clazz); |
sadayapalam@2812 | 59 | MethodSymbol m = new MethodSymbol(0, hasNext, Type.noType, clazz); |
sadayapalam@2812 | 60 | |
sadayapalam@2812 | 61 | // Try enter and remove in different shuffled combinations. |
sadayapalam@2812 | 62 | // working with fresh scope each time. |
sadayapalam@2812 | 63 | Scope cs = new Scope(clazz); |
sadayapalam@2812 | 64 | cs.enter(v); |
sadayapalam@2812 | 65 | cs.enter(m); |
sadayapalam@2812 | 66 | cs.remove(v); |
sadayapalam@2812 | 67 | Symbol s = cs.lookup(hasNext).sym; |
sadayapalam@2812 | 68 | if (s != m) |
sadayapalam@2812 | 69 | throw new AssertionError("Wrong symbol"); |
sadayapalam@2812 | 70 | |
sadayapalam@2812 | 71 | cs = new Scope(clazz); |
sadayapalam@2812 | 72 | cs.enter(m); |
sadayapalam@2812 | 73 | cs.enter(v); |
sadayapalam@2812 | 74 | cs.remove(v); |
sadayapalam@2812 | 75 | s = cs.lookup(hasNext).sym; |
sadayapalam@2812 | 76 | if (s != m) |
sadayapalam@2812 | 77 | throw new AssertionError("Wrong symbol"); |
sadayapalam@2812 | 78 | |
sadayapalam@2812 | 79 | cs = new Scope(clazz); |
sadayapalam@2812 | 80 | cs.enter(v); |
sadayapalam@2812 | 81 | cs.enter(m); |
sadayapalam@2812 | 82 | cs.remove(m); |
sadayapalam@2812 | 83 | s = cs.lookup(hasNext).sym; |
sadayapalam@2812 | 84 | if (s != v) |
sadayapalam@2812 | 85 | throw new AssertionError("Wrong symbol"); |
sadayapalam@2812 | 86 | |
sadayapalam@2812 | 87 | cs = new Scope(clazz); |
sadayapalam@2812 | 88 | cs.enter(m); |
sadayapalam@2812 | 89 | cs.enter(v); |
sadayapalam@2812 | 90 | cs.remove(m); |
sadayapalam@2812 | 91 | s = cs.lookup(hasNext).sym; |
sadayapalam@2812 | 92 | if (s != v) |
sadayapalam@2812 | 93 | throw new AssertionError("Wrong symbol"); |
sadayapalam@2812 | 94 | } |
sadayapalam@2812 | 95 | } |