23 * have any questions. |
23 * have any questions. |
24 */ |
24 */ |
25 |
25 |
26 package com.sun.tools.javap; |
26 package com.sun.tools.javap; |
27 |
27 |
28 import java.io.File; |
|
29 import java.io.PrintWriter; |
28 import java.io.PrintWriter; |
30 import java.nio.charset.Charset; |
29 import java.nio.charset.Charset; |
31 import javax.tools.Diagnostic; |
|
32 import javax.tools.DiagnosticListener; |
30 import javax.tools.DiagnosticListener; |
33 import javax.tools.JavaFileObject; |
31 import javax.tools.JavaFileObject; |
34 |
32 |
35 import com.sun.tools.javac.file.JavacFileManager; |
33 import com.sun.tools.javac.file.JavacFileManager; |
36 import com.sun.tools.javac.util.Context; |
34 import com.sun.tools.javac.util.Context; |
37 import com.sun.tools.javac.util.JCDiagnostic; |
|
38 |
35 |
39 /** |
36 /** |
40 * javap's implementation of JavaFileManager. |
37 * javap's implementation of JavaFileManager. |
41 * |
38 * |
42 * <p><b>This is NOT part of any API supported by Sun Microsystems. If |
39 * <p><b>This is NOT part of any API supported by Sun Microsystems. If |
50 } |
47 } |
51 |
48 |
52 static JavapFileManager create(final DiagnosticListener<? super JavaFileObject> dl, PrintWriter log, Options options) { |
49 static JavapFileManager create(final DiagnosticListener<? super JavaFileObject> dl, PrintWriter log, Options options) { |
53 Context javac_context = new Context(); |
50 Context javac_context = new Context(); |
54 |
51 |
55 if (dl != null) { |
52 if (dl != null) |
56 // Workaround bug 6625520: javac handles missing entries on classpath badly |
53 javac_context.put(DiagnosticListener.class, dl); |
57 // Ignore spurious errors for missing files |
|
58 DiagnosticListener<JavaFileObject> wrapper = new DiagnosticListener<JavaFileObject>() { |
|
59 public void report(Diagnostic<? extends JavaFileObject> diagnostic) { |
|
60 if (diagnostic instanceof JCDiagnostic) { |
|
61 JCDiagnostic jcd = (JCDiagnostic) diagnostic; |
|
62 if (jcd.getCode().equals("compiler.err.error.reading.file")) { |
|
63 Object[] args = jcd.getArgs(); |
|
64 if (args.length > 0 && args[0] != null && args[0].toString().length() > 0) { |
|
65 File f = new File(args[0].toString()); |
|
66 if (!f.exists()) |
|
67 return; |
|
68 } |
|
69 } |
|
70 |
|
71 } |
|
72 dl.report(diagnostic); |
|
73 } |
|
74 }; |
|
75 javac_context.put(DiagnosticListener.class, wrapper); |
|
76 } |
|
77 |
|
78 javac_context.put(com.sun.tools.javac.util.Log.outKey, log); |
54 javac_context.put(com.sun.tools.javac.util.Log.outKey, log); |
79 |
55 |
80 return new JavapFileManager(javac_context, null); |
56 return new JavapFileManager(javac_context, null); |
81 } |
57 } |
82 |
58 |