test/tools/javac/7153958/CPoolRefClassContainingInlinedCts.java

Mon, 21 Jan 2013 20:13:56 +0000

author
mcimadamore
date
Mon, 21 Jan 2013 20:13:56 +0000
changeset 1510
7873d37f5b37
parent 1451
37a5d7eccb87
child 2525
2eb010b6cb22
child 2810
1b59f823d630
permissions
-rw-r--r--

8005244: Implement overload resolution as per latest spec EDR
Summary: Add support for stuck expressions and provisional applicability
Reviewed-by: jjg

     1 /*
     2  * Copyright (c) 2012, 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.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    26 /*
    27  * @test
    28  * @bug 7153958
    29  * @summary add constant pool reference to class containing inlined constants
    30  * @compile pkg/ClassToBeStaticallyImported.java CPoolRefClassContainingInlinedCts.java
    31  * @run main CPoolRefClassContainingInlinedCts
    32  */
    34 import com.sun.tools.classfile.ClassFile;
    35 import com.sun.tools.classfile.ConstantPool.CONSTANT_Class_info;
    36 import com.sun.tools.classfile.ConstantPool.CPInfo;
    37 import com.sun.tools.classfile.ConstantPoolException;
    38 import java.io.File;
    39 import java.io.IOException;
    41 import static pkg.ClassToBeStaticallyImported.staticField;
    43 public class CPoolRefClassContainingInlinedCts {
    45     public static void main(String args[]) throws Exception {
    46         new CPoolRefClassContainingInlinedCts().run();
    47     }
    49     void run() throws Exception {
    50         checkReferences();
    51     }
    53     int numberOfReferencedClassesToBeChecked = 0;
    55     void checkClassName(String className) {
    56         switch (className) {
    57             case "SimpleAssignClass" : case "BinaryExpClass":
    58             case "UnaryExpClass" : case "CastClass":
    59             case "ParensClass" : case "CondClass":
    60             case "IfClass" : case "pkg/ClassToBeStaticallyImported":
    61                 numberOfReferencedClassesToBeChecked++;
    62         }
    63     }
    65     void checkReferences() throws IOException, ConstantPoolException {
    66         File testClasses = new File(System.getProperty("test.classes"));
    67         File file = new File(testClasses,
    68                 CPoolRefClassContainingInlinedCts.class.getName() + ".class");
    69         ClassFile classFile = ClassFile.read(file);
    70         int i = 1;
    71         CPInfo cpInfo;
    72         while (i < classFile.constant_pool.size()) {
    73             cpInfo = classFile.constant_pool.get(i);
    74             if (cpInfo instanceof CONSTANT_Class_info) {
    75                 checkClassName(((CONSTANT_Class_info)cpInfo).getName());
    76             }
    77             i += cpInfo.size();
    78         }
    79         if (numberOfReferencedClassesToBeChecked != 8) {
    80             throw new AssertionError("Class reference missing in the constant pool");
    81         }
    82     }
    84     private int assign = SimpleAssignClass.x;
    85     private int binary = BinaryExpClass.x + 1;
    86     private int unary = -UnaryExpClass.x;
    87     private int cast = (int)CastClass.x;
    88     private int parens = (ParensClass.x);
    89     private int cond = (CondClass.x == 1) ? 1 : 2;
    90     private static int ifConstant;
    91     private static int importStatic;
    92     static {
    93         if (IfClass.x == 1) {
    94             ifConstant = 1;
    95         } else {
    96             ifConstant = 2;
    97         }
    98     }
    99     static {
   100         if (staticField == 1) {
   101             importStatic = 1;
   102         } else {
   103             importStatic = 2;
   104         }
   105     }
   106 }
   108 class SimpleAssignClass {
   109     public static final int x = 1;
   110 }
   112 class BinaryExpClass {
   113     public static final int x = 1;
   114 }
   116 class UnaryExpClass {
   117     public static final int x = 1;
   118 }
   120 class CastClass {
   121     public static final int x = 1;
   122 }
   124 class ParensClass {
   125     public static final int x = 1;
   126 }
   128 class CondClass {
   129     public static final int x = 1;
   130 }
   132 class IfClass {
   133     public static final int x = 1;
   134 }

mercurial