📄 rmic.java
字号:
method = "doubleValue"; else throw new IllegalStateException("unknown primitive class " + primitive); return method; } public static Class box(Class cls) { if (! cls.isPrimitive()) throw new IllegalArgumentException("can only box primitive"); Class box; if (cls.equals(Boolean.TYPE)) box = Boolean.class; else if (cls.equals(Byte.TYPE)) box = Byte.class; else if (cls.equals(Character.TYPE)) box = Character.class; else if (cls.equals(Short.TYPE)) box = Short.class; else if (cls.equals(Integer.TYPE)) box = Integer.class; else if (cls.equals(Long.TYPE)) box = Long.class; else if (cls.equals(Float.TYPE)) box = Float.class; else if (cls.equals(Double.TYPE)) box = Double.class; else throw new IllegalStateException("unknown primitive type " + cls); return box; } private static int size(Class cls) { if (cls.equals(Long.TYPE) || cls.equals(Double.TYPE)) return 2; else return 1; } /** * Sort exceptions so the most general go last. */ private Class[] sortExceptions(Class[] except) { for (int i = 0; i < except.length; i++) { for (int j = i + 1; j < except.length; j++) { if (except[i].isAssignableFrom(except[j])) { Class tmp = except[i]; except[i] = except[j]; except[j] = tmp; } } } return (except); } /** * Process the options until we find the first argument. * * @return true if further processing should stop */ private boolean parseOptions() { for (;;) { if (next >= args.length || args[next].charAt(0) != '-') break; String arg = args[next]; next++; // Accept `--' options if they look long enough. if (arg.length() > 3 && arg.charAt(0) == '-' && arg.charAt(1) == '-') arg = arg.substring(1); if (arg.equals("-keep")) keep = true; else if (arg.equals("-keepgenerated")) keep = true; else if (arg.equals("-v1.1")) { need11Stubs = true; need12Stubs = false; } else if (arg.equals("-vcompat")) { need11Stubs = true; need12Stubs = true; } else if (arg.equals("-v1.2")) { need11Stubs = false; need12Stubs = true; } else if (arg.equals("-g")) { } else if (arg.equals("-depend")) { } else if (arg.equals("-nowarn")) { } else if (arg.equals("-verbose")) verbose = true; else if (arg.equals("-nocompile")) compile = false; else if (arg.equals("-classpath")) { classpath = args[next]; next++; StringTokenizer st = new StringTokenizer(classpath, File.pathSeparator); URL[] u = new URL[st.countTokens()]; for (int i = 0; i < u.length; i++) { String path = st.nextToken(); File f = new File(path); try { u[i] = f.toURL(); } catch (java.net.MalformedURLException mue) { logError("malformed classpath component " + path); return true; } } loader = new URLClassLoader(u); } else if (arg.equals("-help")) { usage(); return true; } else if (arg.equals("-version")) { System.out.println("rmic (" + System.getProperty("java.vm.name") + ") " + System.getProperty("java.vm.version")); System.out.println(); System.out.println("Copyright 2002 Free Software Foundation, Inc."); System.out.println("This is free software; see the source for copying conditions. There is NO"); System.out.println("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."); return true; } else if (arg.equals("-d")) { destination = args[next]; next++; } else if (arg.charAt(1) == 'J') /* ignoring -J flags that are supposed to be passed to the underlying Java interpreter */ continue; else { logError("unrecognized option '" + arg + "'"); return true; } } return false; } private void findRemoteMethods() throws RMICException { List rmeths = new ArrayList(); for (Class cur = clazz; cur != null; cur = cur.getSuperclass()) { Class[] interfaces = cur.getInterfaces(); for (int i = 0; i < interfaces.length; i++) { if (java.rmi.Remote.class.isAssignableFrom(interfaces[i])) { Class remoteInterface = interfaces[i]; if (verbose) System.out.println ("[implements " + remoteInterface.getName() + "]"); // check if the methods declare RemoteExceptions Method[] meths = remoteInterface.getMethods(); for (int j = 0; j < meths.length; j++) { Method m = meths[j]; Class[] exs = m.getExceptionTypes(); boolean throwsRemote = false; for (int k = 0; k < exs.length; k++) { if (exs[k].isAssignableFrom(RemoteException.class)) throwsRemote = true; } if (! throwsRemote) { throw new RMICException ("Method " + m + " in interface " + remoteInterface + " does not throw a RemoteException"); } rmeths.add(m); } mRemoteInterfaces.add(remoteInterface); } } } // intersect exceptions for doubly inherited methods boolean[] skip = new boolean[rmeths.size()]; for (int i = 0; i < skip.length; i++) skip[i] = false; List methrefs = new ArrayList(); for (int i = 0; i < rmeths.size(); i++) { if (skip[i]) continue; Method current = (Method) rmeths.get(i); MethodRef ref = new MethodRef(current); for (int j = i+1; j < rmeths.size(); j++) { Method other = (Method) rmeths.get(j); if (ref.isMatch(other)) { ref.intersectExceptions(other); skip[j] = true; } } methrefs.add(ref); } // Convert into a MethodRef array and sort them remotemethods = (MethodRef[]) methrefs.toArray(new MethodRef[methrefs.size()]); Arrays.sort(remotemethods); } /** * Prints an error to System.err and increases the error count. */ private void logError(Exception theError) { logError(theError.getMessage()); if (verbose) theError.printStackTrace(System.err); } /** * Prints an error to System.err and increases the error count. */ private void logError(String theError) { errorCount++; System.err.println("error: " + theError); } private static void usage() { System.out.println("Usage: rmic [OPTION]... CLASS...\n" + "\n" + " -keep * Don't delete any intermediate files\n" + " -keepgenerated * Same as -keep\n" + " -v1.1 Java 1.1 style stubs only\n" + " -vcompat Java 1.1 & Java 1.2 stubs\n" + " -v1.2 Java 1.2 style stubs only\n" + " -g * Generated debugging information\n" + " -depend * Recompile out-of-date files\n" + " -nowarn * Suppress warning messages\n" + " -nocompile * Don't compile the generated files\n" + " -verbose Output what's going on\n" + " -classpath <path> Use given path as classpath\n" + " -d <directory> Specify where to place generated classes\n" + " -J<flag> * Pass flag to Java\n" + " -help Print this help, then exit\n" + " -version Print version number, then exit\n" + "\n" + " * Option currently ignored\n" + "Long options can be used with `--option' form as well."); } private static String getPrettyName(Class cls) { StringBuffer str = new StringBuffer(); for (int count = 0;; count++) { if (! cls.isArray()) { str.append(cls.getName()); for (; count > 0; count--) str.append("[]"); return (str.toString()); } cls = cls.getComponentType(); } } private static class MethodRef implements Comparable { Method meth; long hash; List exceptions; private String sig; MethodRef(Method m) { meth = m; sig = Type.getMethodDescriptor(meth); hash = RMIHashes.getMethodHash(m); // add exceptions removing subclasses exceptions = removeSubclasses(m.getExceptionTypes()); } public int compareTo(Object obj) { MethodRef that = (MethodRef) obj; int name = this.meth.getName().compareTo(that.meth.getName()); if (name == 0) { return this.sig.compareTo(that.sig); } return name; } public boolean isMatch(Method m) { if (!meth.getName().equals(m.getName())) return false; Class[] params1 = meth.getParameterTypes(); Class[] params2 = m.getParameterTypes(); if (params1.length != params2.length) return false; for (int i = 0; i < params1.length; i++) if (!params1[i].equals(params2[i])) return false; return true; } private static List removeSubclasses(Class[] classes) { List list = new ArrayList(); for (int i = 0; i < classes.length; i++) { Class candidate = classes[i]; boolean add = true; for (int j = 0; j < classes.length; j++) { if (classes[j].equals(candidate)) continue; else if (classes[j].isAssignableFrom(candidate)) add = false; } if (add) list.add(candidate); } return list; } public void intersectExceptions(Method m) { List incoming = removeSubclasses(m.getExceptionTypes()); List updated = new ArrayList(); for (int i = 0; i < exceptions.size(); i++) { Class outer = (Class) exceptions.get(i); boolean addOuter = false; for (int j = 0; j < incoming.size(); j++) { Class inner = (Class) incoming.get(j); if (inner.equals(outer) || inner.isAssignableFrom(outer)) addOuter = true; else if (outer.isAssignableFrom(inner)) updated.add(inner); } if (addOuter) updated.add(outer); } exceptions = updated; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -