// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/kpdus/jad.html
// Decompiler options: packimports(3) deadcode 
// Source File Name:   Messager.java

package com.sun.tools.javadoc;

import com.sun.javadoc.DocErrorReporter;
import com.sun.javadoc.SourcePosition;
import com.sun.tools.javac.v8.util.Context;
import com.sun.tools.javac.v8.util.Log;
import java.io.PrintWriter;
import java.text.MessageFormat;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

public class Messager extends Log
    implements DocErrorReporter
{
    public class ExitJavadoc extends Error
    {

        public ExitJavadoc()
        {
            Error();
        }
    }


    public int nerrors()
    {
        return nerrors;
    }

    public int nwarnings()
    {
        return nwarnings;
    }

    public void exit()
    {
        throw new ExitJavadoc();
    }

    public void exitNotice()
    {
        int i = nerrors();
        int j = nwarnings();
        if(i > 0)
            notice(i <= 1 ? "main.error" : "main.errors", "" + i);
        if(j > 0)
            notice(j <= 1 ? "main.warning" : "main.warnings", "" + j);
    }

    public void reset()
    {
        messageRB = null;
    }

    public void notice(String s)
    {
        printNotice(getText(s));
    }

    public void printError(String s)
    {
        printError(null, s);
    }

    public void printNotice(String s)
    {
        printNotice(null, s);
    }

    public void printWarning(String s)
    {
        printWarning(null, s);
    }

    public static Messager instance0(Context context)
    {
        Messager messager = (Messager)context.get(messagerKey);
        if(messager == null)
            throw new InternalError("no messager instance!");
        else
            return messager;
    }

    public void error(SourcePosition sourceposition, String s)
    {
        printError(sourceposition, getText(s));
    }

    public void printError(SourcePosition sourceposition, String s)
    {
        String s1 = sourceposition != null ? sourceposition.toString() : programName;
        errWriter.println(s1 + ": " + s);
        errWriter.flush();
        prompt();
        nerrors++;
    }

    public void printNotice(SourcePosition sourceposition, String s)
    {
        if(sourceposition == null)
            noticeWriter.println(s);
        else
            noticeWriter.println(sourceposition + ": " + s);
        noticeWriter.flush();
    }

    public void printWarning(SourcePosition sourceposition, String s)
    {
        String s1 = sourceposition != null ? sourceposition.toString() : programName;
        warnWriter.println(s1 + ": warning - " + s);
        warnWriter.flush();
        nwarnings++;
    }

    public void warning(SourcePosition sourceposition, String s)
    {
        printWarning(sourceposition, getText(s));
    }

    protected Messager(Context context, String s)
    {
        Messager(context, s, defaultErrWriter, defaultWarnWriter, defaultNoticeWriter);
    }

    private String getString(String s)
    {
        ResourceBundle resourcebundle = messageRB;
        if(resourcebundle == null)
            try
            {
                messageRB = resourcebundle = ResourceBundle.getBundle("com.sun.tools.javadoc.resources.javadoc");
            }
            catch(MissingResourceException missingresourceexception)
            {
                throw new Error("Fatal: Resource for javadoc is missing");
            }
        return resourcebundle.getString(s);
    }

    String getText(String s)
    {
        return getText(s, (String)null);
    }

    public void notice(String s, String s1)
    {
        printNotice(getText(s, s1));
    }

    public void error(SourcePosition sourceposition, String s, String s1)
    {
        printError(sourceposition, getText(s, s1));
    }

    public void warning(SourcePosition sourceposition, String s, String s1)
    {
        printWarning(sourceposition, getText(s, s1));
    }

    String getText(String s, String s1)
    {
        return getText(s, s1, null);
    }

    public void notice(String s, String s1, String s2)
    {
        printNotice(getText(s, s1, s2));
    }

    public void error(SourcePosition sourceposition, String s, String s1, String s2)
    {
        printError(sourceposition, getText(s, s1, s2));
    }

    public void warning(SourcePosition sourceposition, String s, String s1, String s2)
    {
        printWarning(sourceposition, getText(s, s1, s2));
    }

    String getText(String s, String s1, String s2)
    {
        return getText(s, s1, s2, null);
    }

    public void notice(String s, String s1, String s2, String s3)
    {
        printNotice(getText(s, s1, s2, s3));
    }

    protected Messager(Context context, String s, PrintWriter printwriter, PrintWriter printwriter1, PrintWriter printwriter2)
    {
        Log(context, printwriter, printwriter1, printwriter2);
        messageRB = null;
        context.put(messagerKey, this);
        programName = s;
    }

    public void error(SourcePosition sourceposition, String s, String s1, String s2, String s3)
    {
        printError(sourceposition, getText(s, s1, s2, s3));
    }

    public void warning(SourcePosition sourceposition, String s, String s1, String s2, String s3)
    {
        printWarning(sourceposition, getText(s, s1, s2, s3));
    }

    String getText(String s, String s1, String s2, String s3)
    {
        return getText(s, s1, s2, s3, null);
    }

    public void warning(SourcePosition sourceposition, String s, String s1, String s2, String s3, String s4)
    {
        printWarning(sourceposition, getText(s, s1, s2, s3, s4));
    }

    String getText(String s, String s1, String s2, String s3, String s4)
    {
        String s5;
        String as[];
        s5 = getString(s);
        as = new String[4];
        as[0] = s1;
        as[1] = s2;
        as[2] = s3;
        as[3] = s4;
        return MessageFormat.format(s5, as);
        MissingResourceException missingresourceexception;
        missingresourceexception;
        return "********** Resource for javadoc is broken. There is no " + s + " key in resource.";
    }

    private static final com.sun.tools.javac.v8.util.Context.Key messagerKey = new Key();
    private final String programName;
    private ResourceBundle messageRB;
    static final PrintWriter defaultErrWriter;
    static final PrintWriter defaultWarnWriter;
    static final PrintWriter defaultNoticeWriter;

    static 
    {
        defaultErrWriter = new PrintWriter(System.err);
        defaultWarnWriter = new PrintWriter(System.err);
        defaultNoticeWriter = new PrintWriter(System.out);
    }
}
