jaxws/src/share/classes/com/sun/codemodel/internal/JDocComment.java
author jgodinez
Mon, 20 Apr 2009 12:31:36 -0700
changeset 2697 b27edaf0767e
parent 8 474761f14bca
child 2678 57cf2a1c1a05
permissions -rw-r--r--
6821495: test/java/awt/print/PrinterJob/PrtException.java fails Reviewed-by: igor, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8
474761f14bca Initial load
duke
parents:
diff changeset
     1
/*
474761f14bca Initial load
duke
parents:
diff changeset
     2
 * Copyright 2006 Sun Microsystems, Inc.  All Rights Reserved.
474761f14bca Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
474761f14bca Initial load
duke
parents:
diff changeset
     4
 *
474761f14bca Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
474761f14bca Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
474761f14bca Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
474761f14bca Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
474761f14bca Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
474761f14bca Initial load
duke
parents:
diff changeset
    10
 *
474761f14bca Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
474761f14bca Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
474761f14bca Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
474761f14bca Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
474761f14bca Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
474761f14bca Initial load
duke
parents:
diff changeset
    16
 *
474761f14bca Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
474761f14bca Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
474761f14bca Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
474761f14bca Initial load
duke
parents:
diff changeset
    20
 *
474761f14bca Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
474761f14bca Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
474761f14bca Initial load
duke
parents:
diff changeset
    23
 * have any questions.
474761f14bca Initial load
duke
parents:
diff changeset
    24
 */
474761f14bca Initial load
duke
parents:
diff changeset
    25
474761f14bca Initial load
duke
parents:
diff changeset
    26
package com.sun.codemodel.internal;
474761f14bca Initial load
duke
parents:
diff changeset
    27
474761f14bca Initial load
duke
parents:
diff changeset
    28
import java.util.HashMap;
474761f14bca Initial load
duke
parents:
diff changeset
    29
import java.util.Map;
474761f14bca Initial load
duke
parents:
diff changeset
    30
474761f14bca Initial load
duke
parents:
diff changeset
    31
/**
474761f14bca Initial load
duke
parents:
diff changeset
    32
 * JavaDoc comment.
474761f14bca Initial load
duke
parents:
diff changeset
    33
 *
474761f14bca Initial load
duke
parents:
diff changeset
    34
 * <p>
474761f14bca Initial load
duke
parents:
diff changeset
    35
 * A javadoc comment consists of multiple parts. There's the main part (that comes the first in
474761f14bca Initial load
duke
parents:
diff changeset
    36
 * in the comment section), then the parameter parts (@param), the return part (@return),
474761f14bca Initial load
duke
parents:
diff changeset
    37
 * and the throws parts (@throws).
474761f14bca Initial load
duke
parents:
diff changeset
    38
 *
474761f14bca Initial load
duke
parents:
diff changeset
    39
 * TODO: it would be nice if we have JComment class and we can derive this class from there.
474761f14bca Initial load
duke
parents:
diff changeset
    40
 */
474761f14bca Initial load
duke
parents:
diff changeset
    41
