langtools/test/tools/javap/T6866657.java
author akulyakh
Thu, 21 May 2015 11:41:04 -0700
changeset 30730 d3ce7619db2c
parent 5520 86e4b9a9da40
child 30846 2b3f379840f0
permissions -rw-r--r--
8076543: Add @modules as needed to the langtools tests Reviewed-by: jjg, shurailine
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3543
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
     1
/*
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 5520
diff changeset
     2
 * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
3543
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
     4
 *
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
     8
 *
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    13
 * accompanied this code).
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    14
 *
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    18
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3543
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3543
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3543
diff changeset
    21
 * questions.
3543
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    22
 */
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    23
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    24
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    25
/*
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    26
 * @test
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    27
 * @bug 6866657
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    28
 * @summary add byteLength() method to primary classfile types
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 5520
diff changeset
    29
 * @modules jdk.compiler/com.sun.tools.classfile
3543
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    30
 */
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    31
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    32
import java.io.*;
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    33
import java.util.*;
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    34
import javax.tools.*;
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    35
import com.sun.tools.javap.*;
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    36
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    37
public class T6866657
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    38
{
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    39
    public static void main(String... args) {
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    40
        new T6866657().run();
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    41
    }
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    42
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    43
    void run() {
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    44
        verify("java.lang.Object");
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    45
        verify("java.lang.String");
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    46
        verify("java.util.List");
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    47
        verify("java.util.ArrayList");
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    48
        if (errors > 0)
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    49
            throw new Error(errors + " found.");
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    50
    }
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    51
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    52
    void verify(String className) {
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    53
        try {
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    54
            PrintWriter log = new PrintWriter(System.out);
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    55
            JavaFileManager fileManager = JavapFileManager.create(null, log);
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    56
            JavaFileObject fo = fileManager.getJavaFileForInput(StandardLocation.PLATFORM_CLASS_PATH, className, JavaFileObject.Kind.CLASS);
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    57
            if (fo == null) {
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    58
                error("Can't find " + className);
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    59
            } else {
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    60
                JavapTask t = new JavapTask(log, fileManager, null);
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    61
                t.handleOptions(new String[] { "-sysinfo", className });
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    62
                JavapTask.ClassFileInfo cfInfo = t.read(fo);
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    63
                expectEqual(cfInfo.cf.byteLength(), cfInfo.size);
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    64
            }
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    65
        } catch (Exception e) {
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    66
            e.printStackTrace();
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    67
            error("Exception: " + e);
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    68
        }
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    69
    }
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    70
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    71
    void expectEqual(int found, int expected) {
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    72
        if (found != expected)
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    73
            error("bad value found: " + found + " expected: " + expected);
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    74
    }
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    75
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    76
    void error(String msg) {
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    77
        System.err.println(msg);
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    78
        errors++;
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    79
    }
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    80
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    81
    int errors;
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    82
}
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    83