5 import java.util.zip.*;
6 import java.util.jar.*;
8 import java.lang.reflect.*;
10 import org.eclipse.jdt.core.compiler.IProblem;
11 import org.eclipse.jdt.internal.compiler.ClassFile;
12 import org.eclipse.jdt.internal.compiler.CompilationResult;
13 //import org.eclipse.jdt.internal.compiler.Compiler;
14 import org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies;
15 import org.eclipse.jdt.internal.compiler.ICompilerRequestor;
16 import org.eclipse.jdt.internal.compiler.IErrorHandlingPolicy;
17 import org.eclipse.jdt.internal.compiler.IProblemFactory;
18 import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
19 import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException;
20 import org.eclipse.jdt.internal.compiler.env.*;
21 import org.eclipse.jdt.internal.compiler.impl.*;
22 import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
24 public class Compiler {
25 // Static Entry Point /////////////////////////////////////////////////////
27 public static void main(String[] args) throws IOException {
28 boolean verbose = false;
29 List srcdir = new ArrayList();
30 String source = null, target = null, blddir = null, mainclass = null;
31 boolean buildjar = false;
33 if (args.length == 0) args = new String[] { "--help" };
34 for (int i=0; i < args.length; i++) {
35 if (args[i].charAt(0) == '-') {
36 if (args[i].length() == 1) {
37 System.out.println("Illegal switch: -"); return; }
38 switch (args[i].charAt(1)) {
40 if (args[i].equals("--help")) printHelp();
41 else System.out.println("Unknown switch: -");
44 if (i == args.length - 1) {
45 System.out.println("Missing parameter: "+args[i]); return; }
46 if (blddir != null) { System.err.println("cannot specify both -d and -j"); return; }
50 if (i == args.length - 1) {
51 System.out.println("Missing parameter: "+args[i]); return; }
52 if (blddir != null) { System.err.println("cannot specify both -d and -j"); return; }
57 if (i == args.length - 1) {
58 System.out.println("Missing parameter: "+args[i]); return; }
59 mainclass = args[++i];
62 if (i == args.length - 1) {
63 System.out.println("Missing parameter: "+args[i]); return; }
67 if (i == args.length - 1) {
68 System.out.println("Missing parameter: "+args[i]); return; }
78 } else srcdir.add(args[i]);
81 Compiler c = new Compiler();
83 if (buildjar) c.setBuildJar(blddir);
84 else c.setBuildDir(blddir);
86 if (source != null) c.setSource(source);
87 if (target != null) c.setTarget(target);
88 if (mainclass != null) c.setMainClass(mainclass);
90 String[] s = new String[srcdir.size()];
94 c.setVerbose(verbose);
97 private static void printHelp() {
98 System.out.println("Usage java -cp ... org.ibex.tool.Compiler [options] <source dir> ...");
99 System.out.println("Options:");
100 System.out.println(" -d <directory> Directory to put generated class files in");
101 System.out.println(" -j <jarfile> Jar file to put generated class files in");
102 System.out.println(" -m <class> Main-Class for jar file.");
103 System.out.println(" -s <release> Compile with specified source compatibility.");
104 System.out.println(" -t <release> Compile with specified class file compatibility.");
105 System.out.println(" -v Verbose output.");
106 System.out.println(" -h or --help Print this message.");
107 System.out.println("");
111 // Compiler Interface /////////////////////////////////////////////////////
113 private ClassLoader loader = ClassLoader.getSystemClassLoader();
114 private Map loaded = new HashMap();
115 private PrintWriter out = new PrintWriter(System.out);
116 private Preprocessor preprocessor;
118 private Source[] sources;
120 private File builddir = null;
121 private boolean buildzip = false;
122 private ZipOutputStream jarfile = null;
123 private String mainclass = null;
125 private String[] sourcedirs = new String[0];
127 private PrintWriter warn;
128 private boolean hasErrors;
129 private boolean verbose = false;
132 List defs = Collections.EMPTY_LIST;
134 String define = System.getProperty("org.ibex.tool.preprocessor.define");
135 if (define != null) {
136 defs = new ArrayList();
137 StringTokenizer st = new StringTokenizer(define.toUpperCase(), ",");
138 while (st.hasMoreTokens()) defs.add(st.nextToken().trim());
141 preprocessor = new Preprocessor(null, null, defs);
144 public void setMainClass(String mainclass) { this.mainclass = mainclass; }
145 public void setBuildJar(String dir) throws IOException {
146 builddir = new File(dir == null ? "." : dir);
149 public void setBuildDir(String dir) throws IOException {
150 builddir = new File(dir == null ? "." : dir);
153 public void setSourceDirs(String[] dir) { sourcedirs = dir; }
155 /** Pass CompilerOptions.VERSION_1_*. A String of form "1.1", ".2", etc. */
156 public void setSource(String v) { settings.put(CompilerOptions.OPTION_Source, v); }
158 /** Pass CompilerOptions.VERSION_1_*. A String of form "1.1", ".2", etc. */
159 public void setTarget(String v) { settings.put(CompilerOptions.OPTION_TargetPlatform, v); }
161 public void setVerbose(boolean v) { verbose = v; }
163 public void compile() throws IOException {
164 List s = new ArrayList();
167 Manifest m = new Manifest();
168 m.getMainAttributes().putValue("Manifest-Version", "1.0");
169 if (mainclass != null) m.getMainAttributes().putValue("Main-Class", mainclass);
170 jarfile = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(builddir)), m);
172 for (int i=0; i < sourcedirs.length; i++) {
173 File src = new File(sourcedirs[i]);
175 if (verbose) System.err.println("source directory not found: "+sourcedirs[i]);
178 filterSources(s, src, new char[0][], sourcedirs[i]);
181 if (verbose) System.out.println("working with "+s.size() +" sources");
182 sources = new Source[s.size()]; s.toArray(sources);
183 ICompilationUnit[] units = new ICompilationUnit[s.size()];
184 int u = 0; for (int i=0; i < sources.length; i++)
185 if (sources[i].compiled == null) units[u++] = sources[i].unit;
186 if (u != units.length) {
187 ICompilationUnit[] newu = new ICompilationUnit[u];
188 System.arraycopy(units, 0, newu, 0, u);
194 StringWriter sw = new StringWriter();
195 StringBuffer w = sw.getBuffer();
196 warn = new PrintWriter(sw);
198 org.eclipse.jdt.internal.compiler.Compiler jdt =
199 new org.eclipse.jdt.internal.compiler.Compiler(
200 env, policy, settings, results, problems);
203 if (!hasErrors) { out.write(w.toString()); out.flush(); }
206 if (jarfile != null) jarfile.close();
207 } catch (Exception e) {
212 private final FilenameFilter filterSrcs = new FilenameFilter() {
213 public boolean accept(File dir, String name) { return name.endsWith(".java"); }
215 private final FileFilter filterDirs = new FileFilter() {
216 public boolean accept(File path) { return path.isDirectory(); }
218 private byte[] bytes(File bfile) {
219 byte[] bytes = new byte[2 * 1024];
222 InputStream bin = new FileInputStream(bfile);
223 while ((in = bin.read(bytes, pos, bytes.length - pos)) != -1) {
225 if (pos == bytes.length) {
226 byte[] newbytes= new byte[pos * 2];
227 System.arraycopy(bytes, 0, newbytes, 0, pos);
232 } catch (IOException e) {
233 System.out.println("Error reading class file"); // FIXME
234 e.printStackTrace(); return null;
237 if (pos != bytes.length) {
238 byte[] newbytes= new byte[pos * 2];
239 System.arraycopy(bytes, 0, newbytes, 0, pos);
245 private void filterSources(List s, File dir, char[][] pack, String srcdir) {
246 List bclasses = new ArrayList();
247 File bdir = new File(builddir, str(pack, File.separatorChar));
249 // add the java files in this directory
250 File[] ja = dir.listFiles(filterSrcs);
251 for (int i=0; i < ja.length; i++) {
252 char[] n = name(classname(ja[i].getName()));
253 Source src = new Source(ja[i], n, pack, srcdir);
255 // skip the file if the build version is newer than the source
256 String bclass = new String(n);
257 File bfile = new File(bdir, bclass + ".class");
258 if (bfile.lastModified() > ja[i].lastModified()) {
259 src.compiled = bytes(bfile);
260 bclasses.add(bclass);
266 // process the inner classes of any binary files
267 for (int i=0; i < bclasses.size(); i++) {
268 final String bc = (String)bclasses.get(i);
269 final FilenameFilter f = new FilenameFilter() {
270 public boolean accept(File dir, String name) {
271 return name.length() > bc.length() && name.startsWith(bc) &&
272 name.charAt(bc.length()) == '$' && name.endsWith(".class");
275 File[] bfile = bdir.listFiles(f);
276 for (int j=0; j < bfile.length; j++) {
277 Source src = new Source(bfile[j],
278 name(classname(bfile[j].getName())), pack, srcdir);
279 src.compiled = bytes(bfile[j]);
284 // add the subdirectories as packages
285 File[] d = dir.listFiles(filterDirs);
286 for (int i=0; i < d.length; i++) {
287 char[][] newpack = new char[pack.length + 1][];
288 for (int j=0; j < pack.length; j++) newpack[j] = pack[j];
289 newpack[pack.length] = d[i].getName().toCharArray();
290 filterSources(s, d[i], newpack, srcdir);
295 /** Represents a file to be compiled. */
298 char[] n; char[][] p;
300 char[] processed = null;
301 byte[] compiled = null;
302 ClassFileReader reader = null;
304 final ICompilationUnit unit = new ICompilationUnit() {
305 public char[] getMainTypeName() { return n; }
306 public char[][] getPackageName() { return p; }
307 public char[] getFileName() { return fileName; }
308 public char[] getContents() {
309 if (processed != null) return processed;
312 Reader r = new InputStreamReader(new BufferedInputStream(
313 new FileInputStream(orig)));
314 StringWriter w = new StringWriter();
317 synchronized (preprocessor) {
318 preprocessor.setReader(r);
319 preprocessor.setWriter(w);
320 err = preprocessor.process();
323 if (err.size() > 0) {
324 for (int i=0; i < err.size(); i++) {
325 Preprocessor.Warning warn = (Preprocessor.Warning)err.get(i);
326 out.print(getFileName());
328 out.print(warn.getLine());
330 out.print(warn instanceof Preprocessor.Error ?
331 " error: " : " warning: ");
332 out.println(warn.getMessage());
337 processed = w.toString().toCharArray();
338 } catch (IOException e) {
339 System.out.println("IOException: "+e); // FIXME
347 private Source(File o, char[] n, char[][] p, String srcdir) {
348 orig = o; this.n = n; this.p = p;
349 String file = srcdir;
350 file += File.separatorChar + str(p, File.separatorChar);
351 file += File.separatorChar + new String(n) + ".java";
352 fileName = file.toCharArray();
356 // ClassLoader Wrappers ///////////////////////////////////////////////////
358 final static class LoadedNestedType implements IBinaryNestedType {
360 LoadedNestedType(Class c) { this.c = c; }
361 public char[] getName() { return name(c); }
362 public char[] getEnclosingTypeName() { return name(c.getDeclaringClass()); }
363 public int getModifiers() { return c.getModifiers(); }
366 final static class LoadedField implements IBinaryField {
370 LoadedField(Field f) {
372 int m = f.getModifiers();
374 c = Constant.NotAConstant;
375 if (Modifier.isFinal(m) && Modifier.isStatic(m)) {
377 Class type = f.getType();
378 if (type == Boolean.TYPE) {
379 c = new BooleanConstant(f.getBoolean(null));
380 } else if (type == Byte.TYPE) {
381 c = new ByteConstant(f.getByte(null));
382 } else if (type == Character.TYPE) {
383 c = new CharConstant(f.getChar(null));
384 } else if (type == Double.TYPE) {
385 c = new DoubleConstant(f.getDouble(null));
386 } else if (type == Float.TYPE) {
387 c = new FloatConstant(f.getFloat(null));
388 } else if (type == Integer.TYPE) {
389 c = new IntConstant(f.getInt(null));
390 } else if (type == Long.TYPE) {
391 c = new LongConstant(f.getLong(null));
392 } else if (type == Short.TYPE) {
393 c = new ShortConstant(f.getShort(null));
394 } else if (type == String.class) {
395 c = new StringConstant((String)f.get(null));
397 } catch (IllegalAccessException e) {}
400 public Constant getConstant() { return c; }
401 public char[] getTypeName() { return typeName(f.getType()); }
402 public char[] getName() { return f.getName().toCharArray(); }
403 public int getModifiers() { return f.getModifiers(); }
406 final static class LoadedConstructor implements IBinaryMethod {
407 private Constructor c;
411 LoadedConstructor(Constructor c) {
414 Class[] exs = c.getExceptionTypes();
415 ex = new char[exs.length][];
416 for (int i=0; i < ex.length; i++) ex[i] = name(exs[i]);
418 desc = descriptor(c.getParameterTypes(), null);
420 public int getModifiers() { return c.getModifiers(); }
421 public char[] getSelector() { return c.getName().toCharArray(); }
422 public boolean isConstructor() { return true; }
423 public boolean isClinit() { return false; }
424 public char[][] getArgumentNames() { return null; }
425 public char[][] getExceptionTypeNames() { return ex; }
426 public char[] getMethodDescriptor() { return desc; }
429 final static class LoadedMethod implements IBinaryMethod {
434 LoadedMethod(Method m) {
437 Class[] exs = m.getExceptionTypes();
438 ex = new char[exs.length][];
439 for (int i=0; i < ex.length; i++) ex[i] = name(exs[i]);
441 desc = descriptor(m.getParameterTypes(), m.getReturnType());
443 public int getModifiers() { return m.getModifiers(); }
444 public char[] getSelector() { return m.getName().toCharArray(); }
445 public boolean isConstructor() { return false; }
446 public boolean isClinit() { return false; }
447 public char[][] getArgumentNames() { return null; } // FEATURE: does this do anything cool?
448 public char[][] getExceptionTypeNames() { return ex; }
449 public char[] getMethodDescriptor() { return desc; }
452 final static class LoadedClass implements IBinaryType {
454 private IBinaryField[] f;
455 private char[][] inf;
456 private IBinaryNestedType[] nested;
457 private IBinaryMethod[] meth = null;
459 LoadedClass(Class c) {
462 Field[] fields = c.getDeclaredFields();
463 List flist = new ArrayList(fields.length);
464 for (int i=0; i < fields.length; i++)
465 if (!Modifier.isPrivate(fields[i].getModifiers()))
466 flist.add(new LoadedField(fields[i]));
467 f = new IBinaryField[flist.size()];
470 Class[] interfaces = c.getInterfaces();
471 inf = new char[interfaces.length][];
472 for (int i=0; i < inf.length; i++) inf[i] = name(interfaces[i]);
474 Class[] classes = c.getClasses();
475 nested = new IBinaryNestedType[classes.length];
476 for (int i=0; i < nested.length; i++)
477 nested[i] = new LoadedNestedType(classes[i]);
479 Constructor[] constructors = c.getDeclaredConstructors();
480 Method[] methods = c.getDeclaredMethods();
481 if (methods.length + constructors.length > 0) {
482 List m = new ArrayList(methods.length + constructors.length);
483 for (int j=0; j < methods.length; j++)
484 if (!Modifier.isPrivate(methods[j].getModifiers()))
485 m.add(new LoadedMethod(methods[j]));
486 for (int j=0; j < constructors.length; j++)
487 if (!Modifier.isPrivate(constructors[j].getModifiers()))
488 m.add(new LoadedConstructor(constructors[j]));
489 meth = new IBinaryMethod[m.size()]; m.toArray(meth);
493 public char[] getName() { return name(c); }
494 public char[] getEnclosingTypeName() { return name(c.getDeclaringClass()); }
495 public char[] getSuperclassName() { return name(c.getSuperclass()); }
496 public IBinaryField[] getFields() { return f; }
497 public char[][] getInterfaceNames() { return inf; }
498 public IBinaryNestedType[] getMemberTypes() { return nested; }
499 public IBinaryMethod[] getMethods() { return meth; }
500 public int getModifiers() { return c.getModifiers(); }
502 public boolean isBinaryType() { return true; }
503 public boolean isClass() { return true; }
504 public boolean isInterface() { return c.isInterface(); }
505 public boolean isAnonymous() { return false; }
506 public boolean isLocal() { return false; } // FIXME
507 public boolean isMember() { return false; } // FIXME
508 public char[] sourceFileName() { return null; }
509 public char[] getFileName() { return null; }
511 public boolean equals(Object o) {
512 return o == this || super.equals(o) ||
513 (o != null && o instanceof LoadedClass &&
514 c.equals(((LoadedClass)o).c));
519 // Compiler Parameters ////////////////////////////////////////////////////
521 /** Used by compiler to resolve classes. */
522 final INameEnvironment env = new INameEnvironment() {
523 public NameEnvironmentAnswer findType(char[][] c) { return findType(name(c), pack(c)); }
524 public NameEnvironmentAnswer findType(char[] n, char[][] p) {
525 if (verbose) System.out.print("findType: "+ str(p, '.') + "."+new String(n));
528 Class c = Class.forName(str(p, '.') + '.' + new String(n));
529 if (verbose) System.out.println(" found in classloader: "+ c);
530 IBinaryType b = (IBinaryType)loaded.get(c);
531 if (b == null) loaded.put(c, b = new LoadedClass(c));
532 return new NameEnvironmentAnswer(b);
533 } catch (ClassNotFoundException e) {}
535 // cut out searches for java.* packages in sources list
536 if (p.length > 0 && eq(p[0], "java".toCharArray())) {
537 if (verbose) System.out.println(" not found, unknown java.*");
542 for (int i=0; i < sources.length; i++) {
543 Source s = sources[i];
544 if (eq(n, s.n) && eq(p, s.p)) {
545 if (s.reader != null) {
546 if (verbose) System.out.println(" found reader");
547 return new NameEnvironmentAnswer(s.reader);
549 if (s.compiled != null) {
550 if (verbose) System.out.println(" found compiled, new reader");
551 s.reader = new ClassFileReader(s.compiled,
552 s.orig.getName().toCharArray(), true);
553 return new NameEnvironmentAnswer(s.reader);
555 if (verbose) System.out.println(" found unit");
556 return new NameEnvironmentAnswer(sources[i].unit);
559 } catch (ClassFormatException e) {
560 System.out.println("Unexpected ClassFormatException"); // FIXME
561 e.printStackTrace(); return null;
563 if (verbose) System.out.println(" not found");
566 public boolean isPackage(char[][] parent, char[] name) {
567 if (verbose) System.out.println("isPackage: "+ str(parent, '.') + "."+new String(name));
568 String parentName = str(parent, '/');
569 for (int i=0; i < sources.length; i++) {
570 if (eq(name, sources[i].n) && eq(parent, sources[i].p)) return false;
571 if (eq(pack(sources[i].p), parent) && eq(name(sources[i].p), name)) return true;
574 loader.getResource(parentName + ".class") == null &&
575 loader.getResource(parentName + '/' + new String(name) + ".class") == null;
577 public void cleanup() {}
580 /** Used by compiler to decide what do with problems.. */
581 private final IErrorHandlingPolicy policy =
582 DefaultErrorHandlingPolicies.proceedWithAllProblems();
584 /** Used by compiler for general options. */
585 private final Map settings = new HashMap();
587 settings.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.GENERATE);
588 settings.put(CompilerOptions.OPTION_SourceFileAttribute, CompilerOptions.GENERATE);
589 settings.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_3);
590 settings.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_1);
593 /** Used by compiler for processing compiled classes and their errors. */
594 private final ICompilerRequestor results = new ICompilerRequestor() {
595 public void acceptResult(CompilationResult result) {
596 if (verbose) System.out.println("got result: "+result);
597 if (result.hasProblems()) {
599 IProblem[] p = result.getProblems();
601 for (int i=0; i < p.length; i++) {
602 if (p[i].isError()) { o = out; err = true; }
605 o.print(p[i].getOriginatingFileName());
607 o.print(p[i].getSourceLineNumber());
609 o.print(p[i].isError() ? " error: " : " warning: ");
610 o.println(p[i].getMessage());
613 if (err) { hasErrors = true; return; }
616 ClassFile[] c = result.getClassFiles();
617 for (int i=0; i < c.length; i++) {
619 char[][] name = c[i].getCompoundName();
622 jarfile.putNextEntry(new ZipEntry(str(pack(name), '/') + "/" + new String(name(name)) + ".class"));
623 jarfile.write(c[i].getBytes());
624 } catch (java.util.zip.ZipException ze) {
625 // HACK: horrendous hack
626 if (ze.getMessage().indexOf("duplicate entry") != -1) {
627 System.err.println("compiler emitted class twice: " + new String(name(name)));
633 // build package path to new class file
634 File path = new File(builddir, str(pack(name), '/'));
635 if (!path.exists()) path.mkdirs();
636 // write new class file
637 path = new File(path, new String(name(name)) + ".class");
638 OutputStream o = new BufferedOutputStream(new FileOutputStream(path));
639 o.write(c[i].getBytes());
642 } catch (IOException e) {
643 System.out.println("IOException writing class"); // FIXME
650 /** Problem creater for compiler. */
651 private final IProblemFactory problems = new DefaultProblemFactory();
654 // Helper Functiosn ///////////////////////////////////////////////////////
656 /** Convert source file path into class name block.
657 * eg. in: java/lang/String.java -> { {java} {lang} {String} } */
658 private char[][] classname(String name) {
659 String delim = name.indexOf('/') == -1 ? "." : "/";
661 if (name.endsWith(".java")) name = name.substring(0, name.length() - 5);
662 if (name.endsWith(".class")) name = name.substring(0, name.length() - 6);
663 if (name.startsWith(delim)) name = name.substring(1);
665 StringTokenizer st = new StringTokenizer(name, delim);
666 char[][] n = new char[st.countTokens()][];
667 for (int i=0; st.hasMoreTokens(); i++) n[i] = st.nextToken().toCharArray();
671 /** Convert class name into a String. */
672 private static String str(char[][] name, char delim) {
673 StringBuffer b = new StringBuffer();
674 for (int i=0; name != null && i < name.length; i++) {
675 if (name[i] == null || name[i].length == 0) continue;
676 if (i > 0) b.append(delim);
682 /** Returns the package component of a class name.
683 * Effectively returns char[length - 1][]. */
684 private static char[][] pack(char[][] c) {
685 char[][] p = new char[c.length - 1][];
686 for (int i=0; i < p.length; i++) p[i] = c[i];
690 /** Returns the direct-name component of a class name.
691 * eg. String from java.lang.String */
692 private static char[] name(char[][] c) { return c[c.length - 1]; }
694 /** Returns true of contents of both char arrays are equal. */
695 private static boolean eq(char[][] c1, char[][] c2) {
696 if (c1 == null || c2 == null) return c1 == c2;
697 if (c1.length != c2.length) return false;
698 for (int i=0; i < c1.length; i++) if (!eq(c1[i], c2[i])) return false;
702 /** Returns true of contents of both char arrays are equal. */
703 private static boolean eq(char[] c1, char[] c2) {
704 if (c1 == null || c2 == null) return c1 == c2;
705 if (c1.length != c2.length) return false;
706 for (int i=0; i < c1.length; i++) if (c1[i] != c2[i]) return false;
710 /** Returns class name as per VM Spec 4.2. eg. java/lang/String */
711 private static char[] name(Class c) {
712 return c == null ? null : c.getName().replace('.', '/').toCharArray();
715 /** Returns the type name of a class as per VM Spec 4.3.2. */
716 private static char[] typeName(Class p) {
717 StringBuffer sb = new StringBuffer();
719 return sb.toString().toCharArray();
722 /** Returns the type name of a class as per VM Spec 4.3.2.
723 * eg. int -> I, String -> Ljava/lang/String; */
724 private static void typeName(Class p, StringBuffer sb) {
725 String name = p.getName();
726 switch (name.charAt(0)) {
727 case 'B': case 'C': case 'D': case 'F': case 'I':
728 case 'J': case 'S': case 'Z': case 'V': case '[':
729 sb.append(name(p)); break;
731 case 'b': if (name.equals("boolean")) { sb.append('Z'); break; }
732 if (name.equals("byte")) { sb.append('B'); break; }
733 case 'c': if (name.equals("char")) { sb.append('C'); break; }
734 case 'd': if (name.equals("double")) { sb.append('D'); break; }
735 case 'f': if (name.equals("float")) { sb.append('F'); break; }
736 case 'i': if (name.equals("int")) { sb.append('I'); break; }
737 case 'l': if (name.equals("long")) { sb.append('J'); break; }
738 case 's': if (name.equals("short")) { sb.append('S'); break; }
739 case 'v': if (name.equals("void")) { sb.append('V'); break; }
741 sb.append('L'); sb.append(name(p)); sb.append(';');
745 /** Returns the descriptor of a method per VM Spec 4.3.3.
746 * eg. int get(String n, boolean b) -> (Ljava/lang/String;B)I */
747 private static char[] descriptor(Class[] p, Class r) {
748 StringBuffer sb = new StringBuffer();
750 if (p != null) for (int i=0; i < p.length; i++) typeName(p[i], sb);
752 if (r != null) typeName(r, sb);
753 return sb.toString().toCharArray();