src/share/classes/com/sun/tools/javac/jvm/ClassReader.java

changeset 12
7366066839bb
parent 1
9a66ca7c79fa
child 50
b9bcea8bbe24
     1.1 --- a/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java	Tue Mar 11 13:14:55 2008 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java	Wed Mar 12 13:06:00 2008 -0700
     1.3 @@ -131,6 +131,10 @@
     1.4       */
     1.5      private final JavaFileManager fileManager;
     1.6  
     1.7 +    /** Factory for diagnostics
     1.8 +     */
     1.9 +    JCDiagnostic.Factory diagFactory;
    1.10 +
    1.11      /** Can be reassigned from outside:
    1.12       *  the completer to be used for ".java" files. If this remains unassigned
    1.13       *  ".java" files will not be loaded.
    1.14 @@ -221,6 +225,7 @@
    1.15          fileManager = context.get(JavaFileManager.class);
    1.16          if (fileManager == null)
    1.17              throw new AssertionError("FileManager initialization error");
    1.18 +        diagFactory = JCDiagnostic.Factory.instance(context);
    1.19  
    1.20          init(syms, definitive);
    1.21          log = Log.instance(context);
    1.22 @@ -256,23 +261,26 @@
    1.23   * Error Diagnoses
    1.24   ***********************************************************************/
    1.25  
    1.26 -    public static class BadClassFile extends CompletionFailure {
    1.27 +
    1.28 +    public class BadClassFile extends CompletionFailure {
    1.29          private static final long serialVersionUID = 0;
    1.30  
    1.31 -        /**
    1.32 -         * @param msg A localized message.
    1.33 -         */
    1.34 -        public BadClassFile(ClassSymbol c, Object cname, Object msg) {
    1.35 -            super(c, Log.getLocalizedString("bad.class.file.header",
    1.36 -                                            cname, msg));
    1.37 +        public BadClassFile(TypeSymbol sym, JavaFileObject file, JCDiagnostic diag) {
    1.38 +            super(sym, createBadClassFileDiagnostic(file, diag));
    1.39          }
    1.40      }
    1.41 +    // where
    1.42 +    private JCDiagnostic createBadClassFileDiagnostic(JavaFileObject file, JCDiagnostic diag) {
    1.43 +        String key = (file.getKind() == JavaFileObject.Kind.SOURCE
    1.44 +                    ? "bad.source.file.header" : "bad.class.file.header");
    1.45 +        return diagFactory.fragment(key, file, diag);
    1.46 +    }
    1.47  
    1.48      public BadClassFile badClassFile(String key, Object... args) {
    1.49          return new BadClassFile (
    1.50              currentOwner.enclClass(),
    1.51              currentClassFile,
    1.52 -            Log.getLocalizedString(key, args));
    1.53 +            diagFactory.fragment(key, args));
    1.54      }
    1.55  
    1.56  /************************************************************************
    1.57 @@ -1893,10 +1901,10 @@
    1.58                  currentClassFile = previousClassFile;
    1.59              }
    1.60          } else {
    1.61 +            JCDiagnostic diag =
    1.62 +                diagFactory.fragment("class.file.not.found", c.flatname);
    1.63              throw
    1.64 -                newCompletionFailure(c,
    1.65 -                                     Log.getLocalizedString("class.file.not.found",
    1.66 -                                                            c.flatname));
    1.67 +                newCompletionFailure(c, diag);
    1.68          }
    1.69      }
    1.70      // where
    1.71 @@ -1934,22 +1942,22 @@
    1.72           *  In practice, only one can be used at a time, so we share one
    1.73           *  to reduce the expense of allocating new exception objects.
    1.74           */
    1.75 -        private CompletionFailure newCompletionFailure(ClassSymbol c,
    1.76 -                                                       String localized) {
    1.77 +        private CompletionFailure newCompletionFailure(TypeSymbol c,
    1.78 +                                                       JCDiagnostic diag) {
    1.79              if (!cacheCompletionFailure) {
    1.80                  // log.warning("proc.messager",
    1.81                  //             Log.getLocalizedString("class.file.not.found", c.flatname));
    1.82                  // c.debug.printStackTrace();
    1.83 -                return new CompletionFailure(c, localized);
    1.84 +                return new CompletionFailure(c, diag);
    1.85              } else {
    1.86                  CompletionFailure result = cachedCompletionFailure;
    1.87                  result.sym = c;
    1.88 -                result.errmsg = localized;
    1.89 +                result.diag = diag;
    1.90                  return result;
    1.91              }
    1.92          }
    1.93          private CompletionFailure cachedCompletionFailure =
    1.94 -            new CompletionFailure(null, null);
    1.95 +            new CompletionFailure(null, (JCDiagnostic) null);
    1.96          {
    1.97              cachedCompletionFailure.setStackTrace(new StackTraceElement[0]);
    1.98          }

mercurial