langtools/test/tools/javap/T6866657.java
author ohair
Tue, 25 May 2010 15:54:51 -0700
changeset 5520 86e4b9a9da40
parent 3543 58b72b096bcb
child 30730 d3ce7619db2c
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy
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
/*
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3543
diff changeset
     2
 * Copyright (c) 2009, 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
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    29
 */
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
import java.io.*;
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    32
import java.util.*;
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    33
import javax.tools.*;
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    34
import com.sun.tools.javap.*;
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    35
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    36
public class T6866657
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    37
{
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    38
    public static void main(String... args) {
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    39
        new T6866657().run();
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    40
    }
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
    void run() {
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    43
        verify("java.lang.Object");
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    44
        verify("java.lang.String");
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    45
        verify("java.util.List");
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    46
        verify("java.util.ArrayList");
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    47
        if (errors > 0)
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    48
            throw new Error(errors + " found.");
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    49
    }
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
    void verify(String className) {
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    52
        try {
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    53
            PrintWriter log = new PrintWriter(System.out);
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    54
            JavaFileManager fileManager = JavapFileManager.create(null, log);
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    55
            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
    56
            if (fo == null) {
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    57
                error("Can't find " + className);
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    58
            } else {
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    59
                JavapTask t = new JavapTask(log, fileManager, null);
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    60
                t.handleOptions(new String[] { "-sysinfo", className });
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    61
                JavapTask.ClassFileInfo cfInfo = t.read(fo);
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    62
                expectEqual(cfInfo.cf.byteLength(), cfInfo.size);
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    63
            }
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    64
        } catch (Exception e) {
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    65
            e.printStackTrace();
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    66
            error("Exception: " + e);
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    67
        }
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
    void expectEqual(int found, int expected) {
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    71
        if (found != expected)
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    72
            error("bad value found: " + found + " expected: " + expected);
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    73
    }
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
    void error(String msg) {
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    76
        System.err.println(msg);
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    77
        errors++;
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    78
    }
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
    int errors;
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    81
}
58b72b096bcb 6866657: add byteLength method to primary classfile types
jjg
parents:
diff changeset
    82