langtools/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java
changeset 169 ff76730e430e
parent 10 06bc494ca11e
child 731 1dd22bdb9ca5
equal deleted inserted replaced
168:25697c18650b 169:ff76730e430e
   129 
   129 
   130     /** Access to files
   130     /** Access to files
   131      */
   131      */
   132     private final JavaFileManager fileManager;
   132     private final JavaFileManager fileManager;
   133 
   133 
       
   134     /** Factory for diagnostics
       
   135      */
       
   136     JCDiagnostic.Factory diagFactory;
       
   137 
   134     /** Can be reassigned from outside:
   138     /** Can be reassigned from outside:
   135      *  the completer to be used for ".java" files. If this remains unassigned
   139      *  the completer to be used for ".java" files. If this remains unassigned
   136      *  ".java" files will not be loaded.
   140      *  ".java" files will not be loaded.
   137      */
   141      */
   138     public SourceCompleter sourceCompleter = null;
   142     public SourceCompleter sourceCompleter = null;
   219         syms = Symtab.instance(context);
   223         syms = Symtab.instance(context);
   220         types = Types.instance(context);
   224         types = Types.instance(context);
   221         fileManager = context.get(JavaFileManager.class);
   225         fileManager = context.get(JavaFileManager.class);
   222         if (fileManager == null)
   226         if (fileManager == null)
   223             throw new AssertionError("FileManager initialization error");
   227             throw new AssertionError("FileManager initialization error");
       
   228         diagFactory = JCDiagnostic.Factory.instance(context);
   224 
   229 
   225         init(syms, definitive);
   230         init(syms, definitive);
   226         log = Log.instance(context);
   231         log = Log.instance(context);
   227 
   232 
   228         Options options = Options.instance(context);
   233         Options options = Options.instance(context);
   254 
   259 
   255 /************************************************************************
   260 /************************************************************************
   256  * Error Diagnoses
   261  * Error Diagnoses
   257  ***********************************************************************/
   262  ***********************************************************************/
   258 
   263 
   259     public static class BadClassFile extends CompletionFailure {
   264 
       
   265     public class BadClassFile extends CompletionFailure {
   260         private static final long serialVersionUID = 0;
   266         private static final long serialVersionUID = 0;
   261 
   267 
   262         /**
   268         public BadClassFile(TypeSymbol sym, JavaFileObject file, JCDiagnostic diag) {
   263          * @param msg A localized message.
   269             super(sym, createBadClassFileDiagnostic(file, diag));
   264          */
   270         }
   265         public BadClassFile(ClassSymbol c, Object cname, Object msg) {
   271     }
   266             super(c, Log.getLocalizedString("bad.class.file.header",
   272     // where
   267                                             cname, msg));
   273     private JCDiagnostic createBadClassFileDiagnostic(JavaFileObject file, JCDiagnostic diag) {
   268         }
   274         String key = (file.getKind() == JavaFileObject.Kind.SOURCE
       
   275                     ? "bad.source.file.header" : "bad.class.file.header");
       
   276         return diagFactory.fragment(key, file, diag);
   269     }
   277     }
   270 
   278 
   271     public BadClassFile badClassFile(String key, Object... args) {
   279     public BadClassFile badClassFile(String key, Object... args) {
   272         return new BadClassFile (
   280         return new BadClassFile (
   273             currentOwner.enclClass(),
   281             currentOwner.enclClass(),
   274             currentClassFile,
   282             currentClassFile,
   275             Log.getLocalizedString(key, args));
   283             diagFactory.fragment(key, args));
   276     }
   284     }
   277 
   285 
   278 /************************************************************************
   286 /************************************************************************
   279  * Buffer Access
   287  * Buffer Access
   280  ***********************************************************************/
   288  ***********************************************************************/
  1891                 throw badClassFile("unable.to.access.file", ex.getMessage());
  1899                 throw badClassFile("unable.to.access.file", ex.getMessage());
  1892             } finally {
  1900             } finally {
  1893                 currentClassFile = previousClassFile;
  1901                 currentClassFile = previousClassFile;
  1894             }
  1902             }
  1895         } else {
  1903         } else {
       
  1904             JCDiagnostic diag =
       
  1905                 diagFactory.fragment("class.file.not.found", c.flatname);
  1896             throw
  1906             throw
  1897                 newCompletionFailure(c,
  1907                 newCompletionFailure(c, diag);
  1898                                      Log.getLocalizedString("class.file.not.found",
       
  1899                                                             c.flatname));
       
  1900         }
  1908         }
  1901     }
  1909     }
  1902     // where
  1910     // where
  1903         private static byte[] readInputStream(byte[] buf, InputStream s) throws IOException {
  1911         private static byte[] readInputStream(byte[] buf, InputStream s) throws IOException {
  1904             try {
  1912             try {
  1932         }
  1940         }
  1933         /** Static factory for CompletionFailure objects.
  1941         /** Static factory for CompletionFailure objects.
  1934          *  In practice, only one can be used at a time, so we share one
  1942          *  In practice, only one can be used at a time, so we share one
  1935          *  to reduce the expense of allocating new exception objects.
  1943          *  to reduce the expense of allocating new exception objects.
  1936          */
  1944          */
  1937         private CompletionFailure newCompletionFailure(ClassSymbol c,
  1945         private CompletionFailure newCompletionFailure(TypeSymbol c,
  1938                                                        String localized) {
  1946                                                        JCDiagnostic diag) {
  1939             if (!cacheCompletionFailure) {
  1947             if (!cacheCompletionFailure) {
  1940                 // log.warning("proc.messager",
  1948                 // log.warning("proc.messager",
  1941                 //             Log.getLocalizedString("class.file.not.found", c.flatname));
  1949                 //             Log.getLocalizedString("class.file.not.found", c.flatname));
  1942                 // c.debug.printStackTrace();
  1950                 // c.debug.printStackTrace();
  1943                 return new CompletionFailure(c, localized);
  1951                 return new CompletionFailure(c, diag);
  1944             } else {
  1952             } else {
  1945                 CompletionFailure result = cachedCompletionFailure;
  1953                 CompletionFailure result = cachedCompletionFailure;
  1946                 result.sym = c;
  1954                 result.sym = c;
  1947                 result.errmsg = localized;
  1955                 result.diag = diag;
  1948                 return result;
  1956                 return result;
  1949             }
  1957             }
  1950         }
  1958         }
  1951         private CompletionFailure cachedCompletionFailure =
  1959         private CompletionFailure cachedCompletionFailure =
  1952             new CompletionFailure(null, null);
  1960             new CompletionFailure(null, (JCDiagnostic) null);
  1953         {
  1961         {
  1954             cachedCompletionFailure.setStackTrace(new StackTraceElement[0]);
  1962             cachedCompletionFailure.setStackTrace(new StackTraceElement[0]);
  1955         }
  1963         }
  1956 
  1964 
  1957     /** Load a toplevel class with given fully qualified name
  1965     /** Load a toplevel class with given fully qualified name