jdk/test/java/lang/Class/getSimpleName/GetSimpleNameTest.java
author vlivanov
Tue, 14 Apr 2015 18:03:12 +0300
changeset 30341 a026e34714ed
child 30820 0d4717a011d3
permissions -rw-r--r--
8057919: Class.getSimpleName() should work for non-JLS compliant class names Reviewed-by: dholmes, jrose
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
30341
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
     1
/*
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
     4
 *
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
     8
 *
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    13
 * accompanied this code).
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    14
 *
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    18
 *
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    21
 * questions.
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    22
 */
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    23
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    24
/* @test
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    25
 * @bug 8057919
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    26
 * @summary Class.getSimpleName() should work for non-JLS compliant class names
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    27
 */
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    28
import jdk.internal.org.objectweb.asm.*;
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    29
import static jdk.internal.org.objectweb.asm.Opcodes.*;
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    30
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    31
public class GetSimpleNameTest {
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    32
    static class NestedClass {}
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    33
    class InnerClass {}
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    34
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    35
    static Class<?> f1() {
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    36
        class LocalClass {}
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    37
        return LocalClass.class;
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    38
    }
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    39
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    40
    public static void main(String[] args) throws Exception {
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    41
        assertEquals(NestedClass.class.getSimpleName(), "NestedClass");
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    42
        assertEquals( InnerClass.class.getSimpleName(),  "InnerClass");
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    43
        assertEquals(             f1().getSimpleName(),  "LocalClass");
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    44
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    45
        java.io.Serializable anon = new java.io.Serializable() {};
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    46
        assertEquals(anon.getClass().getSimpleName(), "");
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    47
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    48
        // Java class names, prepended enclosing class name.
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    49
        testNested("p.Outer$Nested", "p.Outer", "Nested");
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    50
        testInner( "p.Outer$Inner",  "p.Inner",  "Inner");
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    51
        testLocal( "p.Outer$1Local", "p.Outer",  "Local");
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    52
        testAnon(  "p.Outer$1",      "p.Outer",       "");
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    53
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    54
        // Non-Java class names, prepended enclosing class name.
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    55
        testNested("p.$C1$Nested", "p.$C1$", "Nested");
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    56
        testInner( "p.$C1$Inner",  "p.$C1$",  "Inner");
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    57
        testLocal( "p.$C1$Local",  "p.$C1$",  "Local");
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    58
        testAnon(  "p.$C1$1",      "p.$C1$",       "");
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    59
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    60
        // Non-Java class names, unrelated class names.
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    61
        testNested("p1.$Nested$", "p2.$C1$", "Nested");
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    62
        testInner( "p1.$Inner$",  "p2.$C1$",  "Inner");
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    63
        testLocal( "p1.$Local$",  "p2.$C1$",  "Local");
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    64
        testAnon(  "p1.$anon$",   "p2.$C1$",       "");
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    65
    }
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    66
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    67
    static void testNested(String innerName, String outerName, String simpleName) throws Exception {
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    68
        BytecodeGenerator bg = new BytecodeGenerator(innerName, outerName, simpleName);
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    69
        CustomCL cl = new CustomCL(innerName, outerName, bg.getNestedClasses(true), bg.getNestedClasses(false));
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    70
        assertEquals(cl.loadClass(innerName).getSimpleName(), simpleName);
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    71
    }
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    72
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    73
    static void testInner(String innerName, String outerName, String simpleName) throws Exception {
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    74
        BytecodeGenerator bg = new BytecodeGenerator(innerName, outerName, simpleName);
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    75
        CustomCL cl = new CustomCL(innerName, outerName, bg.getInnerClasses(true), bg.getInnerClasses(false));
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    76
        assertEquals(cl.loadClass(innerName).getSimpleName(), simpleName);
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    77
    }
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    78
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    79
    static void testLocal(String innerName, String outerName, String simpleName) throws Exception {
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    80
        BytecodeGenerator bg = new BytecodeGenerator(innerName, outerName, simpleName);
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    81
        CustomCL cl = new CustomCL(innerName, outerName, bg.getLocalClasses(true), bg.getLocalClasses(false));
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    82
        assertEquals(cl.loadClass(innerName).getSimpleName(), simpleName);
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    83
    }
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    84
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    85
    static void testAnon(String innerName, String outerName, String simpleName) throws Exception {
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    86
        BytecodeGenerator bg = new BytecodeGenerator(innerName, outerName, simpleName);
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    87
        CustomCL cl = new CustomCL(innerName, outerName, bg.getAnonymousClasses(true), bg.getAnonymousClasses(false));
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    88
        assertEquals(cl.loadClass(innerName).getSimpleName(), simpleName);
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    89
    }
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    90
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    91
    static void assertEquals(Object o1, Object o2) {
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    92
        if (!java.util.Objects.equals(o1, o2)) {
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    93
            throw new AssertionError(o1 + " != " + o2);
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    94
        }
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    95
    }
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    96
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    97
    static class CustomCL extends ClassLoader {
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    98
        final String  innerName;
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
    99
        final String  outerName;
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   100
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   101
        final byte[] innerClassFile;
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   102
        final byte[] outerClassFile;
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   103
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   104
        CustomCL(String innerName, String outerName, byte[] innerClassFile, byte[] outerClassFile) {
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   105
            this.innerName = innerName;
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   106
            this.outerName = outerName;
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   107
            this.innerClassFile = innerClassFile;
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   108
            this.outerClassFile = outerClassFile;
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   109
        }
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   110
        @Override
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   111
        protected Class<?> findClass(String name) throws ClassNotFoundException {
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   112
            if (innerName.equals(name)) {
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   113
                return defineClass(innerName, innerClassFile, 0, innerClassFile.length);
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   114
            } else if (outerName.equals(name)) {
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   115
                return defineClass(outerName, outerClassFile, 0, outerClassFile.length);
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   116
            } else {
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   117
                throw new ClassNotFoundException(name);
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   118
            }
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   119
        }
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   120
    }
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   121
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   122
    static class BytecodeGenerator {
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   123
        final String innerName;
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   124
        final String outerName;
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   125
        final String simpleName;
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   126
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   127
        BytecodeGenerator(String innerName, String outerName, String simpleName) {
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   128
            this.innerName = intl(innerName);
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   129
            this.outerName = intl(outerName);
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   130
            this.simpleName = simpleName;
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   131
        }
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   132
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   133
        static String intl(String name) { return name.replace('.', '/'); }
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   134
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   135
        static void makeDefaultCtor(ClassWriter cw) {
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   136
            MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   137
            mv.visitCode();
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   138
            mv.visitVarInsn(ALOAD, 0);
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   139
            mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   140
            mv.visitInsn(RETURN);
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   141
            mv.visitMaxs(1, 1);
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   142
            mv.visitEnd();
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   143
        }
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   144
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   145
        void makeCtxk(ClassWriter cw, boolean isInner) {
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   146
            if (isInner) {
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   147
                cw.visitOuterClass(outerName, "f", "()V");
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   148
            } else {
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   149
                MethodVisitor mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "f", "()V", null, null);
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   150
                mv.visitCode();
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   151
                mv.visitInsn(RETURN);
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   152
                mv.visitMaxs(0, 0);
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   153
                mv.visitEnd();
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   154
            }
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   155
        }
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   156
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   157
        byte[] getNestedClasses(boolean isInner) {
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   158
            String name = (isInner ? innerName : outerName);
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   159
            ClassWriter cw = new ClassWriter(0);
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   160
            cw.visit(V1_7, ACC_PUBLIC + ACC_SUPER, name, null, "java/lang/Object", null);
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   161
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   162
            cw.visitInnerClass(innerName, outerName, simpleName, ACC_PUBLIC | ACC_STATIC);
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   163
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   164
            makeDefaultCtor(cw);
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   165
            cw.visitEnd();
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   166
            return cw.toByteArray();
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   167
        }
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   168
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   169
        byte[] getInnerClasses(boolean isInner) {
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   170
            String name = (isInner ? innerName : outerName);
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   171
            ClassWriter cw = new ClassWriter(0);
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   172
            cw.visit(V1_7, ACC_PUBLIC + ACC_SUPER, name, null, "java/lang/Object", null);
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   173
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   174
            cw.visitInnerClass(innerName, outerName, simpleName, ACC_PUBLIC);
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   175
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   176
            makeDefaultCtor(cw);
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   177
            cw.visitEnd();
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   178
            return cw.toByteArray();
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   179
        }
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   180
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   181
        byte[] getLocalClasses(boolean isInner) {
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   182
            String name = (isInner ? innerName : outerName);
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   183
            ClassWriter cw = new ClassWriter(0);
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   184
            cw.visit(V1_7, ACC_PUBLIC + ACC_SUPER, name, null, "java/lang/Object", null);
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   185
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   186
            cw.visitInnerClass(innerName, null, simpleName, ACC_PUBLIC | ACC_STATIC);
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   187
            makeCtxk(cw, isInner);
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   188
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   189
            makeDefaultCtor(cw);
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   190
            cw.visitEnd();
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   191
            return cw.toByteArray();
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   192
        }
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   193
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   194
        byte[] getAnonymousClasses(boolean isInner) {
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   195
            String name = (isInner ? innerName : outerName);
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   196
            ClassWriter cw = new ClassWriter(0);
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   197
            cw.visit(V1_7, ACC_PUBLIC + ACC_SUPER, name, null, "java/lang/Object", null);
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   198
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   199
            cw.visitInnerClass(innerName, null, null, ACC_PUBLIC | ACC_STATIC);
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   200
            makeCtxk(cw, isInner);
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   201
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   202
            makeDefaultCtor(cw);
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   203
            cw.visitEnd();
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   204
            return cw.toByteArray();
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   205
        }
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   206
    }
a026e34714ed 8057919: Class.getSimpleName() should work for non-JLS compliant class names
vlivanov
parents:
diff changeset
   207
}