jjg@345: /* ohair@554: * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. jjg@345: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jjg@345: * jjg@345: * This code is free software; you can redistribute it and/or modify it jjg@345: * under the terms of the GNU General Public License version 2 only, as jjg@345: * published by the Free Software Foundation. jjg@345: * jjg@345: * This code is distributed in the hope that it will be useful, but WITHOUT jjg@345: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jjg@345: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jjg@345: * version 2 for more details (a copy is included in the LICENSE file that jjg@345: * accompanied this code). jjg@345: * jjg@345: * You should have received a copy of the GNU General Public License version jjg@345: * 2 along with this work; if not, write to the Free Software Foundation, jjg@345: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jjg@345: * ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@554: * or visit www.oracle.com if you need additional information or have any ohair@554: * questions. jjg@345: */ jjg@345: jjg@345: jjg@345: /* jjg@345: * @test jjg@345: * @bug 6866657 jjg@345: * @summary add byteLength() method to primary classfile types jjg@345: */ jjg@345: jjg@345: import java.io.*; jjg@345: import java.util.*; jjg@345: import javax.tools.*; jjg@345: import com.sun.tools.javap.*; jjg@345: jjg@345: public class T6866657 jjg@345: { jjg@345: public static void main(String... args) { jjg@345: new T6866657().run(); jjg@345: } jjg@345: jjg@345: void run() { jjg@345: verify("java.lang.Object"); jjg@345: verify("java.lang.String"); jjg@345: verify("java.util.List"); jjg@345: verify("java.util.ArrayList"); jjg@345: if (errors > 0) jjg@345: throw new Error(errors + " found."); jjg@345: } jjg@345: jjg@345: void verify(String className) { jjg@345: try { jjg@345: PrintWriter log = new PrintWriter(System.out); jjg@345: JavaFileManager fileManager = JavapFileManager.create(null, log); jjg@345: JavaFileObject fo = fileManager.getJavaFileForInput(StandardLocation.PLATFORM_CLASS_PATH, className, JavaFileObject.Kind.CLASS); jjg@345: if (fo == null) { jjg@345: error("Can't find " + className); jjg@345: } else { jjg@345: JavapTask t = new JavapTask(log, fileManager, null); jjg@345: t.handleOptions(new String[] { "-sysinfo", className }); jjg@345: JavapTask.ClassFileInfo cfInfo = t.read(fo); jjg@345: expectEqual(cfInfo.cf.byteLength(), cfInfo.size); jjg@345: } jjg@345: } catch (Exception e) { jjg@345: e.printStackTrace(); jjg@345: error("Exception: " + e); jjg@345: } jjg@345: } jjg@345: jjg@345: void expectEqual(int found, int expected) { jjg@345: if (found != expected) jjg@345: error("bad value found: " + found + " expected: " + expected); jjg@345: } jjg@345: jjg@345: void error(String msg) { jjg@345: System.err.println(msg); jjg@345: errors++; jjg@345: } jjg@345: jjg@345: int errors; jjg@345: } jjg@345: