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