// 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:   Comment.java

package com.sun.tools.javadoc;

import com.sun.javadoc.*;
import com.sun.tools.javac.v8.util.Enumeration;
import com.sun.tools.javac.v8.util.ListBuffer;

// Referenced classes of package com.sun.tools.javadoc:
//            DocEnv, DocImpl, DocLocale, SeeTagImpl, 
//            TagImpl, ParamTagImpl, SerialFieldTagImpl, ThrowsTagImpl

class Comment
{

    ParamTag[] paramTags()
    {
        ListBuffer listbuffer = new ListBuffer();
        Enumeration enumeration = tagList.elements();
        do
        {
            if(!enumeration.hasMoreElements())
                break;
            Tag tag = (Tag)enumeration.nextElement();
            if(tag instanceof ParamTag)
                listbuffer.append((ParamTag)tag);
        } while(true);
        return (ParamTag[])listbuffer.toArray(new ParamTag[listbuffer.length()]);
    }

    SeeTag[] seeTags()
    {
        ListBuffer listbuffer = new ListBuffer();
        Enumeration enumeration = tagList.elements();
        do
        {
            if(!enumeration.hasMoreElements())
                break;
            Tag tag = (Tag)enumeration.nextElement();
            if(tag instanceof SeeTag)
                listbuffer.append((SeeTag)tag);
        } while(true);
        return (SeeTag[])listbuffer.toArray(new SeeTag[listbuffer.length()]);
    }

    SerialFieldTag[] serialFieldTags()
    {
        ListBuffer listbuffer = new ListBuffer();
        Enumeration enumeration = tagList.elements();
        do
        {
            if(!enumeration.hasMoreElements())
                break;
            Tag tag = (Tag)enumeration.nextElement();
            if(tag instanceof SerialFieldTag)
                listbuffer.append((SerialFieldTag)tag);
        } while(true);
        return (SerialFieldTag[])listbuffer.toArray(new SerialFieldTag[listbuffer.length()]);
    }

    Tag[] tags()
    {
        return (Tag[])tagList.toArray(new Tag[tagList.length()]);
    }

    ThrowsTag[] throwsTags()
    {
        ListBuffer listbuffer = new ListBuffer();
        Enumeration enumeration = tagList.elements();
        do
        {
            if(!enumeration.hasMoreElements())
                break;
            Tag tag = (Tag)enumeration.nextElement();
            if(tag instanceof ThrowsTag)
                listbuffer.append((ThrowsTag)tag);
        } while(true);
        return (ThrowsTag[])listbuffer.toArray(new ThrowsTag[listbuffer.length()]);
    }

    String commentText()
    {
        return text;
    }

    public String toString()
    {
        return text;
    }

    private static int findInlineTagDelim(String s, int i)
    {
        int j;
        if(i == -1 || (j = s.indexOf("}", i)) == -1)
            return -1;
        int k;
        if((k = s.indexOf("{@", i)) != -1 && k < j)
        {
            int l = findInlineTagDelim(s, k + 1);
            return l == -1 ? -1 : findInlineTagDelim(s, l + 1);
        } else
        {
            return j;
        }
    }

    Tag[] tags(String s)
    {
        ListBuffer listbuffer = new ListBuffer();
        String s1 = s;
        if(s1.charAt(0) != '@')
            s1 = "@" + s1;
        Enumeration enumeration = tagList.elements();
        do
        {
            if(!enumeration.hasMoreElements())
                break;
            Tag tag = (Tag)enumeration.nextElement();
            if(tag.kind().equals(s1))
                listbuffer.append(tag);
        } while(true);
        return (Tag[])listbuffer.toArray(new Tag[listbuffer.length()]);
    }

