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
duke@1 | 1 | /* |
duke@1 | 2 | * Copyright 2002-2003 Sun Microsystems, Inc. All Rights Reserved. |
duke@1 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@1 | 4 | * |
duke@1 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@1 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@1 | 7 | * published by the Free Software Foundation. Sun designates this |
duke@1 | 8 | * particular file as subject to the "Classpath" exception as provided |
duke@1 | 9 | * by Sun in the LICENSE file that accompanied this code. |
duke@1 | 10 | * |
duke@1 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@1 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@1 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@1 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@1 | 15 | * accompanied this code). |
duke@1 | 16 | * |
duke@1 | 17 | * You should have received a copy of the GNU General Public License version |
duke@1 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@1 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@1 | 20 | * |
duke@1 | 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@1 | 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@1 | 23 | * have any questions. |
duke@1 | 24 | */ |
duke@1 | 25 | |
duke@1 | 26 | |
duke@1 | 27 | package com.sun.tools.javah; |
duke@1 | 28 | |
duke@1 | 29 | import com.sun.javadoc.*; |
duke@1 | 30 | import java.io.*; |
duke@1 | 31 | |
duke@1 | 32 | /** |
duke@1 | 33 | * A doclet to parse and execute commandline options. |
duke@1 | 34 | * |
duke@1 | 35 | * @author Sucheta Dambalkar(using code from old javap) |
duke@1 | 36 | */ |
duke@1 | 37 | public class MainDoclet{ |
duke@1 | 38 | |
duke@1 | 39 | public static String odir = null; |
duke@1 | 40 | public static String ofile = null; |
duke@1 | 41 | public static boolean stubs = false; |
duke@1 | 42 | public static boolean jni = false; |
duke@1 | 43 | public static boolean llni = false; |
duke@1 | 44 | public static boolean doubleAlign = false; |
duke@1 | 45 | public static boolean force = false; |
duke@1 | 46 | public static String genclass = null; |
duke@1 | 47 | |
duke@1 | 48 | |
duke@1 | 49 | /** |
duke@1 | 50 | * Entry point. |
duke@1 | 51 | */ |
duke@1 | 52 | public static boolean start(RootDoc root) { |
duke@1 | 53 | |
duke@1 | 54 | int j = 0; |
duke@1 | 55 | int k = 0; |
duke@1 | 56 | /** |
duke@1 | 57 | * Command line options. |
duke@1 | 58 | */ |
duke@1 | 59 | String [][] cmdoptions = root.options(); |
duke@1 | 60 | /** |
duke@1 | 61 | * Classes specified on command line. |
duke@1 | 62 | */ |
duke@1 | 63 | ClassDoc[] classes = root.classes(); |
duke@1 | 64 | /** |
duke@1 | 65 | * Generator used by javah. Default is JNI. |
duke@1 | 66 | */ |
duke@1 | 67 | Gen g = new JNI(root); |
duke@1 | 68 | |
duke@1 | 69 | validateOptions(cmdoptions); |
duke@1 | 70 | |
duke@1 | 71 | /* |
duke@1 | 72 | * Select native interface. |
duke@1 | 73 | */ |
duke@1 | 74 | if (jni && llni) Util.error("jni.llni.mixed"); |
duke@1 | 75 | |
duke@1 | 76 | if (llni) |
duke@1 | 77 | g = new LLNI(doubleAlign, root); |
duke@1 | 78 | |
duke@1 | 79 | if (g instanceof JNI && stubs) Util.error("jni.no.stubs"); |
duke@1 | 80 | |
duke@1 | 81 | /* |
duke@1 | 82 | * Arrange for output destination. |
duke@1 | 83 | */ |
duke@1 | 84 | if (odir != null && ofile != null) |
duke@1 | 85 | Util.error("dir.file.mixed"); |
duke@1 | 86 | |
duke@1 | 87 | if (odir != null) |
duke@1 | 88 | g.setOutDir(odir); |
duke@1 | 89 | |
duke@1 | 90 | if (ofile != null) |
duke@1 | 91 | g.setOutFile(ofile); |
duke@1 | 92 | |
duke@1 | 93 | /* |
duke@1 | 94 | * Force set to false will turn off smarts about checking file |
duke@1 | 95 | * content before writing. |
duke@1 | 96 | */ |
duke@1 | 97 | g.setForce(force); |
duke@1 | 98 | |
duke@1 | 99 | /* |
duke@1 | 100 | * Grab the rest of argv[] ... this must be the classes. |
duke@1 | 101 | */ |
duke@1 | 102 | if (classes.length == 0){ |
duke@1 | 103 | Util.error("no.classes.specified"); |
duke@1 | 104 | } |
duke@1 | 105 | /* |
duke@1 | 106 | * Set classes. |
duke@1 | 107 | */ |
duke@1 | 108 | g.setClasses(classes); |
duke@1 | 109 | |
duke@1 | 110 | try { |
duke@1 | 111 | g.run(); |
duke@1 | 112 | } catch (ClassNotFoundException cnfe) { |
duke@1 | 113 | Util.error("class.not.found", cnfe.getMessage()); |
duke@1 | 114 | } catch (IOException ioe) { |
duke@1 | 115 | Util.error("io.exception", ioe.getMessage()); |
duke@1 | 116 | } |
duke@1 | 117 | |
duke@1 | 118 | return true; |
duke@1 | 119 | } |
duke@1 | 120 | |
duke@1 | 121 | /** |
duke@1 | 122 | * Required doclet method. |
duke@1 | 123 | */ |
duke@1 | 124 | public static int optionLength(String option) { |
duke@1 | 125 | if (option.equals("-o")) { |
duke@1 | 126 | return 2; |
duke@1 | 127 | } else if(option.equals("-d")){ |
duke@1 | 128 | return 2; |
duke@1 | 129 | } else if (option.equals("-td")) { |
duke@1 | 130 | return 1; |
duke@1 | 131 | } else if (option.equals("-stubs")) { |
duke@1 | 132 | return 1; |
duke@1 | 133 | } else if(option.equals("-help")){ |
duke@1 | 134 | return 1; |
duke@1 | 135 | } else if(option.equals("--help")){ |
duke@1 | 136 | return 1; |
duke@1 | 137 | } else if(option.equals("-?")){ |
duke@1 | 138 | return 1; |
duke@1 | 139 | } else if(option.equals("-h")){ |
duke@1 | 140 | return 1; |
duke@1 | 141 | } else if(option.equals("-trace")){ |
duke@1 | 142 | return 1; |
duke@1 | 143 | } else if(option.equals("-version")) { |
duke@1 | 144 | return 1; |
duke@1 | 145 | } else if(option.equals("-jni")){ |
duke@1 | 146 | return 1; |
duke@1 | 147 | } else if(option.equals("-force")){ |
duke@1 | 148 | return 1; |
duke@1 | 149 | } else if(option.equals("-Xllni")){ |
duke@1 | 150 | return 1; |
duke@1 | 151 | } else if(option.equals("-llni")){ |
duke@1 | 152 | return 1; |
duke@1 | 153 | } else if(option.equals("-llniDouble")){ |
duke@1 | 154 | return 1; |
duke@1 | 155 | } else return 0; |
duke@1 | 156 | } |
duke@1 | 157 | |
duke@1 | 158 | /** |
duke@1 | 159 | * Parse the command line options. |
duke@1 | 160 | */ |
duke@1 | 161 | public static void validateOptions(String cmdoptions[][]) { |
duke@1 | 162 | /* Default values for options, overridden by user options. */ |
duke@1 | 163 | String bootcp = System.getProperty("sun.boot.class.path"); |
duke@1 | 164 | String usercp = System.getProperty("env.class.path"); |
duke@1 | 165 | |
duke@1 | 166 | for(int p = 0; p < cmdoptions.length; p++){ |
duke@1 | 167 | |
duke@1 | 168 | if (cmdoptions[p][0].equals("-o")) { |
duke@1 | 169 | ofile = cmdoptions[p][1]; |
duke@1 | 170 | } else if(cmdoptions[p][0].equals("-d")){ |
duke@1 | 171 | odir = cmdoptions[p][1]; |
duke@1 | 172 | } else if (cmdoptions[p][0].equals("-td")) { |
duke@1 | 173 | if (p ==cmdoptions.length) |
duke@1 | 174 | Util.usage(1); |
duke@1 | 175 | } else if (cmdoptions[p][0].equals("-stubs")) { |
duke@1 | 176 | stubs = true; |
duke@1 | 177 | } else if (cmdoptions[p][0].equals("-verbose")) { |
duke@1 | 178 | Util.verbose = true; |
duke@1 | 179 | } else if((cmdoptions[p][0].equals("-help")) |
duke@1 | 180 | || (cmdoptions[p][0].equals("--help")) |
duke@1 | 181 | || (cmdoptions[p][0].equals("-?")) |
duke@1 | 182 | || (cmdoptions[p][0].equals("-h"))) { |
duke@1 | 183 | Util.usage(0); |
duke@1 | 184 | } else if (cmdoptions[p][0].equals("-trace")) { |
duke@1 | 185 | System.err.println(Util.getText("tracing.not.supported")); |
duke@1 | 186 | } else if (cmdoptions[p][0].equals("-version")) { |
duke@1 | 187 | Util.version(); |
duke@1 | 188 | } else if (cmdoptions[p][0].equals("-jni")) { |
duke@1 | 189 | jni = true; |
duke@1 | 190 | } else if (cmdoptions[p][0].equals("-force")) { |
duke@1 | 191 | force = true; |
duke@1 | 192 | } else if (cmdoptions[p][0].equals("-Xllni")) { |
duke@1 | 193 | llni = true; |
duke@1 | 194 | } else if (cmdoptions[p][0].equals("-llni")) { |
duke@1 | 195 | llni = true; |
duke@1 | 196 | } else if (cmdoptions[p][0].equals("-llniDouble")) { |
duke@1 | 197 | llni = true; doubleAlign = true; |
duke@1 | 198 | } else if (cmdoptions[p][0].equals("-classpath")) { |
duke@1 | 199 | usercp = cmdoptions[p][1]; |
duke@1 | 200 | } else if (cmdoptions[p][0].equals("-bootclasspath")) { |
duke@1 | 201 | bootcp = cmdoptions[p][1]; |
duke@1 | 202 | } else if((cmdoptions[p][0].charAt(0) == '-') |
duke@1 | 203 | && (!cmdoptions[p][0].equals("-private"))){ |
duke@1 | 204 | Util.error("unknown.option", cmdoptions[p][0], null, true); |
duke@1 | 205 | } else { |
duke@1 | 206 | break; /* The rest must be classes. */ |
duke@1 | 207 | } |
duke@1 | 208 | } |
duke@1 | 209 | |
duke@1 | 210 | |
duke@1 | 211 | if (Util.verbose) { |
duke@1 | 212 | System.err.println("[ Search Path: " |
duke@1 | 213 | + bootcp |
duke@1 | 214 | + System.getProperty("file.separator") |
duke@1 | 215 | + usercp + " ]"); |
duke@1 | 216 | } |
duke@1 | 217 | } |
duke@1 | 218 | } |