public class JDocComment extends JCommentPart implements JGenerable {
474761f14bca Initial load
duke
parents:
diff changeset
    42
474761f14bca Initial load
duke
parents:
diff changeset
    43
474761f14bca Initial load
duke
parents:
diff changeset
    44
    /** list of @param tags */
474761f14bca Initial load
duke
parents:
diff changeset
    45
    private final Map<String,JCommentPart> atParams = new HashMap<String,JCommentPart>();
474761f14bca Initial load
duke
parents:
diff changeset
    46
474761f14bca Initial load
duke
parents:
diff changeset
    47
    /** list of xdoclets */
474761f14bca Initial load
duke
parents:
diff changeset
    48
    private final Map<String,Map<String,String>> atXdoclets = new HashMap<String,Map<String,String>>();
474761f14bca Initial load
duke
parents:
diff changeset
    49
474761f14bca Initial load
duke
parents:
diff changeset
    50
    /** list of @throws tags */
474761f14bca Initial load
duke
parents:
diff changeset
    51
    private final Map<JClass,JCommentPart> atThrows = new HashMap<JClass,JCommentPart>();
474761f14bca Initial load
duke
parents:
diff changeset
    52
474761f14bca Initial load
duke
parents:
diff changeset
    53
    /**
474761f14bca Initial load
duke
parents:
diff changeset
    54
     * The @return tag part.
474761f14bca Initial load
duke
parents:
diff changeset
    55
     */
474761f14bca Initial load
duke
parents:
diff changeset
    56
    private JCommentPart atReturn = null;
474761f14bca Initial load
duke
parents:
diff changeset
    57
474761f14bca Initial load
duke
parents:
diff changeset
    58
    /** The @deprecated tag */
474761f14bca Initial load
duke
parents:
diff changeset
    59
    private JCommentPart atDeprecated = null;
474761f14bca Initial load
duke
parents:
diff changeset
    60
474761f14bca Initial load
duke
parents:
diff changeset
    61
    private final JCodeModel owner;
474761f14bca Initial load
duke
parents:
diff changeset
    62
474761f14bca Initial load
duke
parents:
diff changeset
    63
474761f14bca Initial load
duke
parents:
diff changeset
    64
    public JDocComment(JCodeModel owner) {
474761f14bca Initial load
duke
parents:
diff changeset
    65
        this.owner = owner;
474761f14bca Initial load
duke
parents:
diff changeset
    66
    }
474761f14bca Initial load
duke
parents:
diff changeset
    67
474761f14bca Initial load
duke
parents:
diff changeset
    68
    public JDocComment append(Object o) {
474761f14bca Initial load
duke
parents:
diff changeset
    69
        add(o);
474761f14bca Initial load
duke
parents:
diff changeset
    70
        return this;
474761f14bca Initial load
duke
parents:
diff changeset
    71
    }
474761f14bca Initial load
duke
parents:
diff changeset
    72
474761f14bca Initial load
duke
parents:
diff changeset
    73
    /**
474761f14bca Initial load
duke
parents:
diff changeset
    74
     * Append a text to a @param tag to the javadoc
474761f14bca Initial load
duke
parents:
diff changeset
    75
     */
474761f14bca Initial load
duke
parents:
diff changeset
    76
    public JCommentPart addParam( String param ) {
474761f14bca Initial load
duke
parents:
diff changeset
    77
        JCommentPart p = atParams.get(param);
474761f14bca Initial load
duke
parents:
diff changeset
    78
        if(p==null)
474761f14bca Initial load
duke
parents:
diff changeset
    79
            atParams.put(param,p=new JCommentPart());
474761f14bca Initial load
duke
parents:
diff changeset
    80
        return p;
474761f14bca Initial load
duke
parents:
diff changeset
    81
    }
474761f14bca Initial load
duke
parents:
diff changeset
    82
474761f14bca Initial load
duke
parents:
diff changeset
    83
    /**
474761f14bca Initial load
duke
parents:
diff changeset
    84
     * Append a text to an @param tag.
474761f14bca Initial load
duke
parents:
diff changeset
    85
     */
474761f14bca Initial load
duke
parents:
diff changeset
    86
    public JCommentPart addParam( JVar param ) {
474761f14bca Initial load
duke
parents:
diff changeset
    87
        return addParam( param.name() );
474761f14bca Initial load
duke
parents:
diff changeset
    88
    }
474761f14bca Initial load
duke
parents:
diff changeset
    89
474761f14bca Initial load
duke
parents:
diff changeset
    90
474761f14bca Initial load
duke
parents:
diff changeset
    91
    /**
474761f14bca Initial load
duke
parents:
diff changeset
    92
     * add an @throws tag to the javadoc
474761f14bca Initial load
duke
parents:
diff changeset
    93
     */
474761f14bca Initial load
duke
parents:
diff changeset
    94
    public JCommentPart addThrows( Class exception ) {
474761f14bca Initial load
duke
parents:
diff changeset
    95
        return addThrows( owner.ref(exception) );
474761f14bca Initial load
duke
parents:
diff changeset
    96
    }
474761f14bca Initial load
duke
parents:
diff changeset
    97
474761f14bca Initial load
duke
parents:
diff changeset
    98
    /**
474761f14bca Initial load
duke
parents:
diff changeset
    99
     * add an @throws tag to the javadoc
474761f14bca Initial load
duke
parents:
diff changeset
   100
     */
474761f14bca Initial load
duke
parents:
diff changeset
   101
    public JCommentPart addThrows( JClass exception ) {
474761f14bca Initial load
duke
parents:
diff changeset
   102
        JCommentPart p = atThrows.get(exception);
474761f14bca Initial load
duke
parents:
diff changeset
   103
        if(p==null)
474761f14bca Initial load
duke
parents:
diff changeset
   104
            atThrows.put(exception,p=new JCommentPart());
474761f14bca Initial load
duke
parents:
diff changeset
   105
        return p;
474761f14bca Initial load
duke
parents:
diff changeset
   106
    }
474761f14bca Initial load
duke
parents:
diff changeset
   107
474761f14bca Initial load
duke
parents:
diff changeset
   108
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   109
     * Appends a text to @return tag.
474761f14bca Initial load
duke
parents:
diff changeset
   110
     */
474761f14bca Initial load
duke
parents:
diff changeset
   111
    public JCommentPart addReturn() {
474761f14bca Initial load
duke
parents:
diff changeset
   112
        if(atReturn==null)
474761f14bca Initial load
duke
parents:
diff changeset
   113
            atReturn = new JCommentPart();
474761f14bca Initial load
duke
parents:
diff changeset
   114
        return atReturn;
474761f14bca Initial load
duke
parents:
diff changeset
   115
    }
474761f14bca Initial load
duke
parents:
diff changeset
   116
474761f14bca Initial load
duke
parents:
diff changeset
   117
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   118
     * add an @deprecated tag to the javadoc, with the associated message.
474761f14bca Initial load
duke
parents:
diff changeset
   119
     */
474761f14bca Initial load
duke
parents:
diff changeset
   120
    public JCommentPart addDeprecated() {
474761f14bca Initial load
duke
parents:
diff changeset
   121
        if(atDeprecated==null)
474761f14bca Initial load
duke
parents:
diff changeset
   122
            atDeprecated = new JCommentPart();
474761f14bca Initial load
duke
parents:
diff changeset
   123
        return atDeprecated;
474761f14bca Initial load
duke
parents:
diff changeset
   124
    }
474761f14bca Initial load
duke
parents:
diff changeset
   125
474761f14bca Initial load
duke
parents:
diff changeset
   126
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   127
     * add an xdoclet.
474761f14bca Initial load
duke
parents:
diff changeset
   128
     */
474761f14bca Initial load
duke
parents:
diff changeset
   129
    public Map<String,String> addXdoclet(String name) {
474761f14bca Initial load
duke
parents:
diff changeset
   130
        Map<String,String> p = atXdoclets.get(name);
474761f14bca Initial load
duke
parents:
diff changeset
   131
        if(p==null)
474761f14bca Initial load
duke
parents:
diff changeset
   132
            atXdoclets.put(name,p=new HashMap<String,String>());
474761f14bca Initial load
duke
parents:
diff changeset
   133
        return p;
474761f14bca Initial load
duke
parents:
diff changeset
   134
    }
474761f14bca Initial load
duke
parents:
diff changeset
   135
474761f14bca Initial load
duke
parents:
diff changeset
   136
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   137
     * add an xdoclet.
474761f14bca Initial load
duke
parents:
diff changeset
   138
     */
474761f14bca Initial load
duke
parents:
diff changeset
   139
    public Map<String,String> addXdoclet(String name, Map<String,String> attributes) {
474761f14bca Initial load
duke
parents:
diff changeset
   140
        Map<String,String> p = atXdoclets.get(name);
474761f14bca Initial load
duke
parents:
diff changeset
   141
        if(p==null)
474761f14bca Initial load
duke
parents:
diff changeset
   142
            atXdoclets.put(name,p=new HashMap<String,String>());
474761f14bca Initial load
duke
parents:
diff changeset
   143
        p.putAll(attributes);
474761f14bca Initial load
duke
parents:
diff changeset
   144
        return p;
474761f14bca Initial load
duke
parents:
diff changeset
   145
    }
474761f14bca Initial load
duke
parents:
diff changeset
   146
474761f14bca Initial load
duke
parents:
diff changeset
   147
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   148
     * add an xdoclet.
474761f14bca Initial load
duke
parents:
diff changeset
   149
     */
474761f14bca Initial load
duke
parents:
diff changeset
   150
    public Map<String,String> addXdoclet(String name, String attribute, String value) {
474761f14bca Initial load
duke
parents:
diff changeset
   151
        Map<String,String> p = atXdoclets.get(name);
474761f14bca Initial load
duke
parents:
diff changeset
   152
        if(p==null)
474761f14bca Initial load
duke
parents:
diff changeset
   153
            atXdoclets.put(name,p=new HashMap<String,String>());
474761f14bca Initial load
duke
parents:
diff changeset
   154
        p.put(attribute, value);
474761f14bca Initial load
duke
parents:
diff changeset
   155
        return p;
474761f14bca Initial load
duke
parents:
diff changeset
   156
    }
474761f14bca Initial load
duke
parents:
diff changeset
   157
474761f14bca Initial load
duke
parents:
diff changeset
   158
    public void generate(JFormatter f) {
474761f14bca Initial load
duke
parents:
diff changeset
   159
        // I realized that we can't use StringTokenizer because
474761f14bca Initial load
duke
parents:
diff changeset
   160
        // this will recognize multiple \n as one token.
474761f14bca Initial load
duke
parents:
diff changeset
   161
474761f14bca Initial load
duke
parents:
diff changeset
   162
        f.p("/**").nl();
474761f14bca Initial load
duke
parents:
diff changeset
   163
474761f14bca Initial load
duke
parents:
diff changeset
   164
        format(f," * ");
474761f14bca Initial load
duke
parents:
diff changeset
   165
474761f14bca Initial load
duke
parents:
diff changeset
   166
        f.p(" * ").nl();
474761f14bca Initial load
duke
parents:
diff changeset
   167
        for (Map.Entry<String,JCommentPart> e : atParams.entrySet()) {
474761f14bca Initial load
duke
parents:
diff changeset
   168
            f.p(" * @param ").p(e.getKey()).nl();
474761f14bca Initial load
duke
parents:
diff changeset
   169
            e.getValue().format(f,INDENT);
474761f14bca Initial load
duke
parents:
diff changeset
   170
        }
474761f14bca Initial load
duke
parents:
diff changeset
   171
        if( atReturn != null ) {
474761f14bca Initial load
duke
parents:
diff changeset
   172
            f.p(" * @return").nl();
474761f14bca Initial load
duke
parents:
diff changeset
   173
            atReturn.format(f,INDENT);
474761f14bca Initial load
duke
parents:
diff changeset
   174
        }
474761f14bca Initial load
duke
parents:
diff changeset
   175
        for (Map.Entry<JClass,JCommentPart> e : atThrows.entrySet()) {
474761f14bca Initial load
duke
parents:
diff changeset
   176
            f.p(" * @throws ").t(e.getKey()).nl();
474761f14bca Initial load
duke
parents:
diff changeset
   177
            e.getValue().format(f,INDENT);
474761f14bca Initial load
duke
parents:
diff changeset
   178
        }
474761f14bca Initial load
duke
parents:
diff changeset
   179
        if( atDeprecated != null ) {
474761f14bca Initial load
duke
parents:
diff changeset
   180
            f.p(" * @deprecated").nl();
474761f14bca Initial load
duke
parents:
diff changeset
   181
            atDeprecated.format(f,INDENT);
474761f14bca Initial load
duke
parents:
diff changeset
   182
        }
474761f14bca Initial load
duke
parents:
diff changeset
   183
        for (Map.Entry<String,Map<String,String>> e : atXdoclets.entrySet()) {
474761f14bca Initial load
duke
parents:
diff changeset
   184
            f.p(" * @").p(e.getKey());
474761f14bca Initial load
duke
parents:
diff changeset
   185
            if (e.getValue() != null) {
474761f14bca Initial load
duke
parents:
diff changeset
   186
                for (Map.Entry<String,String> a : e.getValue().entrySet()) {
474761f14bca Initial load
duke
parents:
diff changeset
   187
                    f.p(" ").p(a.getKey()).p("= \"").p(a.getValue()).p("\"");
474761f14bca Initial load
duke
parents:
diff changeset
   188
                }
474761f14bca Initial load
duke
parents:
diff changeset
   189
            }
474761f14bca Initial load
duke
parents:
diff changeset
   190
            f.nl();
474761f14bca Initial load
duke
parents:
diff changeset
   191
        }
474761f14bca Initial load
duke
parents:
diff changeset
   192
        f.p(" */").nl();
474761f14bca Initial load
duke
parents:
diff changeset
   193
    }
474761f14bca Initial load
duke
parents:
diff changeset
   194
474761f14bca Initial load
duke
parents:
diff changeset
   195
    private static final String INDENT = " *     ";
474761f14bca Initial load
duke
parents:
diff changeset
   196
}