2 * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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.
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
28 package sun.tools.javap;
34 * Entry point for javap, class file disassembler.
36 * @author Sucheta Dambalkar (Adopted code from old javap)
40 private Vector classList = new Vector();
41 private PrintWriter out;
42 JavapEnvironment env = new JavapEnvironment();
43 private static boolean errorOccurred = false;
44 private static final String progname = "javap";
47 public Main(PrintWriter out){
51 public static void main(String argv[]) {
60 * Entry point for tool if you don't want System.exit() called.
62 public static void entry(String argv[]) {
63 PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
66 Main jpmain = new Main(out);
75 * Process the arguments and perform the desired action
77 private void perform(String argv[]) {
78 if (parseArguments(argv)) {
84 private void error(String msg) {
86 System.err.println(msg);
91 * Print usage information
93 private void usage() {
94 java.io.PrintStream out = System.out;
95 out.println("Usage: " + progname + " <options> <classes>...");
97 out.println("where options include:");
98 out.println(" -c Disassemble the code");
99 out.println(" -classpath <pathlist> Specify where to find user class files");
100 out.println(" -extdirs <dirs> Override location of installed extensions");
101 out.println(" -help Print this usage message");
102 out.println(" -J<flag> Pass <flag> directly to the runtime system");
103 out.println(" -l Print line number and local variable tables");
104 out.println(" -public Show only public classes and members");
105 out.println(" -protected Show protected/public classes and members");
106 out.println(" -package Show package/protected/public classes");
107 out.println(" and members (default)");
108 out.println(" -private Show all classes and members");
109 out.println(" -s Print internal type signatures");
110 out.println(" -bootclasspath <pathlist> Override location of class files loaded");
111 out.println(" by the bootstrap class loader");
112 out.println(" -verbose Print stack size, number of locals and args for methods");
113 out.println(" If verifying, print reasons for failure");
118 * Parse the command line arguments.
119 * Set flags, construct the class list and create environment.
121 private boolean parseArguments(String argv[]) {
122 for (int i = 0 ; i < argv.length ; i++) {
123 String arg = argv[i];
124 if (arg.startsWith("-")) {
125 if (arg.equals("-l")) {
126 env.showLineAndLocal = true;
127 } else if (arg.equals("-private") || arg.equals("-p")) {
128 env.showAccess = env.PRIVATE;
129 } else if (arg.equals("-package")) {
130 env.showAccess = env.PACKAGE;
131 } else if (arg.equals("-protected")) {
132 env.showAccess = env.PROTECTED;
133 } else if (arg.equals("-public")) {
134 env.showAccess = env.PUBLIC;
135 } else if (arg.equals("-c")) {
136 env.showDisassembled = true;
137 } else if (arg.equals("-s")) {
138 env.showInternalSigs = true;
139 } else if (arg.equals("-verbose")) {
140 env.showVerbose = true;
141 } else if (arg.equals("-v")) {
142 env.showVerbose = true;
143 } else if (arg.equals("-h")) {
144 error("-h is no longer available - use the 'javah' program");
146 } else if (arg.equals("-verify")) {
147 error("-verify is no longer available - use 'java -verify'");
149 } else if (arg.equals("-verify-verbose")) {
150 error("-verify is no longer available - use 'java -verify'");
152 } else if (arg.equals("-help")) {
155 } else if (arg.equals("-classpath")) {
156 if ((i + 1) < argv.length) {
157 env.classPathString = argv[++i];
159 error("-classpath requires argument");
163 } else if (arg.equals("-bootclasspath")) {
164 if ((i + 1) < argv.length) {
165 env.bootClassPathString = argv[++i];
167 error("-bootclasspath requires argument");
171 } else if (arg.equals("-extdirs")) {
172 if ((i + 1) < argv.length) {
173 env.extDirsString = argv[++i];
175 error("-extdirs requires argument");
179 } else if (arg.equals("-all")) {
180 env.showallAttr = true;
182 error("invalid flag: " + arg);
187 classList.addElement(arg);
188 env.nothingToDo = false;
191 if (env.nothingToDo) {
192 System.out.println("No classes were specified on the command line. Try -help.");
193 errorOccurred = true;
202 private void displayResults() {
203 for (int i = 0; i < classList.size() ; i++ ) {
204 String Name = (String)classList.elementAt(i);
205 InputStream classin = env.getFileInputStream(Name);
208 JavapPrinter printer = new JavapPrinter(classin, out, env);
209 printer.print(); // actual do display
211 } catch (IllegalArgumentException exc) {
212 error(exc.getMessage());