63 import com.sun.tools.classfile.*; |
63 import com.sun.tools.classfile.*; |
64 import java.net.URISyntaxException; |
64 import java.net.URISyntaxException; |
65 import java.net.URL; |
65 import java.net.URL; |
66 import java.net.URLConnection; |
66 import java.net.URLConnection; |
67 |
67 |
|
68 import com.sun.tools.javac.util.DefinedBy; |
|
69 import com.sun.tools.javac.util.DefinedBy.Api; |
|
70 |
68 /** |
71 /** |
69 * "Main" class for javap, normally accessed from the command line |
72 * "Main" class for javap, normally accessed from the command line |
70 * via Main, or from JSR199 via DisassemblerTool. |
73 * via Main, or from JSR199 via DisassemblerTool. |
71 * |
74 * |
72 * <p><b>This is NOT part of any supported API. |
75 * <p><b>This is NOT part of any supported API. |
378 } |
381 } |
379 |
382 |
380 private DiagnosticListener<JavaFileObject> getDiagnosticListenerForWriter(Writer w) { |
383 private DiagnosticListener<JavaFileObject> getDiagnosticListenerForWriter(Writer w) { |
381 final PrintWriter pw = getPrintWriterForWriter(w); |
384 final PrintWriter pw = getPrintWriterForWriter(w); |
382 return new DiagnosticListener<JavaFileObject> () { |
385 return new DiagnosticListener<JavaFileObject> () { |
|
386 @DefinedBy(Api.COMPILER) |
383 public void report(Diagnostic<? extends JavaFileObject> diagnostic) { |
387 public void report(Diagnostic<? extends JavaFileObject> diagnostic) { |
384 switch (diagnostic.getKind()) { |
388 switch (diagnostic.getKind()) { |
385 case ERROR: |
389 case ERROR: |
386 pw.print(getMessage("err.prefix")); |
390 pw.print(getMessage("err.prefix")); |
387 break; |
391 break; |
676 try { |
680 try { |
677 final URI uri = new URI(className); |
681 final URI uri = new URI(className); |
678 final URL url = uri.toURL(); |
682 final URL url = uri.toURL(); |
679 final URLConnection conn = url.openConnection(); |
683 final URLConnection conn = url.openConnection(); |
680 return new JavaFileObject() { |
684 return new JavaFileObject() { |
|
685 @DefinedBy(Api.COMPILER) |
681 public Kind getKind() { |
686 public Kind getKind() { |
682 return JavaFileObject.Kind.CLASS; |
687 return JavaFileObject.Kind.CLASS; |
683 } |
688 } |
684 |
689 |
|
690 @DefinedBy(Api.COMPILER) |
685 public boolean isNameCompatible(String simpleName, Kind kind) { |
691 public boolean isNameCompatible(String simpleName, Kind kind) { |
686 throw new UnsupportedOperationException(); |
692 throw new UnsupportedOperationException(); |
687 } |
693 } |
688 |
694 |
|
695 @DefinedBy(Api.COMPILER) |
689 public NestingKind getNestingKind() { |
696 public NestingKind getNestingKind() { |
690 throw new UnsupportedOperationException(); |
697 throw new UnsupportedOperationException(); |
691 } |
698 } |
692 |
699 |
|
700 @DefinedBy(Api.COMPILER) |
693 public Modifier getAccessLevel() { |
701 public Modifier getAccessLevel() { |
694 throw new UnsupportedOperationException(); |
702 throw new UnsupportedOperationException(); |
695 } |
703 } |
696 |
704 |
|
705 @DefinedBy(Api.COMPILER) |
697 public URI toUri() { |
706 public URI toUri() { |
698 return uri; |
707 return uri; |
699 } |
708 } |
700 |
709 |
|
710 @DefinedBy(Api.COMPILER) |
701 public String getName() { |
711 public String getName() { |
702 return url.toString(); |
712 return url.toString(); |
703 } |
713 } |
704 |
714 |
|
715 @DefinedBy(Api.COMPILER) |
705 public InputStream openInputStream() throws IOException { |
716 public InputStream openInputStream() throws IOException { |
706 return conn.getInputStream(); |
717 return conn.getInputStream(); |
707 } |
718 } |
708 |
719 |
|
720 @DefinedBy(Api.COMPILER) |
709 public OutputStream openOutputStream() throws IOException { |
721 public OutputStream openOutputStream() throws IOException { |
710 throw new UnsupportedOperationException(); |
722 throw new UnsupportedOperationException(); |
711 } |
723 } |
712 |
724 |
|
725 @DefinedBy(Api.COMPILER) |
713 public Reader openReader(boolean ignoreEncodingErrors) throws IOException { |
726 public Reader openReader(boolean ignoreEncodingErrors) throws IOException { |
714 throw new UnsupportedOperationException(); |
727 throw new UnsupportedOperationException(); |
715 } |
728 } |
716 |
729 |
|
730 @DefinedBy(Api.COMPILER) |
717 public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { |
731 public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { |
718 throw new UnsupportedOperationException(); |
732 throw new UnsupportedOperationException(); |
719 } |
733 } |
720 |
734 |
|
735 @DefinedBy(Api.COMPILER) |
721 public Writer openWriter() throws IOException { |
736 public Writer openWriter() throws IOException { |
722 throw new UnsupportedOperationException(); |
737 throw new UnsupportedOperationException(); |
723 } |
738 } |
724 |
739 |
|
740 @DefinedBy(Api.COMPILER) |
725 public long getLastModified() { |
741 public long getLastModified() { |
726 return conn.getLastModified(); |
742 return conn.getLastModified(); |
727 } |
743 } |
728 |
744 |
|
745 @DefinedBy(Api.COMPILER) |
729 public boolean delete() { |
746 public boolean delete() { |
730 throw new UnsupportedOperationException(); |
747 throw new UnsupportedOperationException(); |
731 } |
748 } |
732 |
749 |
733 }; |
750 }; |
911 } |
928 } |
912 |
929 |
913 private Diagnostic<JavaFileObject> createDiagnostic( |
930 private Diagnostic<JavaFileObject> createDiagnostic( |
914 final Diagnostic.Kind kind, final String key, final Object... args) { |
931 final Diagnostic.Kind kind, final String key, final Object... args) { |
915 return new Diagnostic<JavaFileObject>() { |
932 return new Diagnostic<JavaFileObject>() { |
|
933 @DefinedBy(Api.COMPILER) |
916 public Kind getKind() { |
934 public Kind getKind() { |
917 return kind; |
935 return kind; |
918 } |
936 } |
919 |
937 |
|
938 @DefinedBy(Api.COMPILER) |
920 public JavaFileObject getSource() { |
939 public JavaFileObject getSource() { |
921 return null; |
940 return null; |
922 } |
941 } |
923 |
942 |
|
943 @DefinedBy(Api.COMPILER) |
924 public long getPosition() { |
944 public long getPosition() { |
925 return Diagnostic.NOPOS; |
945 return Diagnostic.NOPOS; |
926 } |
946 } |
927 |
947 |
|
948 @DefinedBy(Api.COMPILER) |
928 public long getStartPosition() { |
949 public long getStartPosition() { |
929 return Diagnostic.NOPOS; |
950 return Diagnostic.NOPOS; |
930 } |
951 } |
931 |
952 |
|
953 @DefinedBy(Api.COMPILER) |
932 public long getEndPosition() { |
954 public long getEndPosition() { |
933 return Diagnostic.NOPOS; |
955 return Diagnostic.NOPOS; |
934 } |
956 } |
935 |
957 |
|
958 @DefinedBy(Api.COMPILER) |
936 public long getLineNumber() { |
959 public long getLineNumber() { |
937 return Diagnostic.NOPOS; |
960 return Diagnostic.NOPOS; |
938 } |
961 } |
939 |
962 |
|
963 @DefinedBy(Api.COMPILER) |
940 public long getColumnNumber() { |
964 public long getColumnNumber() { |
941 return Diagnostic.NOPOS; |
965 return Diagnostic.NOPOS; |
942 } |
966 } |
943 |
967 |
|
968 @DefinedBy(Api.COMPILER) |
944 public String getCode() { |
969 public String getCode() { |
945 return key; |
970 return key; |
946 } |
971 } |
947 |
972 |
|
973 @DefinedBy(Api.COMPILER) |
948 public String getMessage(Locale locale) { |
974 public String getMessage(Locale locale) { |
949 return JavapTask.this.getMessage(locale, key, args); |
975 return JavapTask.this.getMessage(locale, key, args); |
950 } |
976 } |
951 |
977 |
952 @Override |
978 @Override |