Tue, 03 Jun 2008 13:26:47 -0700
4075303: Use javap to enquire aboput a specific inner class
4348375: Javap is not internationalized
4459541: "javap -l" shows line numbers as signed short; they should be unsigned
4501660: change diagnostic of -help as 'print this help message and exit'
4776241: unused source file in javap...
4870651: javap should recognize generics, varargs, enum
4876942: javap invoked without args does not print help screen
4880663: javap could output whitespace between class name and opening brace
4975569: javap doesn't print new flag bits
6271787: javap dumps LocalVariableTypeTable attribute in hex, needs to print a table
6305779: javap: support annotations
6439940: Clean up javap implementation
6469569: wrong check of searchpath in JavapEnvironment
6474890: javap does not open .zip files in -classpath
6587786: Javap throws error : "ERROR:Could not find <classname>" for JRE classes
6622215: javap ignores certain relevant access flags
6622216: javap names some attributes incorrectly
6622232: javap gets whitespace confused
6622260: javap prints negative bytes incorrectly in hex
Reviewed-by: ksrini
jjg@10 | 1 | /* |
jjg@10 | 2 | * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. |
jjg@10 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jjg@10 | 4 | * |
jjg@10 | 5 | * This code is free software; you can redistribute it and/or modify it |
jjg@10 | 6 | * under the terms of the GNU General Public License version 2 only, as |
jjg@10 | 7 | * published by the Free Software Foundation. Sun designates this |
jjg@10 | 8 | * particular file as subject to the "Classpath" exception as provided |
jjg@10 | 9 | * by Sun in the LICENSE file that accompanied this code. |
jjg@10 | 10 | * |
jjg@10 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jjg@10 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jjg@10 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jjg@10 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
jjg@10 | 15 | * accompanied this code). |
jjg@10 | 16 | * |
jjg@10 | 17 | * You should have received a copy of the GNU General Public License version |
jjg@10 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
jjg@10 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jjg@10 | 20 | * |
jjg@10 | 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
jjg@10 | 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
jjg@10 | 23 | * have any questions. |
jjg@10 | 24 | */ |
jjg@10 | 25 | |
jjg@10 | 26 | /* |
jjg@10 | 27 | * @test |
jjg@10 | 28 | * @bug 6668802 |
jjg@10 | 29 | * @summary javac handles diagnostics for last line badly, if line not terminated by newline |
jjg@10 | 30 | */ |
jjg@10 | 31 | |
jjg@10 | 32 | import java.io.*; |
jjg@10 | 33 | import java.util.*; |
jjg@10 | 34 | |
jjg@10 | 35 | public class T6668802 |
jjg@10 | 36 | { |
jjg@10 | 37 | public static void main(String[] args) throws Exception { |
jjg@10 | 38 | new T6668802().run(); |
jjg@10 | 39 | } |
jjg@10 | 40 | |
jjg@10 | 41 | void run() throws Exception { |
jjg@10 | 42 | String test = "public class Test {"; |
jjg@10 | 43 | File f = writeTestFile("Test.java", test); |
jjg@10 | 44 | String[] out = compileBadFile(f); |
jjg@10 | 45 | for (String line: out) |
jjg@10 | 46 | System.err.println(">>>" + line + "<<<"); |
jjg@10 | 47 | if (!out[1].equals(test)) { |
jjg@10 | 48 | show("expected", test); |
jjg@10 | 49 | show(" actual", out[1]); |
jjg@10 | 50 | throw new Error("test failed"); |
jjg@10 | 51 | } |
jjg@10 | 52 | } |
jjg@10 | 53 | |
jjg@10 | 54 | File writeTestFile(String path, String contents) throws IOException { |
jjg@10 | 55 | File f = new File(path); |
jjg@10 | 56 | FileWriter out = new FileWriter(f); |
jjg@10 | 57 | out.write(contents); |
jjg@10 | 58 | out.close(); |
jjg@10 | 59 | return f; |
jjg@10 | 60 | } |
jjg@10 | 61 | |
jjg@10 | 62 | String[] compileBadFile(File file) throws IOException { |
jjg@10 | 63 | List<String> options = new ArrayList<String>(); |
jjg@10 | 64 | options.add(file.getPath()); |
jjg@10 | 65 | System.err.println("compile: " + options); |
jjg@10 | 66 | String[] opts = options.toArray(new String[options.size()]); |
jjg@10 | 67 | StringWriter sw = new StringWriter(); |
jjg@10 | 68 | PrintWriter out = new PrintWriter(sw); |
jjg@10 | 69 | int rc = com.sun.tools.javac.Main.compile(opts, out); |
jjg@10 | 70 | if (rc == 0) |
jjg@10 | 71 | throw new Error("compilation succeeded unexpectedly"); |
jjg@10 | 72 | out.close(); |
jjg@10 | 73 | return sw.toString().split("[\n\r]+"); |
jjg@10 | 74 | } |
jjg@10 | 75 | |
jjg@10 | 76 | void show(String prefix, String text) { |
jjg@10 | 77 | System.err.println(prefix + ": (" + text.length() + ") " + text); |
jjg@10 | 78 | } |
jjg@10 | 79 | } |