    Comment(final DocImpl holder, final String commentString)
    {
        docenv = holder.env;
        class _cls1CommentStringParser
        {

            void parseCommentStateMachine()
            {
                byte byte0 = 2;
                boolean flag = true;
                String s = null;
                int i = 0;
                int j = 0;
                int k = -1;
                int l = commentString.length();
                for(int i1 = 0; i1 < l; i1++)
                {
                    char c = commentString.charAt(i1);
                    boolean flag1 = Character.isWhitespace(c);
                    switch(byte0)
                    {
                    default:
                        break;

                    case 3: // '\003'
                        if(flag1)
                        {
                            s = commentString.substring(i, i1);
                            byte0 = 2;
                        }
                        break;

                    case 2: // '\002'
                        if(flag1)
                            break;
                        j = i1;
                        byte0 = 1;
                        // fall through

                    case 1: // '\001'
                        if(flag && c == '@')
                        {
                            parseCommentComponent(s, j, k + 1);
                            i = i1;
                            byte0 = 3;
                        }
                        break;
                    }
                    if(c == '\n')
                    {
                        flag = true;
                        continue;
                    }
                    if(!flag1)
                    {
                        k = i1;
                        flag = false;
                    }
                }

                switch(byte0)
                {
                case 3: // '\003'
                    s = commentString.substring(i, l);
                    // fall through

                case 2: // '\002'
                    j = l;
                    // fall through

                case 1: // '\001'
                    parseCommentComponent(s, j, k + 1);
                    // fall through

                default:
                    return;
                }
            }

            void parseCommentComponent(String s, int i, int j)
            {
                String s1 = j > i ? commentString.substring(i, j) : "";
                if(s == null)
                {
                    text = s1;
                } else
                {
                    Object obj;
                    if(s.equals("@exception") || s.equals("@throws"))
                    {
                        warnIfEmpty(s, s1);
                        obj = new ThrowsTagImpl(holder, s, s1);
                    } else
                    if(s.equals("@param"))
                    {
                        warnIfEmpty(s, s1);
                        obj = new ParamTagImpl(holder, s, s1);
                    } else
                    if(s.equals("@see"))
                    {
                        warnIfEmpty(s, s1);
                        obj = new SeeTagImpl(holder, s, s1);
                    } else
                    if(s.equals("@serialField"))
                    {
                        warnIfEmpty(s, s1);
                        obj = new SerialFieldTagImpl(holder, s, s1);
                    } else
                    if(s.equals("@return"))
                    {
                        warnIfEmpty(s, s1);
                        obj = new TagImpl(holder, s, s1);
                    } else
                    if(s.equals("@author"))
                    {
                        warnIfEmpty(s, s1);
                        obj = new TagImpl(holder, s, s1);
                    } else
                    if(s.equals("@version"))
                    {
                        warnIfEmpty(s, s1);
                        obj = new TagImpl(holder, s, s1);
                    } else
                    {
                        obj = new TagImpl(holder, s, s1);
                    }
                    tagList.append(obj);
                }
            }

            void warnIfEmpty(String s, String s1)
            {
                if(s1.length() == 0)
                    docenv.warning(holder, "tag.tag_has_no_arguments", s);
            }

            _cls1CommentStringParser()
            {
                Object();
            }
        }

        (new _cls1CommentStringParser()).parseCommentStateMachine();
    }

    private static int inlineTagFound(DocImpl docimpl, String s, int i)
    {
        DocEnv docenv1 = docimpl.env;
        int j;
        if(i == s.length() || (j = s.indexOf("{@", i)) == -1)
            return -1;
        if(s.indexOf('}', i) == -1)
        {
            docenv1.warning(docimpl, "tag.Improper_Use_Of_Link_Tag", s.substring(j, s.length()));
            return -1;
        } else
        {
            return j;
        }
    }

    static Tag[] firstSentenceTags(DocImpl docimpl, String s)
    {
        DocLocale doclocale = docimpl.env.doclocale;
        return getInlineTags(docimpl, doclocale.localeSpecificFirstSentence(docimpl, s));
    }

    static Tag[] getInlineTags(DocImpl docimpl, String s)
    {
        ListBuffer listbuffer = new ListBuffer();
        boolean flag = false;
        int j = 0;
        int k = s.length();
        DocEnv docenv1 = docimpl.env;
        if(k == 0)
            return (Tag[])listbuffer.toArray(new Tag[listbuffer.length()]);
        do
        {
            int l;
            if((l = inlineTagFound(docimpl, s, j)) == -1)
            {
                listbuffer.append(new TagImpl(docimpl, "Text", s.substring(j)));
                break;
            }
            int i1 = l;
            int j1 = l;
            do
            {
                if(j1 >= s.length())
                    break;
                char c = s.charAt(j1);
                if(Character.isWhitespace(c) || c == '}')
                {
                    i1 = j1;
                    break;
                }
                j1++;
            } while(true);
            String s1 = s.substring(l + 2, i1);
            for(; Character.isWhitespace(s.charAt(i1)); i1++)
                if(s.length() <= i1)
                {
                    listbuffer.append(new TagImpl(docimpl, "Text", s.substring(j, i1)));
                    docenv1.warning(docimpl, "tag.Improper_Use_Of_Link_Tag", s);
                    return (Tag[])listbuffer.toArray(new Tag[listbuffer.length()]);
                }

            listbuffer.append(new TagImpl(docimpl, "Text", s.substring(j, l)));
            j = i1;
            int i;
            if((i = findInlineTagDelim(s, j)) == -1)
            {
                listbuffer.append(new TagImpl(docimpl, "Text", s.substring(j)));
                docenv1.warning(docimpl, "tag.End_delimiter_missing_for_possible_SeeTag", s);
                return (Tag[])listbuffer.toArray(new TagImpl[listbuffer.length()]);
            }
            if(s1.equals("see") || s1.equals("link") || s1.equals("linkplain"))
                listbuffer.append(new SeeTagImpl(docimpl, "@" + s1, s.substring(j, i)));
            else
                listbuffer.append(new TagImpl(docimpl, "@" + s1, s.substring(j, i)));
            j = i + 1;
        } while(j != s.length());
        return (Tag[])listbuffer.toArray(new Tag[listbuffer.length()]);
    }

    private final ListBuffer tagList = new ListBuffer();
    private String text;
    private final DocEnv docenv;



}
