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